]> err.no Git - systemd/commitdiff
dbus: don't try to run AddMatch when connected to a private bus
authorLennart Poettering <lennart@poettering.net>
Wed, 7 Jul 2010 01:43:39 +0000 (03:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Wed, 7 Jul 2010 02:13:19 +0000 (04:13 +0200)
src/dbus-common.c
src/dbus-common.h
src/install.c
src/systemctl.c

index 504eefbbb0b3e00fc6a917dd4de75fd413268839..11d989d7c34de57a7dd8a62b9f41ef205f5804ec 100644 (file)
@@ -54,7 +54,7 @@ int bus_check_peercred(DBusConnection *c) {
         return 1;
 }
 
-int bus_connect(DBusBusType t, DBusConnection **_bus, DBusError *error) {
+int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *error) {
         DBusConnection *bus;
 
         assert(_bus);
@@ -71,9 +71,16 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, DBusError *error) {
                         dbus_set_error_const(error, DBUS_ERROR_ACCESS_DENIED, "Failed to verify owner of bus.");
                         return -EACCES;
                 }
+
+                if (private)
+                        *private = true;
+
         } else {
                 if (!(bus = dbus_bus_get(t, error)))
                         return -EIO;
+
+                if (private)
+                        *private = false;
         }
 
         dbus_connection_set_exit_on_disconnect(bus, FALSE);
index f355de14f80ea8bbec97564b43d136d89ad701a0..b28755fc79769c298148b5228a3eba88ff903ea5 100644 (file)
@@ -26,6 +26,6 @@
 
 int bus_check_peercred(DBusConnection *c);
 
-int bus_connect(DBusBusType t, DBusConnection **_bus, DBusError *error);
+int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
 
 #endif
index 3bf5761b3d93b5dcefb5239fbce7f402dcc74a55..3b70bd1d3db2354dfd2d0ee04cd782074dc3cc82 100644 (file)
@@ -791,7 +791,7 @@ static int do_run(void) {
                 return 0;
         }
 
-        if ((r = bus_connect(arg_where == WHERE_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &error)) < 0) {
+        if ((r = bus_connect(arg_where == WHERE_SESSION ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, NULL, &error)) < 0) {
                 log_error("Failed to get D-Bus connection: %s", error.message);
                 goto finish;
         }
index 5c91c325cd2d5ae8b5012248dbb163f35ad7f117..081f34bcfd17b493f0c8893b15f98dc1d72a4d02 100644 (file)
@@ -75,6 +75,8 @@ enum action {
         _ACTION_MAX
 } arg_action = ACTION_SYSTEMCTL;
 
+static bool private_bus = false;
+
 static bool error_is_no_service(DBusError *error) {
 
         assert(error);
@@ -561,6 +563,9 @@ static int enable_wait_for_jobs(DBusConnection *bus) {
 
         assert(bus);
 
+        if (private_bus)
+                return 0;
+
         dbus_error_init(&error);
         dbus_bus_add_match(bus,
                            "type='signal',"
@@ -1849,43 +1854,45 @@ static int monitor(DBusConnection *bus, char **args, unsigned n) {
 
         dbus_error_init(&error);
 
-        dbus_bus_add_match(bus,
-                           "type='signal',"
-                           "sender='org.freedesktop.systemd1',"
-                           "interface='org.freedesktop.systemd1.Manager',"
-                           "path='/org/freedesktop/systemd1'",
-                           &error);
+        if (!private_bus) {
+                dbus_bus_add_match(bus,
+                                   "type='signal',"
+                                   "sender='org.freedesktop.systemd1',"
+                                   "interface='org.freedesktop.systemd1.Manager',"
+                                   "path='/org/freedesktop/systemd1'",
+                                   &error);
 
-        if (dbus_error_is_set(&error)) {
-                log_error("Failed to add match: %s", error.message);
-                r = -EIO;
-                goto finish;
-        }
+                if (dbus_error_is_set(&error)) {
+                        log_error("Failed to add match: %s", error.message);
+                        r = -EIO;
+                        goto finish;
+                }
 
-        dbus_bus_add_match(bus,
-                           "type='signal',"
-                           "sender='org.freedesktop.systemd1',"
-                           "interface='org.freedesktop.systemd1.Unit',"
-                           "member='Changed'",
-                           &error);
+                dbus_bus_add_match(bus,
+                                   "type='signal',"
+                                   "sender='org.freedesktop.systemd1',"
+                                   "interface='org.freedesktop.systemd1.Unit',"
+                                   "member='Changed'",
+                                   &error);
 
-        if (dbus_error_is_set(&error)) {
-                log_error("Failed to add match: %s", error.message);
-                r = -EIO;
-                goto finish;
-        }
+                if (dbus_error_is_set(&error)) {
+                        log_error("Failed to add match: %s", error.message);
+                        r = -EIO;
+                        goto finish;
+                }
 
-        dbus_bus_add_match(bus,
-                           "type='signal',"
-                           "sender='org.freedesktop.systemd1',"
-                           "interface='org.freedesktop.systemd1.Job',"
-                           "member='Changed'",
-                           &error);
+                dbus_bus_add_match(bus,
+                                   "type='signal',"
+                                   "sender='org.freedesktop.systemd1',"
+                                   "interface='org.freedesktop.systemd1.Job',"
+                                   "member='Changed'",
+                                   &error);
 
-        if (dbus_error_is_set(&error)) {
-                log_error("Failed to add match: %s", error.message);
-                r = -EIO;
-                goto finish;
+                if (dbus_error_is_set(&error)) {
+                        log_error("Failed to add match: %s", error.message);
+                        r = -EIO;
+                        goto finish;
+                }
         }
 
         if (!dbus_connection_add_filter(bus, monitor_filter, NULL, NULL)) {
@@ -3286,7 +3293,7 @@ int main(int argc, char*argv[]) {
                 goto finish;
         }
 
-        bus_connect(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &error);
+        bus_connect(arg_session ? DBUS_BUS_SESSION : DBUS_BUS_SYSTEM, &bus, &private_bus, &error);
 
         switch (arg_action) {