]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: systemd-wrapper: Kill child processes when interrupted
authorKristoffer Grönlund <krig@koru.se>
Fri, 22 Nov 2013 10:09:39 +0000 (11:09 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 23 Nov 2013 11:06:51 +0000 (12:06 +0100)
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

index 6546616b79ee711386bf5a731d6eb9b2fdf24dad..d337f4c0d44e2a384aa4bef632d3a695e8bed344 100644 (file)
@@ -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);