[vdagent-linux v1 6/8] console-kit: include signal handler function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At the moment we are only reading the ActiveSessionChanged signal from
ConsoleKit.Seat but in a later patch we will be reading a few more signals so it
make sense to move this handler to its own function.
---
 src/console-kit.c | 100 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 51 insertions(+), 49 deletions(-)

diff --git a/src/console-kit.c b/src/console-kit.c
index 04437af..0940cf5 100644
--- a/src/console-kit.c
+++ b/src/console-kit.c
@@ -43,9 +43,59 @@ struct session_info {
 
 #define INTERFACE_CK_SEAT       INTERFACE_CONSOLE_KIT ".Seat"
 
+#define CK_SEAT_SIGNAL_ACTIVE_SESSION_CHANGED       "ActiveSessionChanged"
+
 static char *console_kit_get_first_seat(struct session_info *si);
 static char *console_kit_check_active_session_change(struct session_info *si);
 
+static void
+si_dbus_read_signals(struct session_info *si)
+{
+    DBusMessage *message = NULL;
+
+    dbus_connection_read_write(si->connection, 0);
+    message = dbus_connection_pop_message(si->connection);
+    while (message != NULL) {
+        const char *member;
+
+        if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_SIGNAL) {
+            syslog(LOG_WARNING, "(console-kit) received non signal message");
+            dbus_message_unref(message);
+            break;
+        }
+
+        member = dbus_message_get_member (message);
+        if (g_strcmp0(member, CK_SEAT_SIGNAL_ACTIVE_SESSION_CHANGED) == 0) {
+            DBusMessageIter iter;
+            gint type;
+            gchar *session;
+
+            free(si->active_session);
+            si->active_session = NULL;
+
+            dbus_message_iter_init(message, &iter);
+            type = dbus_message_iter_get_arg_type(&iter);
+            if (type == DBUS_TYPE_STRING || type == DBUS_TYPE_OBJECT_PATH) {
+                dbus_message_iter_get_basic(&iter, &session);
+                si->active_session = g_strdup(session);
+            } else {
+                /* Session should be an object path, but there is a bug in
+                   ConsoleKit where it sends a string rather then an object_path
+                   accept object_path too in case the bug ever gets fixed */
+                syslog(LOG_ERR,
+                       "ActiveSessionChanged message has unexpected type: '%c'",
+                       type);
+            }
+        } else if (si->verbose) {
+            syslog(LOG_DEBUG, "(console-kit) Signal not handled: %s", member);
+        }
+
+        dbus_message_unref(message);
+        dbus_connection_read_write(si->connection, 0);
+        message = dbus_connection_pop_message(si->connection);
+    }
+}
+
 struct session_info *session_info_create(int verbose)
 {
     struct session_info *si;
@@ -316,55 +366,7 @@ exit:
 
 static char *console_kit_check_active_session_change(struct session_info *si)
 {
-    DBusMessage *message = NULL;
-    DBusMessageIter iter;
-    char *session;
-    int type;
-
-    /* non blocking read of the next available message */
-    dbus_connection_read_write(si->connection, 0);
-    while ((message = dbus_connection_pop_message(si->connection))) {
-        if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_SIGNAL) {
-            const char *member = dbus_message_get_member (message);
-            if (!strcmp(member, "NameAcquired")) {
-                dbus_message_unref(message);
-                continue;
-            }
-            if (strcmp(member, "ActiveSessionChanged")) {
-                syslog(LOG_ERR, "unexpected signal member: %s", member);
-                dbus_message_unref(message);
-                continue;
-            }
-        } else {
-            syslog(LOG_ERR, "received non signal message!");
-            dbus_message_unref(message);
-            continue;
-        }
-
-        free(si->active_session);
-        si->active_session = NULL;
-
-        dbus_message_iter_init(message, &iter);
-        type = dbus_message_iter_get_arg_type(&iter);
-        /* Session should be an object path, but there is a bug in
-           ConsoleKit where it sends a string rather then an object_path
-           accept object_path too in case the bug ever gets fixed */
-        if (type != DBUS_TYPE_STRING && type != DBUS_TYPE_OBJECT_PATH) {
-            syslog(LOG_ERR,
-                   "ActiveSessionChanged message has unexpected type: '%c'",
-                   type);
-            dbus_message_unref(message);
-            continue;
-        }
-
-        dbus_message_iter_get_basic(&iter, &session);
-        si->active_session = strdup(session);
-        dbus_message_unref(message);
-
-        /* non blocking read of the next available message */
-        dbus_connection_read_write(si->connection, 0);
-    }
-
+    si_dbus_read_signals(si);
     if (si->verbose)
         syslog(LOG_DEBUG, "(console-kit) active-session: %s", si->active_session);
     return si->active_session;
-- 
2.5.5

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]