From f1739c03e00a51e87bd49d04827e5b765d1c70de Mon Sep 17 00:00:00 2001 From: Faidon Liambotis Date: Tue, 15 Sep 2015 01:31:07 +0300 Subject: Lock the screen on systemd sleep under systemd Add a handler for the PrepareForSleep event on the system bus under systemd and lock the screen in such an event. This addresses the issue where "systemctl suspend" suspends the system but the system isn't locked on resume, with the obvious negative security connotations. --- src/gs-listener-dbus.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c index 3a73612..96b3f6a 100644 --- a/src/gs-listener-dbus.c +++ b/src/gs-listener-dbus.c @@ -1654,6 +1654,17 @@ listener_dbus_handle_system_message (DBusConnection *connection, g_signal_emit (listener, signals [LOCK], 0); } + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal (message, SYSTEMD_LOGIND_INTERFACE, "PrepareForSleep")) { + gboolean active; + if (dbus_message_get_args (message, NULL, + DBUS_TYPE_BOOLEAN, &active, + DBUS_TYPE_INVALID) && active) { + gs_debug ("systemd notified that system is about to sleep"); + g_signal_emit (listener, signals [LOCK], 0); + } else { + gs_debug ("cannot parse PrepareForSleep"); + } return DBUS_HANDLER_RESULT_HANDLED; } else if (dbus_message_is_signal (message, DBUS_INTERFACE_PROPERTIES, "PropertiesChanged")) { @@ -2270,6 +2281,12 @@ gs_listener_acquire (GSListener *listener, ",interface='"SYSTEMD_LOGIND_SESSION_INTERFACE"'" ",member='Lock'", NULL); + dbus_bus_add_match (listener->priv->system_connection, + "type='signal'" + ",sender='"SYSTEMD_LOGIND_SERVICE"'" + ",interface='"SYSTEMD_LOGIND_INTERFACE"'" + ",member='PrepareForSleep'", + NULL); dbus_bus_add_match (listener->priv->system_connection, "type='signal'" ",sender='"SYSTEMD_LOGIND_SERVICE"'" -- cgit v1.2.1