]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: log peer ID when shutdown is called 41229/head
authorMichael Vogt <michael@amutable.com>
Tue, 24 Mar 2026 14:40:40 +0000 (15:40 +0100)
committerMichael Vogt <michael@amutable.com>
Tue, 7 Apr 2026 19:01:21 +0000 (21:01 +0200)
The io.systemd.Manager.{PowerOff,SoftReboot,Halt,Kexec} manager
varlink and bus methods log the peer ID when calling shutdown.

The logind code is missing this, so this commit adds a similar
logging now. The code is quite similar to the one in existing in
src/core/manager.c but its hard to share code so this adds a bit
of duplication.

src/login/logind-dbus.c
src/login/logind-shutdown.c
src/login/logind-shutdown.h
src/login/logind-varlink.c

index ac5da453d64ab02c95150b764e9794fab0aee6e1..98c651896d281c380f88708dbfd4c5b5c7f0574a 100644 (file)
@@ -2310,6 +2310,13 @@ static int method_do_shutdown_or_sleep(
         if (r != 0)
                 return r;
 
+        {
+                _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+
+                (void) bus_query_sender_pidref(message, &pidref);
+                log_shutdown_caller(&pidref, handle_action_to_string(a->handle));
+        }
+
         if (m->delayed_action)
                 return sd_bus_error_setf(error, BUS_ERROR_OPERATION_IN_PROGRESS,
                                          "Action %s already in progress, refusing requested %s operation.",
index d79843a287fcb64a9e47dd2d127523c82fb0d8e7..064ebf8e2ff8fb22fbc2dfe534637a29923b64ce 100644 (file)
@@ -8,8 +8,11 @@
 
 #include "bus-common-errors.h"
 #include "bus-polkit.h"
+#include "cgroup-util.h"
+#include "format-util.h"
 #include "fs-util.h"
 #include "hashmap.h"
+#include "log.h"
 #include "login-util.h"
 #include "logind.h"
 #include "logind-dbus.h"
@@ -17,6 +20,8 @@
 #include "logind-session.h"
 #include "logind-shutdown.h"
 #include "logind-user.h"
+#include "pidref.h"
+#include "process-util.h"
 #include "user-record.h"
 
 int manager_have_multiple_sessions(
@@ -37,6 +42,24 @@ int manager_have_multiple_sessions(
         return false;
 }
 
+void log_shutdown_caller(const PidRef *caller, const char *method) {
+        _cleanup_free_ char *comm = NULL, *unit = NULL;
+
+        assert(method);
+
+        if (!pidref_is_set(caller)) {
+                return log_notice("%s requested from unknown client PID...", method);
+        }
+
+        (void) pidref_get_comm(caller, &comm);
+        (void) cg_pidref_get_unit(caller, &unit);
+
+        log_notice("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...",
+                   method, caller->pid,
+                   comm ? " ('" : "", strempty(comm), comm ? "')" : "",
+                   unit ? " (unit " : "", strempty(unit), unit ? ")" : "");
+}
+
 int manager_verify_shutdown_creds(
                 Manager *m,
                 sd_bus_message *message,
index 38b8b7a9c0841639c1317ebedb1958b031ecadbe..e6bcc8c4f5d4e40865862007d5666e8ace0930cd 100644 (file)
@@ -7,6 +7,8 @@
 
 int manager_have_multiple_sessions(Manager *m, uid_t uid);
 
+void log_shutdown_caller(const PidRef *caller, const char *method);
+
 /* manager_verify_shutdown_creds() takes *either* a "message" or "link" depending on if it is used
  * to validate a D-Bus or Varlink shutdown request. When varlink is used the sd_bus_error *error
  * must be NULL */
index f9ba74c6320838cc865c580cd77d54dd8377fd22..40dee113c4292d7d43aa432340e613bf9c6f8ffb 100644 (file)
@@ -385,6 +385,13 @@ static int manager_do_shutdown_action(sd_varlink *link, sd_json_variant *paramet
         if (r != 0)
                 return r;
 
+        {
+                _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+
+                (void) varlink_get_peer_pidref(link, &pidref);
+                log_shutdown_caller(&pidref, handle_action_to_string(action));
+        }
+
         if (m->delayed_action)
                 return sd_varlink_error(link, "io.systemd.Shutdown.AlreadyInProgress", /* parameters= */ NULL);