1*8fae3551SRodney W. GrimesPOSIX and init: 2*8fae3551SRodney W. Grimes-------------- 3*8fae3551SRodney W. Grimes 4*8fae3551SRodney W. GrimesPOSIX.1 does not define 'init' but it mentions it in a few places. 5*8fae3551SRodney W. Grimes 6*8fae3551SRodney W. GrimesB.2.2.2, p205 line 873: 7*8fae3551SRodney W. Grimes 8*8fae3551SRodney W. Grimes This is part of the extensive 'job control' glossary entry. 9*8fae3551SRodney W. Grimes This specific reference says that 'init' must by default provide 10*8fae3551SRodney W. Grimes protection from job control signals to jobs it starts -- 11*8fae3551SRodney W. Grimes it sets SIGTSTP, SIGTTIN and SIGTTOU to SIG_IGN. 12*8fae3551SRodney W. Grimes 13*8fae3551SRodney W. GrimesB.2.2.2, p206 line 889: 14*8fae3551SRodney W. Grimes 15*8fae3551SRodney W. Grimes Here is a reference to 'vhangup'. It says, 'POSIX.1 does 16*8fae3551SRodney W. Grimes not specify how controlling terminal access is affected by 17*8fae3551SRodney W. Grimes a user logging out (that is, by a controlling process 18*8fae3551SRodney W. Grimes terminating).' vhangup() is recognized as one way to handle 19*8fae3551SRodney W. Grimes the problem. I'm not clear what happens in Reno; I have 20*8fae3551SRodney W. Grimes the impression that when the controlling process terminates, 21*8fae3551SRodney W. Grimes references to the controlling terminal are converted to 22*8fae3551SRodney W. Grimes references to a 'dead' vnode. I don't know whether vhangup() 23*8fae3551SRodney W. Grimes is required. 24*8fae3551SRodney W. Grimes 25*8fae3551SRodney W. GrimesB.2.2.2, p206 line 921: 26*8fae3551SRodney W. Grimes 27*8fae3551SRodney W. Grimes Orphaned process groups bear indirectly on this issue. A 28*8fae3551SRodney W. Grimes session leader's process group is considered to be orphaned; 29*8fae3551SRodney W. Grimes that is, it's immune to job control signals from the terminal. 30*8fae3551SRodney W. Grimes 31*8fae3551SRodney W. GrimesB.2.2.2, p233 line 2055: 32*8fae3551SRodney W. Grimes 33*8fae3551SRodney W. Grimes 'Historically, the implementation-dependent process that 34*8fae3551SRodney W. Grimes inherits children whose parents have terminated without 35*8fae3551SRodney W. Grimes waiting on them is called "init" and has a process ID of 1.' 36*8fae3551SRodney W. Grimes 37*8fae3551SRodney W. Grimes It goes on to note that it used to be the case that 'init' 38*8fae3551SRodney W. Grimes was responsible for sending SIGHUP to the foreground process 39*8fae3551SRodney W. Grimes group of a tty whose controlling process has exited, using 40*8fae3551SRodney W. Grimes vhangup(). It is now the responsibility of the kernel to 41*8fae3551SRodney W. Grimes do this when the controlling process calls _exit(). The 42*8fae3551SRodney W. Grimes kernel is also responsible for sending SIGCONT to stopped 43*8fae3551SRodney W. Grimes process groups that become orphaned. This is like old BSD 44*8fae3551SRodney W. Grimes but entire process groups are signaled instead of individual 45*8fae3551SRodney W. Grimes processes. 46*8fae3551SRodney W. Grimes 47*8fae3551SRodney W. Grimes In general it appears that the kernel now automatically 48*8fae3551SRodney W. Grimes takes care of orphans, relieving 'init' of any responsibility. 49*8fae3551SRodney W. Grimes Specifics are listed on the _exit() page (p50). 50*8fae3551SRodney W. Grimes 51*8fae3551SRodney W. GrimesOn setsid(): 52*8fae3551SRodney W. Grimes----------- 53*8fae3551SRodney W. Grimes 54*8fae3551SRodney W. GrimesIt appears that neither getty nor login call setsid(), so init must 55*8fae3551SRodney W. Grimesdo this -- seems reasonable. B.4.3.2 p 248 implies that this is the 56*8fae3551SRodney W. Grimesway that 'init' should work; it says that setsid() should be called 57*8fae3551SRodney W. Grimesafter forking. 58*8fae3551SRodney W. Grimes 59*8fae3551SRodney W. GrimesProcess group leaders cannot call setsid() -- another reason to 60*8fae3551SRodney W. Grimesfork! Of course setsid() causes the current process to become a 61*8fae3551SRodney W. Grimesprocess group leader, so we can only call setsid() once. Note that 62*8fae3551SRodney W. Grimesthe controlling terminal acquires the session leader's process 63*8fae3551SRodney W. Grimesgroup when opened. 64*8fae3551SRodney W. Grimes 65*8fae3551SRodney W. GrimesControlling terminals: 66*8fae3551SRodney W. Grimes--------------------- 67*8fae3551SRodney W. Grimes 68*8fae3551SRodney W. GrimesB.7.1.1.3 p276: 'POSIX.1 does not specify a mechanism by which to 69*8fae3551SRodney W. Grimesallocate a controlling terminal. This is normally done by a system 70*8fae3551SRodney W. Grimesutility (such as 'getty') and is considered ... outside the scope 71*8fae3551SRodney W. Grimesof POSIX.1.' It goes on to say that historically the first open() 72*8fae3551SRodney W. Grimesof a tty in a session sets the controlling terminal. P130 has the 73*8fae3551SRodney W. Grimesfull details; nothing particularly surprising. 74*8fae3551SRodney W. Grimes 75*8fae3551SRodney W. GrimesThe glossary p12 describes a 'controlling process' as the first 76*8fae3551SRodney W. Grimesprocess in a session that acquires a controlling terminal. Access 77*8fae3551SRodney W. Grimesto the terminal from the session is revoked if the controlling 78*8fae3551SRodney W. Grimesprocess exits (see p50, in the discussion of process termination). 79*8fae3551SRodney W. Grimes 80*8fae3551SRodney W. GrimesDesign notes: 81*8fae3551SRodney W. Grimes------------ 82*8fae3551SRodney W. Grimes 83*8fae3551SRodney W. Grimesyour generic finite state machine 84*8fae3551SRodney W. Grimeswe are fascist about which signals we elect to receive, 85*8fae3551SRodney W. Grimes even signals purportedly generated by hardware 86*8fae3551SRodney W. Grimeshandle fatal errors gracefully if possible (we reboot if we goof!!) 87*8fae3551SRodney W. Grimes if we get a segmentation fault etc., print a message on the console 88*8fae3551SRodney W. Grimes and spin for a while before rebooting 89*8fae3551SRodney W. Grimes (this at least decreases the amount of paper consumed :-) 90*8fae3551SRodney W. Grimesapply hysteresis to rapidly exiting gettys 91*8fae3551SRodney W. Grimescheck wait status of children we reap 92*8fae3551SRodney W. Grimes don't wait for stopped children 93*8fae3551SRodney W. Grimesdon't use SIGCHILD, it's too expensive 94*8fae3551SRodney W. Grimes but it may close windows and avoid races, sigh 95*8fae3551SRodney W. Grimeslook for EINTR in case we need to change state 96*8fae3551SRodney W. Grimesinit is responsible for utmp and wtmp maintenance (ick) 97*8fae3551SRodney W. Grimes maybe now we can consider replacements? maintain them in parallel 98*8fae3551SRodney W. Grimes init only removes utmp and closes out wtmp entries... 99*8fae3551SRodney W. Grimes 100*8fae3551SRodney W. Grimesnecessary states and state transitions (gleaned from the man page): 101*8fae3551SRodney W. Grimes 1: single user shell (with password checking?); on exit, go to 2 102*8fae3551SRodney W. Grimes 2: rc script: on exit 0, go to 3; on exit N (error), go to 1 103*8fae3551SRodney W. Grimes 3: read ttys file: on completion, go to 4 104*8fae3551SRodney W. Grimes 4: multi-user operation: on SIGTERM, go to 7; on SIGHUP, go to 5; 105*8fae3551SRodney W. Grimes on SIGTSTP, go to 6 106*8fae3551SRodney W. Grimes 5: clean up mode (re-read ttys file, killing off controlling processes 107*8fae3551SRodney W. Grimes on lines that are now 'off', starting them on lines newly 'on') 108*8fae3551SRodney W. Grimes on completion, go to 4 109*8fae3551SRodney W. Grimes 6: boring mode (no new sessions); signals as in 4 110*8fae3551SRodney W. Grimes 7: death: send SIGHUP to all controlling processes, reap for 30 seconds, 111*8fae3551SRodney W. Grimes then go to 1 (warn if not all processes died, i.e. wait blocks) 112*8fae3551SRodney W. GrimesGiven the -s flag, we start at state 1; otherwise state 2 113