Use process groups for services

This lets us properly signal services with child processes of their own.
This commit is contained in:
C. McEnroe 2020-08-16 00:27:08 -04:00
parent 844f34a0c1
commit 3fbe9b5933

View File

@ -174,6 +174,7 @@ void serviceStart(struct Service *service) {
return; return;
} }
setpgid(0, 0);
dup2(service->outPipe[1], STDOUT_FILENO); dup2(service->outPipe[1], STDOUT_FILENO);
dup2(service->errPipe[1], STDERR_FILENO); dup2(service->errPipe[1], STDERR_FILENO);
@ -207,10 +208,10 @@ void serviceStart(struct Service *service) {
void serviceSignal(struct Service *service, int signal) { void serviceSignal(struct Service *service, int signal) {
if (service->state != Start) return; if (service->state != Start) return;
int error = kill(service->pid, signal); int error = killpg(service->pid, signal);
if (error) { if (error) {
syslog( syslog(
LOG_WARNING, "kill(%s[%d], %s): %m", LOG_WARNING, "killpg(%s[%d], %s): %m",
service->name, service->pid, sys_signame[signal] service->name, service->pid, sys_signame[signal]
); );
} }