mirror of
https://github.com/troglobit/finit.git
synced 2026-11-10 16:31:21 +00:00
sig.c: Use watchdogd to reboot system
This patch reorders the shutdown/reboot handler slightly and fixes a bug in sleep(). It seems the sleep() syscall was interrupted by receiving lots of SIGCHLD. Unsurprisingly since we just sent all processes SIGTERM, but unfortunate since that was too short time to deliver SIGTERM to watchdogd. We now call sleep() again, as long as it returns a non-zero value, until at most two (2) seconds have passed. During this time we basically pend for watchdogd to do its job and let the WDT reboot the system. If the two second timeout passes we send SIGKILL and forcibly reboot(RB_AUTOBOOT) the system. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
b212babc87
commit
f277166354
1 file changed
+12
-3
@@ -49,6 +49,12 @@
|
|||||||
|
|
||||||
static int stopped = 0;
|
static int stopped = 0;
|
||||||
|
|
||||||
|
/* Signal safe sleep ... we get a lot of SIGCHLD at reboot */
|
||||||
|
void do_sleep(unsigned int sec)
|
||||||
|
{
|
||||||
|
while ((sec = sleep(sec)))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
void do_shutdown (int sig)
|
void do_shutdown (int sig)
|
||||||
{
|
{
|
||||||
@@ -57,12 +63,15 @@ void do_shutdown (int sig)
|
|||||||
if (sdown)
|
if (sdown)
|
||||||
run_interactive(sdown, "Calling shutdown hook: %s", sdown);
|
run_interactive(sdown, "Calling shutdown hook: %s", sdown);
|
||||||
|
|
||||||
|
/* Call all shutdown hooks before rebooting... */
|
||||||
|
plugin_run_hooks(HOOK_SHUTDOWN);
|
||||||
|
|
||||||
|
/* Here is where we signal watchdogd to do a forced reset for us */
|
||||||
_d("Sending SIGTERM to all processes.");
|
_d("Sending SIGTERM to all processes.");
|
||||||
kill(-1, SIGTERM);
|
kill(-1, SIGTERM);
|
||||||
|
|
||||||
sleep(1);
|
/* Wait for WDT to timeout, should be no more than ~1 sec. */
|
||||||
/* Call all shutdown hooks, this is the last call before rebooting... */
|
do_sleep(2);
|
||||||
plugin_run_hooks(HOOK_SHUTDOWN);
|
|
||||||
|
|
||||||
_d("Sending SIGKILL to remaining processes.");
|
_d("Sending SIGKILL to remaining processes.");
|
||||||
kill(-1, SIGKILL);
|
kill(-1, SIGKILL);
|
||||||
|
|||||||
Reference in new issue
Block a user