SHA256
1
0
forked from pool/haproxy
haproxy/0007-MEDIUM-systemd-wrapper-Kill-child-processes-when-int.patch
2014-05-06 15:38:15 +00:00

62 lines
1.7 KiB
Diff

From e2f3c212072dcf1e9b809fc2cb774946eaba665f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristoffer=20Gr=C3=B6nlund?= <krig@koru.se>
Date: Fri, 22 Nov 2013 11:09:39 +0100
Subject: [PATCH 07/15] MEDIUM: systemd-wrapper: Kill child processes when
interrupted
Send SIGINT to child processes when killed. This ensures that
the haproxy process managed by the systemd-wrapper is stopped
when "systemctl stop haproxy.service" is called.
---
src/haproxy-systemd-wrapper.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/src/haproxy-systemd-wrapper.c b/src/haproxy-systemd-wrapper.c
index 6546616b79ee..d337f4c0d44e 100644
--- a/src/haproxy-systemd-wrapper.c
+++ b/src/haproxy-systemd-wrapper.c
@@ -83,7 +83,7 @@ static int read_pids(char ***pid_strv)
return read;
}
-static void signal_handler(int signum __attribute__((unused)))
+static void sigusr2_handler(int signum __attribute__((unused)))
{
int i;
char **pid_strv = NULL;
@@ -96,6 +96,21 @@ static void signal_handler(int signum __attribute__((unused)))
free(pid_strv);
}
+static void sigint_handler(int signum __attribute__((unused)))
+{
+ int i, pid;
+ char **pid_strv = NULL;
+ int nb_pid = read_pids(&pid_strv);
+ for (i = 0; i < nb_pid; ++i) {
+ pid = atoi(pid_strv[i]);
+ if (pid > 0) {
+ kill(pid, SIGINT);
+ free(pid_strv[i]);
+ }
+ }
+ free(pid_strv);
+}
+
static void init(int argc, char **argv)
{
while (argc > 1) {
@@ -117,7 +132,8 @@ int main(int argc, char **argv)
init(argc, argv);
- signal(SIGUSR2, &signal_handler);
+ signal(SIGINT, &sigint_handler);
+ signal(SIGUSR2, &sigusr2_handler);
spawn_haproxy(NULL, 0);
while (-1 != wait(NULL) || errno == EINTR);
--
1.8.4.5