]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: use helper functions like unit_main_pid() in unit_kill_context()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 24 Jan 2024 05:02:46 +0000 (14:02 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 24 Jan 2024 05:43:18 +0000 (14:43 +0900)
No functional changes. Just refactoring.

src/core/mount.c
src/core/scope.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/unit.c
src/core/unit.h

index 048802fa1be85e230d88f945d75c8ef5a4891841..d840414d1a3cba807ada9488f437f57e54974f80 100644 (file)
@@ -1033,13 +1033,7 @@ static void mount_enter_signal(Mount *m, MountState state, MountResult f) {
         if (m->result == MOUNT_SUCCESS)
                 m->result = f;
 
-        r = unit_kill_context(
-                        UNIT(m),
-                        &m->kill_context,
-                        state_to_kill_operation(state),
-                        /* main_pid= */ NULL,
-                        &m->control_pid,
-                        /* main_pid_alien= */ false);
+        r = unit_kill_context(UNIT(m), state_to_kill_operation(state));
         if (r < 0) {
                 log_unit_warning_errno(UNIT(m), r, "Failed to kill processes: %m");
                 goto fail;
index e4c27da91d23541122cef739219ce36eb8677c86..8cbbf25801e368edefdfa55d851ff34cbf08a99f 100644 (file)
@@ -317,13 +317,9 @@ static void scope_enter_signal(Scope *s, ScopeState state, ScopeResult f) {
         else {
                 r = unit_kill_context(
                                 UNIT(s),
-                                &s->kill_context,
                                 state != SCOPE_STOP_SIGTERM ? KILL_KILL :
                                 s->was_abandoned            ? KILL_TERMINATE_AND_LOG :
-                                                              KILL_TERMINATE,
-                                /* main_pid= */ NULL,
-                                /* control_pid= */ NULL,
-                                /* main_pid_alien= */ false);
+                                                              KILL_TERMINATE);
                 if (r < 0) {
                         log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
                         goto fail;
index 4f53a0dc060e5d3de872523014235d0e89162ee2..97b547084eebc982e302410042213009a6ea98f3 100644 (file)
@@ -2121,13 +2121,7 @@ static void service_enter_signal(Service *s, ServiceState state, ServiceResult f
         (void) unit_enqueue_rewatch_pids(UNIT(s));
 
         kill_operation = state_to_kill_operation(s, state);
-        r = unit_kill_context(
-                        UNIT(s),
-                        &s->kill_context,
-                        kill_operation,
-                        &s->main_pid,
-                        &s->control_pid,
-                        s->main_pid_alien);
+        r = unit_kill_context(UNIT(s), kill_operation);
         if (r < 0) {
                 log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
                 goto fail;
index e539e2ca0bef5d5f968919cfbfdd956cf618732f..57f6ab18db2c57708a5248da49d0b0f0527172d3 100644 (file)
@@ -2070,13 +2070,7 @@ static void socket_enter_signal(Socket *s, SocketState state, SocketResult f) {
         if (s->result == SOCKET_SUCCESS)
                 s->result = f;
 
-        r = unit_kill_context(
-                        UNIT(s),
-                        &s->kill_context,
-                        state_to_kill_operation(s, state),
-                        /* main_pid= */ NULL,
-                        &s->control_pid,
-                        /* main_pid_alien= */ false);
+        r = unit_kill_context(UNIT(s), state_to_kill_operation(s, state));
         if (r < 0) {
                 log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
                 goto fail;
index 9f7c12b0c3cf12c73ab7d2e9b0a0f86280536861..0022a3d0ac744c8ce81c09d82473e689b6c40b10 100644 (file)
@@ -734,13 +734,7 @@ static void swap_enter_signal(Swap *s, SwapState state, SwapResult f) {
         if (s->result == SWAP_SUCCESS)
                 s->result = f;
 
-        r = unit_kill_context(
-                        UNIT(s),
-                        &s->kill_context,
-                        state_to_kill_operation(s, state),
-                        /* main_pid= */ NULL,
-                        &s->control_pid,
-                        /* main_pid_alien= */ false);
+        r = unit_kill_context(UNIT(s), state_to_kill_operation(s, state));
         if (r < 0) {
                 log_unit_warning_errno(UNIT(s), r, "Failed to kill processes: %m");
                 goto fail;
index 1c7225bb8f19efc3af1729a2dec1a505311eaba8..1e0a3d86302b7566ba59783d937dca4e0aa9b6c9 100644 (file)
@@ -4749,26 +4749,19 @@ static int operation_to_signal(
         }
 }
 
-int unit_kill_context(
-                Unit *u,
-                KillContext *c,
-                KillOperation k,
-                PidRef* main_pid,
-                PidRef* control_pid,
-                bool main_pid_alien) {
-
+int unit_kill_context(Unit *u, KillOperation k) {
         bool wait_for_exit = false, send_sighup;
         cg_kill_log_func_t log_func = NULL;
         int sig, r;
 
         assert(u);
-        assert(c);
 
         /* Kill the processes belonging to this unit, in preparation for shutting the unit down.  Returns > 0
          * if we killed something worth waiting for, 0 otherwise. Do not confuse with unit_kill_common()
          * which is used for user-requested killing of unit processes. */
 
-        if (c->kill_mode == KILL_NONE)
+        KillContext *c = unit_get_kill_context(u);
+        if (!c || c->kill_mode == KILL_NONE)
                 return 0;
 
         bool noteworthy;
@@ -4781,6 +4774,8 @@ int unit_kill_context(
                 IN_SET(k, KILL_TERMINATE, KILL_TERMINATE_AND_LOG) &&
                 sig != SIGHUP;
 
+        bool is_alien;
+        PidRef *main_pid = unit_main_pid_full(u, &is_alien);
         if (pidref_is_set(main_pid)) {
                 if (log_func)
                         log_func(main_pid, sig, u);
@@ -4792,7 +4787,7 @@ int unit_kill_context(
 
                         log_unit_warning_errno(u, r, "Failed to kill main process " PID_FMT " (%s), ignoring: %m", main_pid->pid, strna(comm));
                 } else {
-                        if (!main_pid_alien)
+                        if (!is_alien)
                                 wait_for_exit = true;
 
                         if (r != -ESRCH && send_sighup)
@@ -4800,6 +4795,7 @@ int unit_kill_context(
                 }
         }
 
+        PidRef *control_pid = unit_control_pid(u);
         if (pidref_is_set(control_pid)) {
                 if (log_func)
                         log_func(control_pid, sig, u);
index eb94ff2964143feb6282317807cc43972c9d4902..1d43acc01834ca12b28486ad7a69274f7dd7a84d 100644 (file)
@@ -1006,7 +1006,7 @@ char* unit_concat_strv(char **l, UnitWriteFlags flags);
 int unit_write_setting(Unit *u, UnitWriteFlags flags, const char *name, const char *data);
 int unit_write_settingf(Unit *u, UnitWriteFlags mode, const char *name, const char *format, ...) _printf_(4,5);
 
-int unit_kill_context(Unit *u, KillContext *c, KillOperation k, PidRef *main_pid, PidRef *control_pid, bool main_pid_alien);
+int unit_kill_context(Unit *u, KillOperation k);
 
 int unit_make_transient(Unit *u);