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.
This commit is contained in:
Willy Tarreau 2016-02-27 08:18:04 +01:00
parent 1ab5e8642a
commit 2fadbe5b0a

View 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);
}
}