summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2013-11-05 20:44:27 +0100
committerLennart Poettering <lennart@poettering.net>2013-11-05 20:44:27 +0100
commit4e724d9c5ab76c3f8327945317463ef706011082 (patch)
tree21d2bc54974b381eb3219558fa50e4312ec98b6d
parent2614202b517790d1d11319dce830a9bdcca37f00 (diff)
logind: automatically determine client side PID if GetSessionByPID() is called with a PID == 0
-rw-r--r--src/login/logind-dbus.c20
-rw-r--r--src/machine/machined-dbus.c10
2 files changed, 27 insertions, 3 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);
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index b55266249b..505bc17e6a 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -86,17 +86,25 @@ static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
Machine *machine = 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_machine_by_pid(m, pid, &machine);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);