init: Waiting for all processes to die before restarting

Mike Crowe mac at mcrowe.com
Fri Aug 16 11:02:02 UTC 2013


I believe that the removal of the sleep(1); after sending SIGKILL to
all processes in commit 4ae8a05b131836184eb32c440a6bf814ff81b069 may
cause problems when a new init is executed due to receiving
SIGQUIT. I'm also suspicious that sleep(1) was not really the best
solution anyway but happened to work for me.

As far as I can tell there is no guarantee that the kernel will have
finished tearing down all the processes killed by
run_shutdown_and_kill_processes in response to a SIGQUIT before the
new init is executed. This means that:

1. The new init may fail due to files still being open. (The previous
sleep(1) probably avoided this.)

2. The new init becomes responsible for reaping those processes. (The
sleep(1) doesn't help with this.)

In my particular case the new init is a shell script which unmounts
all the file systems in preparation for a firmware update. This
sometimes fails because the kernel hasn't finished closing all the
files on that filesystem.

Adding back the sleep(1) in run_shutdown_and_kill_processes or in
restart_handler would mostly hide this problem but perhaps init should
actually wait for all processes to die and reap them before restarting?

sysvinit just seems to sleep(1) after SIGKILL but it doesn't send it
in the restart case anyway.

systemd does appear to wait for the processes to exit in response to
SIGKILL (via broadcast_signal.)

Mike.


More information about the busybox mailing list