]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
logind: add GetSessionByPID() bus call
authorLennart Poettering <lennart@poettering.net>
Wed, 1 Feb 2012 18:04:54 +0000 (19:04 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 1 Feb 2012 18:04:54 +0000 (19:04 +0100)
TODO
src/login/logind-dbus.c
src/login/org.freedesktop.login1.conf

diff --git a/TODO b/TODO
index a30621e757c35b91a1fdf4caeeffd398c699463e..baf4840cdbfd16aa737f3474958f937dd34bc50a 100644 (file)
--- 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
 
index da2eb141c7ad57a7a0509aa90da887b9501a4fa5..fda1b0dba36703087f233439067e9eb89d9738a5 100644 (file)
         "   <arg name=\"id\" type=\"s\" direction=\"in\"/>\n"           \
         "   <arg name=\"session\" type=\"o\" direction=\"out\"/>\n"     \
         "  </method>\n"                                                 \
+        "  <method name=\"GetSessionByPID\">\n"                         \
+        "   <arg name=\"pid\" type=\"u\" direction=\"in\"/>\n"          \
+        "   <arg name=\"session\" type=\"o\" direction=\"out\"/>\n"     \
+        "  </method>\n"                                                 \
         "  <method name=\"GetUser\">\n"                                 \
         "   <arg name=\"uid\" type=\"u\" direction=\"in\"/>\n"          \
         "   <arg name=\"user\" type=\"o\" direction=\"out\"/>\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;
index c423ef5930131c7a04c180799f2f3d9c1eee5d38..17ec605cde22f6ca3db75d14009700f557f18951 100644 (file)
                        send_interface="org.freedesktop.login1.Manager"
                        send_member="GetSession"/>
 
+                <allow send_destination="org.freedesktop.login1"
+                       send_interface="org.freedesktop.login1.Manager"
+                       send_member="GetSessionByPID"/>
+
                 <allow send_destination="org.freedesktop.login1"
                        send_interface="org.freedesktop.login1.Manager"
                        send_member="GetUser"/>