mirror of
https://github.com/troglobit/finit.git
synced 2026-10-31 13:00:32 +00: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:
1 parent
1177c734ce
commit
3de9e4e5db
1 file changed
+2
-10
@@ -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);
|
||||||
@@ -257,6 +247,8 @@ static int service_start(svc_t *svc)
|
|||||||
result = WEXITSTATUS(complete(svc->cmd, pid));
|
result = WEXITSTATUS(complete(svc->cmd, pid));
|
||||||
svc->pid = 0;
|
svc->pid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sigprocmask(SIG_SETMASK, &omask, NULL);
|
||||||
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
print_result(result);
|
print_result(result);
|
||||||
|
|||||||
Reference in new issue
Block a user