do_shutdown(): Advise watchdog using SIGPWR, system is going down

On shutdown/reboot, send SIGPR as a heads-up to watchdogd that the
system is going down.  All file systems are about to be unmounted.
It's just about the last process left running in the system, so we
give it two seconds to complete its work before we continue.

When everything has been unmounted and we're ready to call reboot(),
we send SIGTERM to the registered watchdog, to give ti the chance to
let the WDT reset the system.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2017-12-28 20:45:02 +01:00
parent c82a2ce215
commit dcf8fbe235
+8 -1
View File
@@ -133,6 +133,8 @@ void do_kill(int signo)
if (fgets(file, sizeof(file), fp)) {
if (file[0] != '@')
kill(pid, signo);
else
_d("Skipping %s ...", &file[1]);
}
fclose(fp);
}
@@ -179,6 +181,11 @@ void do_shutdown(shutop_t op)
return;
}
if (wdogpid) {
print(kill(wdogpid, SIGPWR) == 1, "Advising watchdog, system going down");
do_sleep(2);
}
/* Unmount any tmpfs before unmounting swap ... */
unmount_tmpfs();
run("swapoff -e -a");
@@ -201,7 +208,7 @@ void do_shutdown(shutop_t op)
int timeout = 10;
/* Wait here until the WDT reboots, or timeout with fallback */
print(kill(wdogpid, SIGPWR) == 1, "Pending watchdog reboot");
print(kill(wdogpid, SIGTERM) == 1, "Pending watchdog reboot");
while (timeout--)
do_sleep(1);
}