From: Luca Boccassi Date: Mon, 12 Dec 2022 15:34:43 +0000 (+0000) Subject: manager: log unit/pid of sender when Reload() is called X-Git-Tag: v253-rc1~292^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9524c2fd43aa3b76719cc21eb7093a5b90997fd9;p=thirdparty%2Fsystemd.git manager: log unit/pid of sender when Reload() is called 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. --- diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 8d7b1f60daf..5c8a7d410f9 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -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