diff options
author | Lennart Poettering <lennart@poettering.net> | 2013-11-05 20:44:27 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2013-11-05 20:44:27 +0100 |
commit | 4e724d9c5ab76c3f8327945317463ef706011082 (patch) | |
tree | 21d2bc54974b381eb3219558fa50e4312ec98b6d /src/login | |
parent | 2614202b517790d1d11319dce830a9bdcca37f00 (diff) |
logind: automatically determine client side PID if GetSessionByPID() is called with a PID == 0
Diffstat (limited to 'src/login')
-rw-r--r-- | src/login/logind-dbus.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index dcfd25d69b..7e22b842a4 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -157,17 +157,25 @@ static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void _cleanup_free_ char *p = NULL; Session *session = NULL; Manager *m = userdata; - uint32_t pid; + pid_t pid; int r; assert(bus); assert(message); assert(m); + assert_cc(sizeof(pid_t) == sizeof(uint32_t)); + r = sd_bus_message_read(message, "u", &pid); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); + if (pid == 0) { + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return sd_bus_reply_method_errno(bus, message, r, NULL); + } + r = manager_get_session_by_pid(m, pid, &session); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); @@ -211,17 +219,25 @@ static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *us _cleanup_free_ char *p = NULL; Manager *m = userdata; User *user = NULL; - uint32_t pid; + pid_t pid; int r; assert(bus); assert(message); assert(m); + assert_cc(sizeof(pid_t) == sizeof(uint32_t)); + r = sd_bus_message_read(message, "u", &pid); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); + if (pid == 0) { + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return sd_bus_reply_method_errno(bus, message, r, NULL); + } + r = manager_get_user_by_pid(m, pid, &user); if (r < 0) return sd_bus_reply_method_errno(bus, message, r, NULL); |