Kill processes on shutdown
authorMichel Stam <m.stam@fugro.nl>
Thu, 2 Oct 2014 11:56:20 +0000 (11:56 +0000)
committerJohn Crispin <blogic@openwrt.org>
Thu, 2 Oct 2014 17:18:52 +0000 (19:18 +0200)
Procd as it currently is does not kill the running processes during shutdown.
As this might cause undesired behaviour, this should be implemented.
Implementation was taken from busybox 1.19.4

Signed-off-by: Michel Stam <m.stam@fugro.nl>
state.c

diff --git a/state.c b/state.c
index bba59665167df085bda91337dadb447332b4376d..b9416341440d873b999dadbda8e6b43a0b9a3477 100644 (file)
--- a/state.c
+++ b/state.c
@@ -15,6 +15,8 @@
 #include <sys/reboot.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
 
 #include "procd.h"
 #include "syslog.h"
@@ -75,6 +77,14 @@ static void state_enter(void)
                break;
 
        case STATE_HALT:
+               LOG("- SIGTERM processes -\n");
+               kill(-1, SIGTERM);
+               sync();
+               sleep(1);
+               LOG("- SIGKILL processes -\n");
+               kill(-1, SIGKILL);
+               sync();
+               sleep(1);
                LOG("- reboot -\n");
                reboot(reboot_event);
                break;