Skip to content

Commit b2ad47b

Browse files
committed
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 6209e06 commit b2ad47b

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
@@ -1987,7 +1987,7 @@ static bool service_good(Service *s) {
19871987
main_pid_ok = main_pid_good(s);
19881988
if (main_pid_ok > 0) /* It's alive */
19891989
return true;
1990-
if (main_pid_ok == 0) /* It's dead */
1990+
if (main_pid_ok == 0 && s->exit_type == SERVICE_EXIT_MAIN) /* It's dead */
19911991
return false;
19921992

19931993
/* OK, we don't know anything about the main PID, maybe
@@ -3565,7 +3565,12 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
35653565
default:
35663566
assert_not_reached("Uh, main process died at wrong time.");
35673567
}
3568-
}
3568+
} else if (s->exit_type == SERVICE_EXIT_CGROUP && s->state == SERVICE_START)
3569+
/* If a main process exits very quickly, this function might be executed
3570+
* before service_dispatch_exec_io(). Since this function disabled IO events
3571+
* to monitor the main process above, we need to update the state here too.
3572+
* Let's consider the process is successfully launched and exited. */
3573+
service_enter_start_post(s);
35693574
}
35703575

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

0 commit comments

Comments
 (0)