mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-07 07:37:02 +02:00
MEDIUM: systemd-wrapper: Kill child processes when interrupted
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.
This commit is contained in:
parent
1b6e75fa84
commit
66fd1d830e
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user