From add10b5ae7636137f530e15efdf7af075d6361eb Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Jun 2011 23:15:57 +0200 Subject: [PATCH] dbus: fix name allocation logic --- src/hostnamed.c | 11 +++++++++-- src/localed.c | 11 +++++++++-- src/timedated.c | 11 +++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/hostnamed.c b/src/hostnamed.c index c6b63cd9..7b2ce691 100644 --- a/src/hostnamed.c +++ b/src/hostnamed.c @@ -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; } diff --git a/src/localed.c b/src/localed.c index 5efee0b2..93e4e9bd 100644 --- a/src/localed.c +++ b/src/localed.c @@ -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; } diff --git a/src/timedated.c b/src/timedated.c index 097e0a00..55cc904f 100644 --- a/src/timedated.c +++ b/src/timedated.c @@ -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; } -- 2.39.5