]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: systemd: report the correct signal in debug message output
authorWilly Tarreau <w@1wt.eu>
Sat, 27 Feb 2016 07:18:04 +0000 (08:18 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 27 Feb 2016 07:28:42 +0000 (08:28 +0100)
Commit c54bdd2 ("MINOR: Also accept SIGHUP/SIGTERM in systemd-wrapper")
added support for extra signals but did not adapt the debug message,
which continues to report incorrect signal types. Let's pass the signal
number to the do_restart() and do_shutdown() functions so that the output
matches the signal that was received.

src/haproxy-systemd-wrapper.c

index 10396aec85482b0f22d8e8c9bb9161c157fb397e..42b0b0791b9787fd90b1179bbc2f59446a4f39af 100644 (file)
@@ -126,15 +126,18 @@ static void signal_handler(int signum)
        caught_signal = signum;
 }
 
-static void do_restart(void)
+/* handles SIGUSR2 and SIGHUP only */
+static void do_restart(int sig)
 {
        setenv(REEXEC_FLAG, "1", 1);
-       fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: re-executing\n");
+       fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: re-executing on %s.\n",
+               sig == SIGUSR2 ? "SIGUSR2" : "SIGHUP");
 
        execv(wrapper_argv[0], wrapper_argv);
 }
 
-static void do_shutdown(void)
+/* handles SIGTERM and SIGINT only */
+static void do_shutdown(int sig)
 {
        int i, pid;
        char **pid_strv = NULL;
@@ -142,7 +145,8 @@ static void do_shutdown(void)
        for (i = 0; i < nb_pid; ++i) {
                pid = atoi(pid_strv[i]);
                if (pid > 0) {
-                       fprintf(stderr, SD_DEBUG "haproxy-systemd-wrapper: SIGINT -> %d\n", pid);
+                       fprintf(stderr, SD_DEBUG "haproxy-systemd-wrapper: %s -> %d.\n",
+                               sig == SIGTERM ? "SIGTERM" : "SIGINT", pid);
                        kill(pid, SIGINT);
                        free(pid_strv[i]);
                }
@@ -198,13 +202,15 @@ int main(int argc, char **argv)
 
        status = -1;
        while (caught_signal || wait(&status) != -1 || errno == EINTR) {
+               int sig = caught_signal;
+
                if (caught_signal == SIGUSR2 || caught_signal == SIGHUP) {
                        caught_signal = 0;
-                       do_restart();
+                       do_restart(sig);
                }
                else if (caught_signal == SIGINT || caught_signal == SIGTERM) {
                        caught_signal = 0;
-                       do_shutdown();
+                       do_shutdown(sig);
                }
        }