dbus: fix name allocation logic
authorLennart Poettering <lennart@poettering.net>
Mon, 27 Jun 2011 21:15:57 +0000 (23:15 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 27 Jun 2011 21:15:57 +0000 (23:15 +0200)
src/hostnamed.c
src/localed.c
src/timedated.c

index c6b63cd..7b2ce69 100644 (file)
@@ -524,8 +524,15 @@ static int connect_bus(DBusConnection **_bus) {
                 goto fail;
         }
 
-        if (dbus_bus_request_name(bus, "org.freedesktop.hostname1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) < 0) {
-                log_error("Failed to register name on bus: %s", error.message);
+        r = dbus_bus_request_name(bus, "org.freedesktop.hostname1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
+        if (dbus_error_is_set(&error)) {
+                log_error("Failed to register name on bus: %s", bus_error_message(&error));
+                r = -EEXIST;
+                goto fail;
+        }
+
+        if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+                log_error("Failed to acquire name.");
                 r = -EEXIST;
                 goto fail;
         }
index 5efee0b..93e4e9b 100644 (file)
@@ -540,8 +540,15 @@ static int connect_bus(DBusConnection **_bus) {
                 goto fail;
         }
 
-        if (dbus_bus_request_name(bus, "org.freedesktop.locale1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) < 0) {
-                log_error("Failed to register name on bus: %s", error.message);
+        r = dbus_bus_request_name(bus, "org.freedesktop.locale1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
+        if (dbus_error_is_set(&error)) {
+                log_error("Failed to register name on bus: %s", bus_error_message(&error));
+                r = -EEXIST;
+                goto fail;
+        }
+
+        if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+                log_error("Failed to acquire name.");
                 r = -EEXIST;
                 goto fail;
         }
index 097e0a0..55cc904 100644 (file)
@@ -543,8 +543,15 @@ static int connect_bus(DBusConnection **_bus) {
                 goto fail;
         }
 
-        if (dbus_bus_request_name(bus, "org.freedesktop.timedate1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error) < 0) {
-                log_error("Failed to register name on bus: %s", error.message);
+        r = dbus_bus_request_name(bus, "org.freedesktop.timedate1", DBUS_NAME_FLAG_DO_NOT_QUEUE, &error);
+        if (dbus_error_is_set(&error)) {
+                log_error("Failed to register name on bus: %s", bus_error_message(&error));
+                r = -EEXIST;
+                goto fail;
+        }
+
+        if (r != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)  {
+                log_error("Failed to acquire name.");
                 r = -EEXIST;
                 goto fail;
         }