]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: add comment explaining event source deallocation
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Jul 2021 09:06:45 +0000 (11:06 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 1 Jul 2021 13:22:33 +0000 (15:22 +0200)
Followup for bc989831e6. The original reproducer still works w/o the unref,
and doesn't work with this change.

src/core/service.c

index 8517d5441c38cf5ff1feab9cf542057d5f54e727..cb0a528f0d62b23175e430d67fa710ade81a666c 100644 (file)
@@ -3384,11 +3384,6 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
         else
                 clean_mode = EXIT_CLEAN_DAEMON;
 
-        if (s->main_pid == pid)
-                /* Clean up the exec_fd event source. The source owns its end of the pipe, so this will close
-                 * that too. */
-                s->exec_fd_event_source = sd_event_source_disable_unref(s->exec_fd_event_source);
-
         if (is_clean_exit(code, status, clean_mode, &s->success_status))
                 f = SERVICE_SUCCESS;
         else if (code == CLD_EXITED)
@@ -3401,6 +3396,11 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
                 assert_not_reached("Unknown code");
 
         if (s->main_pid == pid) {
+                /* Clean up the exec_fd event source. We want to do this here, not later in
+                 * service_set_state(), because service_enter_stop_post() calls service_spawn().
+                 * The source owns its end of the pipe, so this will close that too. */
+                s->exec_fd_event_source = sd_event_source_disable_unref(s->exec_fd_event_source);
+
                 /* Forking services may occasionally move to a new PID.
                  * As long as they update the PID file before exiting the old
                  * PID, they're fine. */