From 5eeb067838ff588eb1bc328499ecfe4c3c43b3fb Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Fri, 28 Jul 2017 13:41:17 -0400 Subject: [PATCH] Correctly get session path The old way of getting the session path was to simply append the session id to the path "/org/freedesktop/login1/session/". However this is not the correct path for newer systems like Fedora 26. Instead, get the session path directly from the session manager from the id via a dbus call to GetSession(). fixes #35 --- session/logind.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/session/logind.c b/session/logind.c index cfbdb4c7..6744215a 100644 --- a/session/logind.c +++ b/session/logind.c @@ -124,6 +124,36 @@ static bool logind_change_vt(struct wlr_session *base, unsigned vt) { return ret >= 0; } +static bool find_sesion_path(struct logind_session *session) { + int ret; + sd_bus_message *msg = NULL; + sd_bus_error error = SD_BUS_ERROR_NULL; + + ret = sd_bus_call_method(session->bus, "org.freedesktop.login1", + "/org/freedesktop/login1", "org.freedesktop.login1.Manager", + "GetSession", &error, &msg, "s", session->id); + if (ret < 0) { + wlr_log(L_ERROR, "Failed to get session path: %s", strerror(-ret)); + goto out; + } + + const char *path; + + ret = sd_bus_message_read(msg, "o", &path); + if (ret < 0) { + wlr_log(L_ERROR, "Could not parse session path: %s", strerror(-ret)); + goto out; + } + + session->path = strdup(path); + +out: + sd_bus_error_free(&error); + sd_bus_message_unref(msg); + + return ret >= 0; +} + static bool session_activate(struct logind_session *session) { int ret; sd_bus_message *msg = NULL; @@ -315,22 +345,17 @@ static struct wlr_session *logind_session_start(struct wl_display *disp) { snprintf(session->base.seat, sizeof(session->base.seat), "%s", seat); free(seat); - const char *fmt = "/org/freedesktop/login1/session/%s"; - int len = snprintf(NULL, 0, fmt, session->id); - - session->path = malloc(len + 1); - if (!session->path) { - goto error; - } - - sprintf(session->path, fmt, session->id); - ret = sd_bus_default_system(&session->bus); if (ret < 0) { wlr_log(L_ERROR, "Failed to open D-Bus connection: %s", strerror(-ret)); goto error; } + if (!find_sesion_path(session)) { + sd_bus_unref(session->bus); + goto error; + } + if (!add_signal_matches(session)) { goto error_bus; } @@ -357,9 +382,9 @@ static struct wlr_session *logind_session_start(struct wl_display *disp) { error_bus: sd_bus_unref(session->bus); + free(session->path); error: - free(session->path); free(session->id); return NULL; }