diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c index d97e92ff8..16a9df675 100644 --- a/hw/xfree86/os-support/linux/systemd-logind.c +++ b/hw/xfree86/os-support/linux/systemd-logind.c @@ -444,6 +444,7 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data) static void connect_hook(DBusConnection *connection, void *data) { + const char *session_type = "x11"; struct systemd_logind_info *info = data; DBusError error; DBusMessage *msg = NULL; @@ -510,6 +511,33 @@ connect_hook(DBusConnection *connection, void *data) error.message); goto cleanup; } + dbus_message_unref(msg); + dbus_message_unref(reply); + reply = NULL; + + msg = dbus_message_new_method_call("org.freedesktop.login1", + session, "org.freedesktop.login1.Session", "SetType"); + if (!msg) { + LogMessage(X_ERROR, "systemd-logind: out of memory\n"); + goto cleanup; + } + + if (!dbus_message_append_args(msg, DBUS_TYPE_STRING, &session_type, + DBUS_TYPE_INVALID)) { + LogMessage(X_ERROR, "systemd-logind: out of memory\n"); + goto cleanup; + } + + reply = dbus_connection_send_with_reply_and_block(connection, msg, + DBUS_TIMEOUT_USE_DEFAULT, &error); + /* Requires systemd >= 246, SetType() is not critical for xserver function */ + if (!reply) { + /* unprevileged users get access denied rather than unknown method */ + if (!dbus_error_has_name(&error, DBUS_ERROR_ACCESS_DENIED) && + !dbus_error_has_name(&error, DBUS_ERROR_UNKNOWN_METHOD)) + LogMessage(X_WARNING, "systemd-logind: SetType failed: %s\n", error.message); + dbus_error_free(&error); + } dbus_bus_add_match(connection, "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.login1.Session',member='PauseDevice'",