]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: unexport cg_kill log funcs, rather take in bool
authorMike Yuan <me@yhndnzj.com>
Tue, 30 Jul 2024 19:37:36 +0000 (21:37 +0200)
committerMike Yuan <me@yhndnzj.com>
Fri, 2 Aug 2024 14:36:08 +0000 (16:36 +0200)
It seems unnecessary to duplicate the func ptrs everywhere.

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

index e040f151f42b8c86c511818d5473c0397338ba26..61aa8bb590ae74a7d6d37725a4e4d07139a178cb 100644 (file)
@@ -919,7 +919,7 @@ static void mount_enter_dead(Mount *m, MountResult f, bool flush_result) {
                 m->result = f;
 
         unit_log_result(UNIT(m), m->result == MOUNT_SUCCESS, mount_result_to_string(m->result));
-        unit_warn_leftover_processes(UNIT(m), unit_log_leftover_process_stop);
+        unit_warn_leftover_processes(UNIT(m), /* start = */ false);
 
         mount_set_state(m, m->result != MOUNT_SUCCESS ? MOUNT_FAILED : MOUNT_DEAD);
 
@@ -1176,7 +1176,7 @@ static void mount_enter_mounting(Mount *m) {
 
         if (source_is_dir)
                 unit_warn_if_dir_nonempty(UNIT(m), m->where);
-        unit_warn_leftover_processes(UNIT(m), unit_log_leftover_process_start);
+        unit_warn_leftover_processes(UNIT(m), /* start = */ true);
 
         m->control_command_id = MOUNT_EXEC_MOUNT;
         m->control_command = m->exec_command + MOUNT_EXEC_MOUNT;
index 4403b209bdeab81acbef243837fb6893afde8c39..2c6d83babe5692e4f0d367c86421582cc7ade587 100644 (file)
@@ -2035,7 +2035,7 @@ static void service_enter_dead(Service *s, ServiceResult f, bool allow_restart)
                 end_state = SERVICE_FAILED;
                 restart_state = SERVICE_FAILED_BEFORE_AUTO_RESTART;
         }
-        unit_warn_leftover_processes(UNIT(s), unit_log_leftover_process_stop);
+        unit_warn_leftover_processes(UNIT(s), /* start = */ false);
 
         if (!allow_restart)
                 log_unit_debug(UNIT(s), "Service restart not allowed.");
@@ -2387,11 +2387,11 @@ static int service_adverse_to_leftover_processes(Service *s) {
          * instances running, lets not stress the rigor of these. Also ExecStartPre= parts of the service
          * aren't as rigoriously written to protect aganst against multiple use. */
 
-        if (unit_warn_leftover_processes(UNIT(s), unit_log_leftover_process_start) > 0 &&
+        if (unit_warn_leftover_processes(UNIT(s), /* start = */ true) > 0 &&
             IN_SET(s->kill_context.kill_mode, KILL_MIXED, KILL_CONTROL_GROUP) &&
             !s->kill_context.send_sigkill)
-               return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EBUSY),
-                                           "Will not start SendSIGKILL=no service of type KillMode=control-group or mixed while processes exist");
+                return log_unit_error_errno(UNIT(s), SYNTHETIC_ERRNO(EBUSY),
+                                            "Will not start SendSIGKILL=no service of type KillMode=control-group or mixed while processes exist");
 
         return 0;
 }
