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