From c4aa65e7147dc742886edf25593e10466b02fc3a Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 1 Feb 2012 19:04:54 +0100 Subject: [PATCH] logind: add GetSessionByPID() bus call --- TODO | 2 +- src/login/logind-dbus.c | 38 +++++++++++++++++++++++++++ src/login/org.freedesktop.login1.conf | 4 +++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index a30621e7..baf4840c 100644 --- a/TODO +++ b/TODO @@ -23,7 +23,7 @@ Features: * journald: reuse XZ context -* logind: add equivalent to sd_pid_get_session() to the D-Bus API +* logind: add equivalent to sd_pid_get_owner_uid() to the D-Bus API * Fedora: disable journald's /proc/kmsg reading on Fedora for now diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c index da2eb141..fda1b0db 100644 --- a/src/login/logind-dbus.c +++ b/src/login/logind-dbus.c @@ -36,6 +36,10 @@ " \n" \ " \n" \ " \n" \ + " \n" \ + " \n" \ + " \n" \ + " \n" \ " \n" \ " \n" \ " \n" \ @@ -771,6 +775,40 @@ static DBusHandlerResult manager_message_handler( if (!b) goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetSessionByPID")) { + uint32_t pid; + char *p; + Session *session; + bool b; + + if (!dbus_message_get_args( + message, + &error, + DBUS_TYPE_UINT32, &pid, + DBUS_TYPE_INVALID)) + return bus_send_error_reply(connection, message, &error, -EINVAL); + + r = manager_get_session_by_pid(m, pid, &session); + if (r <= 0) + return bus_send_error_reply(connection, message, NULL, r < 0 ? r : -ENOENT); + + reply = dbus_message_new_method_return(message); + if (!reply) + goto oom; + + p = session_bus_path(session); + if (!p) + goto oom; + + b = dbus_message_append_args( + reply, + DBUS_TYPE_OBJECT_PATH, &p, + DBUS_TYPE_INVALID); + free(p); + + if (!b) + goto oom; + } else if (dbus_message_is_method_call(message, "org.freedesktop.login1.Manager", "GetUser")) { uint32_t uid; char *p; diff --git a/src/login/org.freedesktop.login1.conf b/src/login/org.freedesktop.login1.conf index c423ef59..17ec605c 100644 --- a/src/login/org.freedesktop.login1.conf +++ b/src/login/org.freedesktop.login1.conf @@ -40,6 +40,10 @@ send_interface="org.freedesktop.login1.Manager" send_member="GetSession"/> + + -- 2.39.5