mirror of
https://github.com/troglobit/finit.git
synced 2026-10-02 05:52:48 +07:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user