Skip to content

Commit ef43006

Browse files
ftakeYHNdnzj
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
1 parent a035a33 commit ef43006

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
@@ -2231,7 +2231,7 @@ static bool service_good(Service *s) {
22312231
main_pid_ok = main_pid_good(s);
22322232
if (main_pid_ok > 0) /* It's alive */
22332233
return true;
2234-
if (main_pid_ok == 0) /* It's dead */
2234+
if (main_pid_ok == 0 && s->exit_type == SERVICE_EXIT_MAIN) /* It's dead */
22352235
return false;
22362236

22372237
/* OK, we don't know anything about the main PID, maybe
@@ -3879,7 +3879,12 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
38793879
default:
38803880
assert_not_reached();
38813881
}
3882-
}
3882+
} else if (s->exit_type == SERVICE_EXIT_CGROUP && s->state == SERVICE_START)
3883+
/* If a main process exits very quickly, this function might be executed
3884+
* before service_dispatch_exec_io(). Since this function disabled IO events
3885+
* to monitor the main process above, we need to update the state here too.
3886+
* Let's consider the process is successfully launched and exited. */
3887+
service_enter_start_post(s);
38833888
}
38843889

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

0 commit comments

Comments
 (0)