index 5042e4b0784a9a2d86e054253749430696f6f7a0..da9aa9a4a7868e16e8301e4cd5dfb516e2ce3879 100644 (file)
@@ -2061,7 +2061,7 @@ static void socket_enter_dead(Socket *s, SocketResult f) {
         else
                 unit_log_failure(UNIT(s), socket_result_to_string(s->result));
 
-        unit_warn_leftover_processes(UNIT(s), unit_log_leftover_process_stop);
+        unit_warn_leftover_processes(UNIT(s), /* start = */ false);
 
         socket_set_state(s, s->result != SOCKET_SUCCESS ? SOCKET_FAILED : SOCKET_DEAD);
 
@@ -2262,7 +2262,7 @@ static void socket_enter_start_pre(Socket *s) {
 
         socket_unwatch_control_pid(s);
 
-        unit_warn_leftover_processes(UNIT(s), unit_log_leftover_process_start);
+        unit_warn_leftover_processes(UNIT(s), /* start = */ true);
 
         s->control_command_id = SOCKET_EXEC_START_PRE;
         s->control_command = s->exec_command[SOCKET_EXEC_START_PRE];
index e6f6f78dc9c355046da7c8d4aea5839a2fd78c15..3b76ae33a3c0969a05aa7d85f695f377562ce8cc 100644 (file)
@@ -670,7 +670,8 @@ static void swap_enter_dead(Swap *s, SwapResult f) {
                 s->result = f;
 
         unit_log_result(UNIT(s), s->result == SWAP_SUCCESS, swap_result_to_string(s->result));
-        unit_warn_leftover_processes(UNIT(s), unit_log_leftover_process_stop);
+        unit_warn_leftover_processes(UNIT(s), /* start = */ false);
+
         swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
 
         s->exec_runtime = exec_runtime_destroy(s->exec_runtime);
@@ -752,7 +753,7 @@ static void swap_enter_activating(Swap *s) {
 
         assert(s);
 
-        unit_warn_leftover_processes(UNIT(s), unit_log_leftover_process_start);
+        unit_warn_leftover_processes(UNIT(s), /* start = */ true);
 
         s->control_command_id = SWAP_EXEC_ACTIVATE;
         s->control_command = s->exec_command + SWAP_EXEC_ACTIVATE;
index b2055850544a92520d667026eefe4a8b5b422eda..fa28f67f34e0ab8cecbfdbf200d025c2a3a693ec 100644 (file)
@@ -5840,7 +5840,8 @@ static bool ignore_leftover_process(const char *comm) {
         return comm && comm[0] == '('; /* Most likely our own helper process (PAM?), ignore */
 }
 
-int unit_log_leftover_process_start(const PidRef *pid, int sig, void *userdata) {
+static int unit_log_leftover_process_start(const PidRef *pid, int sig, void *userdata) {
+        const Unit *u = ASSERT_PTR(userdata);
         _cleanup_free_ char *comm = NULL;
 
         assert(pidref_is_set(pid));
@@ -5852,7 +5853,7 @@ int unit_log_leftover_process_start(const PidRef *pid, int sig, void *userdata)
 
         /* During start we print a warning */
 
-        log_unit_warning(userdata,
+        log_unit_warning(u,
                          "Found left-over process " PID_FMT " (%s) in control group while starting unit. Ignoring.\n"
                          "This usually indicates unclean termination of a previous run, or service implementation deficiencies.",
                          pid->pid, strna(comm));
@@ -5860,7 +5861,8 @@ int unit_log_leftover_process_start(const PidRef *pid, int sig, void *userdata)
         return 1;
 }
 
-int unit_log_leftover_process_stop(const PidRef *pid, int sig, void *userdata) {
+static int unit_log_leftover_process_stop(const PidRef *pid, int sig, void *userdata) {
+        const Unit *u = ASSERT_PTR(userdata);
         _cleanup_free_ char *comm = NULL;
 
         assert(pidref_is_set(pid));
@@ -5872,20 +5874,19 @@ int unit_log_leftover_process_stop(const PidRef *pid, int sig, void *userdata) {
 
         /* During stop we only print an informational message */
 
-        log_unit_info(userdata,
+        log_unit_info(u,
                       "Unit process " PID_FMT " (%s) remains running after unit stopped.",
                       pid->pid, strna(comm));
 
         return 1;
 }
 
-int unit_warn_leftover_processes(Unit *u, cg_kill_log_func_t log_func) {
+int unit_warn_leftover_processes(Unit *u, bool start) {
         assert(u);
 
         (void) unit_pick_cgroup_path(u);
 
         CGroupRuntime *crt = unit_get_cgroup_runtime(u);
-
         if (!crt || !crt->cgroup_path)
                 return 0;
 
@@ -5894,7 +5895,7 @@ int unit_warn_leftover_processes(Unit *u, cg_kill_log_func_t log_func) {
                         /* sig= */ 0,
                         /* flags= */ 0,
                         /* set= */ NULL,
-                        log_func,
+                        start ? unit_log_leftover_process_start : unit_log_leftover_process_stop,
                         u);
 }
 
index 115948cd26d77ca914f5349ccf1605fa19fe1f23..bf736a5870492a00a177313d21c8f88117e8ad98 100644 (file)
@@ -990,10 +990,7 @@ void unit_unlink_state_files(Unit *u);
 
 int unit_prepare_exec(Unit *u);
 
-int unit_log_leftover_process_start(const PidRef* pid, int sig, void *userdata);
-int unit_log_leftover_process_stop(const PidRef* pid, int sig, void *userdata);
-
-int unit_warn_leftover_processes(Unit *u, cg_kill_log_func_t log_func);
+int unit_warn_leftover_processes(Unit *u, bool start);
 
 bool unit_needs_console(Unit *u);