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.
(cherry picked from commit 2fadbe5b0a69e03f51d655b7324a176335bd7fdb)
(cherry picked from commit 2fd5fe6598fd33f2dc515c0b716185377575eb0a)
diff --git a/src/haproxy-systemd-wrapper.c b/src/haproxy-systemd-wrapper.c
index 507edd8..7af5759 100644
--- a/src/haproxy-systemd-wrapper.c
+++ b/src/haproxy-systemd-wrapper.c
@@ -126,15 +126,18 @@
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 @@
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 @@
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);
}
}