Skip to content

Commit 789d978

Browse files
ftakebluca
authored andcommitted
core: fix race condition during startup of a service with ExitType=cgroup
This commit allows service_sigchld_event() is executed before service_dispatch_exec_io(), which might happen when a main process exits very quickly. Also do not check PID for service goodness because the main process have already been exited in this case. Fix: #27919 (cherry picked from commit ef43006) (cherry picked from commit ead4050)
1 parent 6f042e5 commit 789d978

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/core/service.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2070,7 +2070,7 @@ static bool service_good(Service *s) {
20702070
main_pid_ok = main_pid_good(s);
20712071
if (main_pid_ok > 0) /* It's alive */
20722072
return true;
2073-
if (main_pid_ok == 0) /* It's dead */
2073+
if (main_pid_ok == 0 && s->exit_type == SERVICE_EXIT_MAIN) /* It's dead */
20742074
return false;
20752075

20762076
/* OK, we don't know anything about the main PID, maybe
@@ -3649,7 +3649,12 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
36493649
default:
36503650
assert_not_reached();
36513651
}
3652-
}
3652+
} else if (s->exit_type == SERVICE_EXIT_CGROUP && s->state == SERVICE_START)
3653+
/* If a main process exits very quickly, this function might be executed
3654+
* before service_dispatch_exec_io(). Since this function disabled IO events
3655+
* to monitor the main process above, we need to update the state here too.
3656+
* Let's consider the process is successfully launched and exited. */
3657+
service_enter_start_post(s);
36533658
}
36543659

36553660
} else if (s->control_pid == pid) {

0 commit comments

Comments
 (0)