]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/unit: modernize log_kill() too
authorMike Yuan <me@yhndnzj.com>
Tue, 30 Jul 2024 19:44:36 +0000 (21:44 +0200)
committerMike Yuan <me@yhndnzj.com>
Fri, 2 Aug 2024 14:36:09 +0000 (16:36 +0200)
src/core/unit.c

index fa28f67f34e0ab8cecbfdbf200d025c2a3a693ec..c8c34fc0d9b9a21f2df2848ab7e86651620509ac 100644 (file)
@@ -4683,21 +4683,24 @@ int unit_make_transient(Unit *u) {
         return 0;
 }
 
+static bool ignore_leftover_process(const char *comm) {
+        return comm && comm[0] == '('; /* Most likely our own helper process (PAM?), ignore */
+}
+
 static int log_kill(const PidRef *pid, int sig, void *userdata) {
+        const Unit *u = ASSERT_PTR(userdata);
         _cleanup_free_ char *comm = NULL;
 
         assert(pidref_is_set(pid));
 
         (void) pidref_get_comm(pid, &comm);
 
-        /* Don't log about processes marked with brackets, under the assumption that these are temporary processes
-           only, like for example systemd's own PAM stub process. */
-        if (comm && comm[0] == '(')
+        if (ignore_leftover_process(comm))
                 /* Although we didn't log anything, as this callback is used in unit_kill_context we must return 1
                  * here to let the manager know that a process was killed. */
                 return 1;
 
-        log_unit_notice(userdata,
+        log_unit_notice(u,
                         "Killing process " PID_FMT " (%s) with signal SIG%s.",
                         pid->pid,
                         strna(comm),
@@ -4712,6 +4715,7 @@ static int operation_to_signal(
                 bool *ret_noteworthy) {
 
         assert(c);
+        assert(ret_noteworthy);
 
         switch (k) {
 
@@ -5836,10 +5840,6 @@ int unit_prepare_exec(Unit *u) {
         return 0;
 }
 
-static bool ignore_leftover_process(const char *comm) {
-        return comm && comm[0] == '('; /* Most likely our own helper process (PAM?), ignore */
-}
-
 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;