init(8) running rc.shutdown inappropriately, mechanism for halt(8)/reboot(8)

Jilles Tjoelker jilles at stack.nl
Sun Jan 2 22:31:21 UTC 2011


As discussed on the svn-src commits mailing list, I think halt and
reboot should be changed to trigger the shutdown by sending a signal to
init, either directly or by calling shutdown. The new poweroff utility
should do the same as halt -p. A new -f option and the filenames
fastboot and fasthalt keep the current behaviour of killing all
processes and calling reboot(2) directly, and the same applies if one of
the options -d, -n and -q is used (which cannot be passed to init).

I'm aware of shutdown's -o option which makes it call halt(8) or
reboot(8). These invocations should gain the -f option or change to
fasthalt/fastboot.

The current halt and reboot programs do not run /etc/rc.shutdown, which
may cause daemons not to be shut down correctly. At this time, there is
no way to fix this properly, because /etc/rc.shutdown should not be run
from single-user mode (if this is done, /etc/rc.d/mixer overwrites
/var/db/mixer*-state with the defaults, for example) and reboot has no
way to know this.

When rebooting by sending a signal to init (directly, via ctrl+alt+del,
by re-executing /sbin/init or via shutdown), /etc/rc.shutdown is always
executed. The attached patch changes this, executing it only if /etc/rc
has completed.

The bigger-picture goal is to make all the common ways of shutting down
(ctrl+alt+del, shutdown(8), halt(8), reboot(8), poweroff(8)) work
properly both in single-user and multi-user. Currently, only
ctrl+alt+del, shutdown(8) and poweroff(8) work properly in multi-user,
while only halt(8) and reboot(8) work properly in single-user.

The patch also fixes segfaults and other erratic behaviour if init
receives SIGHUP or SIGTSTP while in single-user mode.

The patch does not attempt to fix any badness with signal handlers
(assumption that pointers can be read and written atomically, EINTR race
condition). I believe the patch does not make this badness any worse.

If the attachment does not work, the patch is also here for some time:
http://www.stack.nl/~jilles/unix/init-fixes-20110102.patch

-- 
Jilles Tjoelker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: init-fixes-20110102.patch
Type: text/x-diff
Size: 3255 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20110102/ccfd3392/init-fixes-20110102.bin


More information about the freebsd-arch mailing list