[Xfce4-commits] [apps/xfce4-screensaver] 208/425: Fix systemd event handling

noreply at xfce.org noreply at xfce.org
Mon Oct 15 01:50:55 CEST 2018


This is an automated email from the git hooks/post-receive script.

b   l   u   e   s   a   b   r   e       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-screensaver.

commit 306599bdbae51788ed2c2faa061adc6966fd814d
Author: Faidon Liambotis <paravoid at debian.org>
Date:   Tue Sep 15 01:26:01 2015 +0300

    Fix systemd event handling
    
    Right now the systemd event handling is not actually working at all.
    This happens because _listener_message_path_is_our_session() has code to
    check if the event came to our session (e.g. "10") and, under systemd,
    does this by trying to compare it with the object path, by stripping the
    /org/freedesktop/login1/session/ prefix.
    
    However, under -at least recent versions- of systemd, the session ID
    part of the path is escaped separately, and following D-Bus rules
    initial numbers are escaped. In the example above, the obj_path is
    /org/freedesktop/login1/session/_310, so the comparison actually fails.
    
    Port a fix that has been present on various distributions (e.g. Arch)
    and pieces of software (e.g. cinnamon-screensaver) since at least March
    2013.  The original author is Peter de Ridder <peter at xfce.org>.
    
    The bug and the fix can both be easily verified by running "loginctl
    lock-sessions".
---
 src/gs-listener-dbus.c | 56 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 35 insertions(+), 21 deletions(-)

diff --git a/src/gs-listener-dbus.c b/src/gs-listener-dbus.c
index f3dd09c..3a73612 100644
--- a/src/gs-listener-dbus.c
+++ b/src/gs-listener-dbus.c
@@ -1541,21 +1541,10 @@ _listener_message_path_is_our_session (GSListener  *listener,
 		return FALSE;
 
 	if (listener->priv->session_id == NULL)
-	return FALSE;
-
-#ifdef WITH_SYSTEMD
-	/* The bus object path is simply the actual session ID
-	* prefixed to make it a bus path */
-	if (listener->priv->have_systemd)
-		return g_str_has_prefix (ssid, SYSTEMD_LOGIND_SESSION_PATH "/")
-			&& strcmp (ssid + sizeof (SYSTEMD_LOGIND_SESSION_PATH),
-			listener->priv->session_id) == 0;
-#endif
+		return FALSE;
 
-#ifdef WITH_CONSOLE_KIT
 	if (strcmp (ssid, listener->priv->session_id) == 0)
 		return TRUE;
-#endif
 
 	return FALSE;
 }
@@ -2340,20 +2329,45 @@ query_session_id (GSListener *listener)
 
 #ifdef WITH_SYSTEMD
 	if (listener->priv->have_systemd) {
-		char *t;
-		int r;
+		dbus_uint32_t pid = getpid();
 
-		r = sd_pid_get_session (0, &t);
-		if (r < 0) {
-			gs_debug ("Couldn't determine our own session id: %s", strerror (-r));
+		message = dbus_message_new_method_call (SYSTEMD_LOGIND_SERVICE,
+		                                        SYSTEMD_LOGIND_PATH,
+							SYSTEMD_LOGIND_INTERFACE,
+							"GetSessionByPID");
+		if (message == NULL)
+		{
+			gs_debug ("Couldn't allocate the dbus message");
 			return NULL;
 		}
 
-		/* t is allocated with malloc(), we need it with g_malloc() */
-		ssid = g_strdup(t);
-		free (t);
+		if (dbus_message_append_args (message,
+					      DBUS_TYPE_UINT32,
+					      &pid, DBUS_TYPE_INVALID) == FALSE)
+		{
+			gs_debug ("Couldn't add args to the dbus message");
+			return NULL;
+		}
+
+		/* FIXME: use async? */
+		reply = dbus_connection_send_with_reply_and_block (listener->priv->system_connection,
+			message,
+			-1, &error);
+		dbus_message_unref (message);
+
+		if (dbus_error_is_set (&error))
+		{
+			gs_debug ("%s raised:\n %s\n\n", error.name, error.message);
+			dbus_error_free (&error);
+			return NULL;
+		}
+
+		dbus_message_iter_init (reply, &reply_iter);
+		dbus_message_iter_get_basic (&reply_iter, &ssid);
+
+		dbus_message_unref (reply);
 
-		return ssid;
+		return g_strdup (ssid);
 	}
 #endif
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list