summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Wilck <mwilck@suse.com>2020-01-04 23:54:36 +0100
committerMartin Wilck <mwilck@suse.com>2020-02-14 21:26:25 +0100
commitd117d4a474b1f19f7e184506d42770f82f88364f (patch)
tree74ec799a957872cb15f89517f0b559943b97e89d
parent4e35229b4884e2940d3b3df9a5eb9b1f474e13a4 (diff)
downloadlibproxy-git-d117d4a474b1f19f7e184506d42770f82f88364f.tar.gz
config_pacrunner: add test for pacrunner availability on D-Bus
If the "org.pacrunner" D-Bus name is owned, it's likely that pacrunner is running. Use this as test for the module.
-rw-r--r--libproxy/modules/config_pacrunner.cpp48
1 files changed, 47 insertions, 1 deletions
diff --git a/libproxy/modules/config_pacrunner.cpp b/libproxy/modules/config_pacrunner.cpp
index b4cf723..5e9e772 100644
--- a/libproxy/modules/config_pacrunner.cpp
+++ b/libproxy/modules/config_pacrunner.cpp
@@ -119,4 +119,50 @@ private:
DBusConnection *conn;
};
-MM_MODULE_INIT_EZ(pacrunner_config_extension, true, NULL, NULL);
+#define TEST_TIMEOUT_MS 100
+
+static bool is_pacrunner_available(void)
+{
+ DBusMessage *msg, *reply;
+ DBusConnection* system;
+ dbus_bool_t owned;
+ bool found = false;
+ const char *name = "org.pacrunner";
+
+ msg = dbus_message_new_method_call("org.freedesktop.DBus",
+ "/org/freedesktop/DBus",
+ "org.freedesktop.DBus",
+ "NameHasOwner");
+ if (!msg)
+ return false;
+
+ dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID);
+
+ system = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL);
+ if (!system)
+ goto out_msg;
+
+ reply = dbus_connection_send_with_reply_and_block(system, msg,
+ TEST_TIMEOUT_MS,
+ NULL);
+ if (!reply)
+ goto out_sys;
+
+ if (dbus_message_get_args(reply, NULL, DBUS_TYPE_BOOLEAN, &owned,
+ DBUS_TYPE_INVALID))
+ found = owned;
+
+out_reply:
+ dbus_message_unref(reply);
+out_sys:
+ dbus_connection_close(system);
+ dbus_connection_unref(system);
+out_msg:
+ dbus_message_unref(msg);
+
+ return found;
+}
+
+MM_MODULE_INIT_EZ(pacrunner_config_extension, is_pacrunner_available(),
+ NULL, NULL);