From dcf8fbe235d1e9dfc1e6b101a6cb3983439fb6f6 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Thu, 28 Dec 2017 20:40:30 +0100 Subject: [PATCH] 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 --- src/sig.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/sig.c b/src/sig.c index 2c5c5917..b4de14f3 100644 --- a/src/sig.c +++ b/src/sig.c @@ -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); }