From: Kristoffer Grönlund Date: Fri, 22 Nov 2013 10:09:39 +0000 (+0100) Subject: MEDIUM: systemd-wrapper: Kill child processes when interrupted X-Git-Tag: v1.5-dev20~221 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=66fd1d830e0164468320a37b38a1805efb4da21a;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/src/haproxy-systemd-wrapper.c b/src/haproxy-systemd-wrapper.c index 6546616b79..d337f4c0d4 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);