From 05be3e8be8e3ef7ec4326290192c36577d6c6024 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Wed, 9 Aug 2023 14:02:34 +0100 Subject: [PATCH] core: split manager's process killing on shutdown to separate helper --- src/core/main.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index 1fe93a2f554..e6932784d15 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -1818,6 +1818,19 @@ static void filter_args( } } +static void finish_remaining_processes(ManagerObjective objective) { + assert(objective >= 0 && objective < _MANAGER_OBJECTIVE_MAX); + + /* Kill all remaining processes from the initrd, but don't wait for them, so that we can handle the + * SIGCHLD for them after deserializing. */ + if (IN_SET(objective, MANAGER_SWITCH_ROOT, MANAGER_SOFT_REBOOT)) + broadcast_signal(SIGTERM, /* wait_for_exit= */ false, /* send_sighup= */ true, arg_default_timeout_stop_usec); + + /* On soft reboot really make sure nothing is left */ + if (objective == MANAGER_SOFT_REBOOT) + broadcast_signal(SIGKILL, /* wait_for_exit= */ false, /* send_sighup= */ false, arg_default_timeout_stop_usec); +} + static int do_reexecute( ManagerObjective objective, int argc, @@ -1868,13 +1881,7 @@ static int do_reexecute( if (saved_rlimit_memlock->rlim_cur != RLIM_INFINITY) (void) setrlimit(RLIMIT_MEMLOCK, saved_rlimit_memlock); - /* Kill all remaining processes from the initrd, but don't wait for them, so that we can handle the - * SIGCHLD for them after deserializing. */ - if (IN_SET(objective, MANAGER_SWITCH_ROOT, MANAGER_SOFT_REBOOT)) - broadcast_signal(SIGTERM, /* wait_for_exit= */ false, /* send_sighup= */ true, arg_default_timeout_stop_usec); - /* On soft reboot really make sure nothing is left */ - if (objective == MANAGER_SOFT_REBOOT) - broadcast_signal(SIGKILL, /* wait_for_exit= */ false, /* send_sighup= */ false, arg_default_timeout_stop_usec); + finish_remaining_processes(objective); if (!switch_root_dir && objective == MANAGER_SOFT_REBOOT) { /* If no switch root dir is specified, then check if /run/nextroot/ qualifies and use that */ -- 2.47.3