summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-12-30 14:33:23 +0100
committerBryce Harrington <bryce@osg.samsung.com>2015-01-16 18:34:10 -0800
commit5dbc79ffaed3e2646aee1a9426072e0f65ec14e3 (patch)
tree76fff35d48bc1cd2bc9fbef31f841a88a53b3a81
parent2ecb84a20dab56b9479186e5a32ae7aa31565756 (diff)
downloadweston-5dbc79ffaed3e2646aee1a9426072e0f65ec14e3.tar.gz
logind: fix PropertiesChanged parser
The current parser directly reads a BOOLEAN on the PropertiesChanged signal for 'Active' properties. However, all property-values are packed in a VARIANT, otherwise, we wouldn't know the type. Fix the parser to recurse into the variant before reading the boolean. To avoid such bugs in the future, we extract the 'Active' parser into a helper function parse_active(), which is then shared between the PropertiesChanged and Get handlers. Signed-off-by: David Herrmann <dh.herrmann@gmail.com> Reviewed-by: Bryce Harrington <bryce@osg.samsung.com> Tested-by: nerdopolis <bluescreen_avenger@verizon.net>
-rw-r--r--src/logind-util.c56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/logind-util.c b/src/logind-util.c
index db23606f..e4e20ebb 100644
--- a/src/logind-util.c
+++ b/src/logind-util.c
@@ -287,33 +287,18 @@ weston_logind_set_active(struct weston_logind *wl, bool active)
}
static void
-get_active_cb(DBusPendingCall *pending, void *data)
+parse_active(struct weston_logind *wl, DBusMessage *m, DBusMessageIter *iter)
{
- struct weston_logind *wl = data;
- DBusMessage *m;
- DBusMessageIter iter, sub;
- int type;
+ DBusMessageIter sub;
dbus_bool_t b;
- dbus_pending_call_unref(wl->pending_active);
- wl->pending_active = NULL;
-
- m = dbus_pending_call_steal_reply(pending);
- if (!m)
+ if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_VARIANT)
return;
- type = dbus_message_get_type(m);
- if (type != DBUS_MESSAGE_TYPE_METHOD_RETURN)
- goto err_unref;
-
- if (!dbus_message_iter_init(m, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
- goto err_unref;
-
- dbus_message_iter_recurse(&iter, &sub);
+ dbus_message_iter_recurse(iter, &sub);
if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_BOOLEAN)
- goto err_unref;
+ return;
dbus_message_iter_get_basic(&sub, &b);
@@ -322,8 +307,28 @@ get_active_cb(DBusPendingCall *pending, void *data)
* other backends, we immediately forward the Active-change event. */
if (!wl->sync_drm || !b)
weston_logind_set_active(wl, b);
+}
+
+static void
+get_active_cb(DBusPendingCall *pending, void *data)
+{
+ struct weston_logind *wl = data;
+ DBusMessageIter iter;
+ DBusMessage *m;
+ int type;
+
+ dbus_pending_call_unref(wl->pending_active);
+ wl->pending_active = NULL;
+
+ m = dbus_pending_call_steal_reply(pending);
+ if (!m)
+ return;
+
+ type = dbus_message_get_type(m);
+ if (type == DBUS_MESSAGE_TYPE_METHOD_RETURN &&
+ dbus_message_iter_init(m, &iter))
+ parse_active(wl, m, &iter);
-err_unref:
dbus_message_unref(m);
}
@@ -408,7 +413,6 @@ property_changed(struct weston_logind *wl, DBusMessage *m)
{
DBusMessageIter iter, sub, entry;
const char *interface, *name;
- dbus_bool_t b;
if (!dbus_message_iter_init(m, &iter) ||
dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
@@ -433,12 +437,8 @@ property_changed(struct weston_logind *wl, DBusMessage *m)
goto error;
if (!strcmp(name, "Active")) {
- if (dbus_message_iter_get_arg_type(&entry) == DBUS_TYPE_BOOLEAN) {
- dbus_message_iter_get_basic(&entry, &b);
- if (!b)
- weston_logind_set_active(wl, false);
- return;
- }
+ parse_active(wl, m, &entry);
+ return;
}
dbus_message_iter_next(&sub);