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.
This commit is contained in:
parent
1c376ca9b1
commit
262ccef84e
1 changed files with 21 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue