Fix potential race condition/hang for SVC_TYPE_RUN services

In service_start() the SIGCHLD handler is reenabled before calling complete(), so the service could be reaped by the SIGCHLD handler leaving service_start() waiting forever
Also remove code that duplicates sig_unblock()
This commit is contained in:
Patrick Stewart
2016-04-13 22:09:05 +01:00
parent 1177c734ce
commit 3de9e4e5db
Regular → Executable
+2 -10
View File
@@ -162,7 +162,6 @@ static int service_start(svc_t *svc)
sigprocmask(SIG_BLOCK, &nmask, &omask);
pid = fork();
sigprocmask(SIG_SETMASK, &omask, NULL);
if (pid == 0) {
int i = 0;
int status;
@@ -171,17 +170,8 @@ static int service_start(svc_t *svc)
#else
int uid = getuser(svc->username);
#endif
struct sigaction sa;
char *args[MAX_NUM_SVC_ARGS];
sigemptyset(&nmask);
sigaddset(&nmask, SIGCHLD);
sigprocmask(SIG_UNBLOCK, &nmask, NULL);
/* Reset signal handlers that were set by the parent process */
for (i = 1; i < NSIG; i++)
DFLSIG(sa, i, 0);
/* Set desired user */
if (uid >= 0) {
setuid(uid);
@@ -257,6 +247,8 @@ static int service_start(svc_t *svc)
result = WEXITSTATUS(complete(svc->cmd, pid));
svc->pid = 0;
}
sigprocmask(SIG_SETMASK, &omask, NULL);
if (!silent)
print_result(result);