diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-07-02 17:54:11 +0200 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-07-03 10:11:21 +0200 |
commit | ff21827fee34a5c1db9fe7ca26b0cd94be9cb595 (patch) | |
tree | 0881babf8ab99552d37af989d42862b118db2341 /src/core/dbus-manager.c | |
parent | mkosi: Don't touch the packaging checkout if work is being done (diff) | |
download | systemd-ff21827fee34a5c1db9fe7ca26b0cd94be9cb595.tar.xz systemd-ff21827fee34a5c1db9fe7ca26b0cd94be9cb595.zip |
core/dbus-manager: use PidRef for log_caller()
This is only for logging, but since we lookup for the unit
here, let's try to be accurate.
Diffstat (limited to 'src/core/dbus-manager.c')
-rw-r--r-- | src/core/dbus-manager.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index 6001dccd6e..207dbac52a 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1553,26 +1553,27 @@ static int verify_run_space_permissive(const char *message, sd_bus_error *error) static void log_caller(sd_bus_message *message, Manager *manager, const char *method) { _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL; - const char *comm = NULL; - Unit *caller; - pid_t pid; + _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL; assert(message); assert(manager); assert(method); - if (sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID|SD_BUS_CREDS_AUGMENT|SD_BUS_CREDS_COMM, &creds) < 0) + if (sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID|SD_BUS_CREDS_PIDFD|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) + /* We need at least the PID, otherwise there's nothing to log, the rest is optional. */ + if (bus_creds_get_pidref(creds, &pidref) < 0) return; + const char *comm = NULL; + Unit *caller; + (void) sd_bus_creds_get_comm(creds, &comm); - caller = manager_get_unit_by_pid(manager, pid); + caller = manager_get_unit_by_pidref(manager, &pidref); log_info("%s requested from client PID " PID_FMT "%s%s%s%s%s%s...", - method, pid, + method, pidref.pid, comm ? " ('" : "", strempty(comm), comm ? "')" : "", caller ? " (unit " : "", caller ? caller->id : "", caller ? ")" : ""); } |