about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-01-09 13:44:50 +0100
committerLeah Neukirchen <leah@vuxu.org>2024-01-09 13:44:50 +0100
commitdfd9e40e6af48218641983f1b4181b90275c80bd (patch)
treeead201da6cdc6b9997ff4c38ae1e6f0f18474066
parentd2a487e92b1313c062e1107041cf18db01fac7d0 (diff)
downloadnitro-dfd9e40e6af48218641983f1b4181b90275c80bd.tar.gz
nitro-dfd9e40e6af48218641983f1b4181b90275c80bd.tar.xz
nitro-dfd9e40e6af48218641983f1b4181b90275c80bd.zip
send SIGTERM/SIGKILL to all processes on shutdown
-rw-r--r--nitro.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/nitro.c b/nitro.c
index d200422..c66c108 100644
--- a/nitro.c
+++ b/nitro.c
@@ -725,6 +725,8 @@ on_signal(int sig)
 	case SIGHUP:
 		want_rescan = 1;
 		break;
+	case SIGALRM:		/* just for EINTR */
+		break;
 	}
 
 	errno = old_errno;
@@ -1454,6 +1456,27 @@ main(int argc, char *argv[])
 	}
 
 #ifdef __linux__
+	if (pid1) {
+		prn(2, "- nitro: sending SIGTERM to all processes\n");
+		kill(-1, SIGTERM);
+		kill(-1, SIGCONT);
+
+		struct sigaction sa = {
+			.sa_handler = on_signal,
+			.sa_mask = allset,
+		};
+		sigaction(SIGALRM, &sa, 0);
+		alarm(3);
+
+		while(1) {
+			int r = waitpid(-1, 0, 0);
+			if (r < 0)
+				break;
+		}
+
+		prn(2, "- nitro: sending SIGKILL to all processes\n");
+		kill(-1, SIGKILL);
+	}
 	if (real_pid1) {
 		prn(2, "- nitro: system %s\n",
 		    global_state == GLBL_WANT_REBOOT ? "reboot" : "halt");