diff options
author | Simon Ser <contact@emersion.fr> | 2021-09-22 09:40:02 +0000 |
---|---|---|
committer | Kenny Levinsen <kl@kl.wtf> | 2021-09-22 21:55:49 +0200 |
commit | 262ccef84eddf3714183b80729a157504615468e (patch) | |
tree | 909b13ee0d405f268313d79fbb1b2778a3594c0b /libseat/backend | |
parent | 1c376ca9b13458b1e4ad0da20c8d35729fa09d4b (diff) |
logind: check if session is active on startup
Up until now we assumed the session was always active on startup.
This might not be the case. Instead, read the current value of the
Active property.
Diffstat (limited to 'libseat/backend')
-rw-r--r-- | libseat/backend/logind.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/libseat/backend/logind.c b/libseat/backend/logind.c index dd050ce..ceafc6c 100644 --- a/libseat/backend/logind.c +++ b/libseat/backend/logind.c @@ -303,6 +303,7 @@ static bool session_activate(struct backend_logind *session) { sd_bus_message *msg = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; + // Note: the Activate call might not make the session active immediately int ret = sd_bus_call_method(session->bus, "org.freedesktop.login1", session->path, "org.freedesktop.login1.Session", "Activate", &error, &msg, ""); if (ret < 0) { @@ -314,6 +315,22 @@ static bool session_activate(struct backend_logind *session) { return ret >= 0; } +static bool session_check_active(struct backend_logind *session) { + sd_bus_error error = SD_BUS_ERROR_NULL; + int active = 0; + int ret = sd_bus_get_property_trivial(session->bus, "org.freedesktop.login1", session->path, + "org.freedesktop.login1.Session", "Active", &error, + 'b', &active); + if (ret < 0) { + log_errorf("Could not check if session is active: %s", error.message); + } else { + session->active = (bool)active; + } + + sd_bus_error_free(&error); + return ret >= 0; +} + static bool take_control(struct backend_logind *session) { sd_bus_message *msg = NULL; sd_bus_error error = SD_BUS_ERROR_NULL; @@ -699,6 +716,10 @@ static struct libseat *logind_open_seat(const struct libseat_seat_listener *list goto error; } + if (!session_check_active(backend)) { + goto error; + } + if (!take_control(backend)) { goto error; } @@ -709,7 +730,6 @@ static struct libseat *logind_open_seat(const struct libseat_seat_listener *list } backend->initial_setup = true; - backend->active = true; backend->seat_listener = listener; backend->seat_listener_data = data; backend->base.impl = &logind_impl; |