From 2260dea7d81591305efb5b807ce6246aebee1027 Mon Sep 17 00:00:00 2001 From: Aaron Dill Date: Mon, 12 Jun 2023 22:48:03 +0000 Subject: [PATCH] logind: call SetType on the logind session This allows manual handling of IdleAction and IdleHint rather than automatically calling the IdleAction every IdleSecs, due to inactivity on the underlying tty. Fixes: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1194 Signed-off-by: aarondill Reviewed-by: Hans de Goede --- hw/xfree86/os-support/linux/systemd-logind.c | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) 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'",