X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Flogin%2Flogind-session-dbus.c;h=4995391443fe13ec6cf2b41ca8d95145ec70d74a;hb=718db96199e;hp=cda6a0a4827a3e9023e53b5bbbae7d7a2dcc39bf;hpb=cc3773810855956bad92337cee8fa193584ab62e;p=elogind.git diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index cda6a0a48..499539144 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -25,6 +25,7 @@ #include "util.h" #include "strv.h" #include "bus-util.h" +#include "bus-errors.h" #include "logind.h" #include "logind-session.h" @@ -465,10 +466,9 @@ const sd_bus_vtable session_vtable[] = { }; int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) { - _cleanup_free_ char *e = NULL; Manager *m = userdata; Session *session; - const char *p; + int r; assert(bus); assert(path); @@ -476,17 +476,37 @@ int session_object_find(sd_bus *bus, const char *path, const char *interface, vo assert(found); assert(m); - p = startswith(path, "/org/freedesktop/login1/session/"); - if (!p) - return 0; + if (streq(path, "/org/freedesktop/login1/session/self")) { + sd_bus_message *message; + pid_t pid; - e = bus_path_unescape(p); - if (!e) - return -ENOMEM; + message = sd_bus_get_current(bus); + if (!message) + return 0; - session = hashmap_get(m->sessions, e); - if (!session) - return 0; + r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid); + if (r < 0) + return 0; + + r = manager_get_session_by_pid(m, pid, &session); + if (r <= 0) + return 0; + } else { + _cleanup_free_ char *e = NULL; + const char *p; + + p = startswith(path, "/org/freedesktop/login1/session/"); + if (!p) + return 0; + + e = bus_path_unescape(p); + if (!e) + return -ENOMEM; + + session = hashmap_get(m->sessions, e); + if (!session) + return 0; + } *found = session; return 1; @@ -625,18 +645,27 @@ int session_send_create_reply(Session *s, sd_bus_error *error) { if (error) return sd_bus_reply_method_error(s->manager->bus, c, error); - /* Update the session state file before we notify the client - * about the result. */ - session_save(s); - fifo_fd = session_create_fifo(s); if (fifo_fd < 0) return fifo_fd; + /* Update the session state file before we notify the client + * about the result. */ + session_save(s); + p = session_bus_path(s); if (!p) return -ENOMEM; + log_debug("Sending reply about created session: " + "id=%s object_path=%s runtime_path=%s session_fd=%d seat=%s vtnr=%u", + s->id, + p, + s->user->runtime_path, + fifo_fd, + s->seat ? s->seat->id : "", + (uint32_t) s->vtnr); + return sd_bus_reply_method_return( s->manager->bus, c, "soshsub",