From 1651ce09c049d7dae1b987f0a74d54e7c1bc3231 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 2 Mar 2024 21:03:22 +0800 Subject: [PATCH 1/2] core/service: Type=notify/dbus services shouldn't be considered active when ExitType=cgroup and main process exits Follow-up for ef4300654e70e76ed74f7d544e0f44c5d92fb698 --- src/core/service.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index f11ef0859a..a2a8e4af69 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3877,11 +3877,13 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { default: assert_not_reached(); } - } else if (s->exit_type == SERVICE_EXIT_CGROUP && s->state == SERVICE_START) + } else if (s->exit_type == SERVICE_EXIT_CGROUP && s->state == SERVICE_START && + !IN_SET(s->type, SERVICE_NOTIFY, SERVICE_NOTIFY_RELOAD, SERVICE_DBUS)) /* If a main process exits very quickly, this function might be executed * before service_dispatch_exec_io(). Since this function disabled IO events * to monitor the main process above, we need to update the state here too. - * Let's consider the process is successfully launched and exited. */ + * Let's consider the process is successfully launched and exited, but + * only when we're not expecting a readiness notification or dbus name. */ service_enter_start_post(s); } From f52e9ed62bc27cbb04f8f41bb2c60d2b540e023e Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Sat, 2 Mar 2024 21:22:51 +0800 Subject: [PATCH 2/2] core/service: don't transition to start-post on cgroup empty event with ExitType=cgroup It's not clear to me what the rationale of the logic was when ExitType=cgroup got introduced. But similar to the previous commit, I think we should not transition to 'start-post' on cgroup empty event. This is especially important for Type=dbus/notify services. --- src/core/service.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index a2a8e4af69..a9047be1ca 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3604,8 +3604,10 @@ static void service_notify_cgroup_empty_event(Unit *u) { break; } - if (s->exit_type == SERVICE_EXIT_CGROUP && main_pid_good(s) <= 0) - service_enter_start_post(s); + if (s->exit_type == SERVICE_EXIT_CGROUP && main_pid_good(s) <= 0) { + service_enter_stop_post(s, SERVICE_SUCCESS); + break; + } _fallthrough_; case SERVICE_START_POST: