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 committed 2016-04-13 22:09:05 +01:00
1 parent 1177c734ce
commit 3de9e4e5db
1 file changed
+2 -10
Regular → Executable
+2 -10
View File
@@ -162,7 +162,6 @@ static int service_start(svc_t *svc)
sigprocmask(SIG_BLOCK, &nmask, &omask); sigprocmask(SIG_BLOCK, &nmask, &omask);
pid = fork(); pid = fork();
sigprocmask(SIG_SETMASK, &omask, NULL);
if (pid == 0) { if (pid == 0) {
int i = 0; int i = 0;
int status; int status;
@@ -171,17 +170,8 @@ static int service_start(svc_t *svc)
#else #else
int uid = getuser(svc->username); int uid = getuser(svc->username);
#endif #endif
struct sigaction sa;
char *args[MAX_NUM_SVC_ARGS]; 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 */ /* Set desired user */
if (uid >= 0) { if (uid >= 0) {
setuid(uid); setuid(uid);
@@ -258,6 +248,8 @@ static int service_start(svc_t *svc)
svc->pid = 0; svc->pid = 0;
} }
sigprocmask(SIG_SETMASK, &omask, NULL);
if (!silent) if (!silent)
print_result(result); print_result(result);