aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2017-07-28 13:41:17 -0400
committerTony Crisci <tony@dubstepdish.com>2017-07-29 08:16:14 -0400
commit5eeb067838ff588eb1bc328499ecfe4c3c43b3fb (patch)
treee752ce51350215dd5c43a29af20eb4093a25e246
parentb1ec0dce3a8c5def94e497dd8b16f59a2038c0ed (diff)
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
-rw-r--r--session/logind.c47
1 files 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;
}