From: Willy Tarreau Date: Sat, 27 Feb 2016 07:18:04 +0000 (+0100) Subject: BUG/MINOR: systemd: report the correct signal in debug message output X-Git-Tag: v1.7-dev2~71 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2fadbe5b0a69e03f51d655b7324a176335bd7fdb;p=thirdparty%2Fhaproxy.git BUG/MINOR: systemd: report the correct signal in debug message output 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. --- diff --git a/src/haproxy-systemd-wrapper.c b/src/haproxy-systemd-wrapper.c index 10396aec85..42b0b0791b 100644 --- a/src/haproxy-systemd-wrapper.c +++ b/src/haproxy-systemd-wrapper.c @@ -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); } }