mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-01 05:47:04 +03:00
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.
This commit is contained in:
parent
e6319a102e
commit
9524c2fd43
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user