]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
manager: log unit/pid of sender when Reload() is called
authorLuca Boccassi <bluca@debian.org>
Mon, 12 Dec 2022 15:34:43 +0000 (15:34 +0000)
committerLuca Boccassi <bluca@debian.org>
Tue, 13 Dec 2022 18:13:10 +0000 (18:13 +0000)
Reloading is a heavy-weight operation, and currently it is not
possible to figure out who/what requested it, even at debug level
logging.
Check the sender of the D-Bus message and print it out at info level.

src/core/dbus-manager.c

index 8d7b1f60daf0e2c7d41aedb8344258d5a5d0d2ac..5c8a7d410f97fee36aff1044fc11530f6d280c1a 100644 (file)
@@ -1451,6 +1451,29 @@ int verify_run_space_and_log(const char *message) {
         return 0;
 }
 
+static void log_reload_caller(sd_bus_message *message, Manager *manager) {
+        _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
+        const char *comm = NULL;
+        Unit *caller;
+        pid_t pid;
+
+        assert(message);
+        assert(manager);
+
+        if (sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID|SD_BUS_CREDS_AUGMENT|SD_BUS_CREDS_COMM, &creds) < 0)
+                return;
+
+        /* We need at least the PID, otherwise there's nothing to log, the rest is optional */
+        if (sd_bus_creds_get_pid(creds, &pid) < 0)
+                return;
+
+        (void) sd_bus_creds_get_comm(creds, &comm);
+        caller = manager_get_unit_by_pid(manager, pid);
+
+        log_info("Reloading requested from client PID " PID_FMT " ('%s') (from unit '%s')...",
+                 pid, strna(comm), strna(caller ? caller->id : NULL));
+}
+
 static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *error) {
         Manager *m = ASSERT_PTR(userdata);
         int r;
@@ -1471,6 +1494,9 @@ static int method_reload(sd_bus_message *message, void *userdata, sd_bus_error *
         if (r == 0)
                 return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
 
+        /* Write a log message noting the unit or process who requested the Reload() */
+        log_reload_caller(message, m);
+
         /* Instead of sending the reply back right away, we just
          * remember that we need to and then send it after the reload
          * is finished. That way the caller knows when the reload