chiark / gitweb /
libsystemd-bus: sd_bus_request_name: fix return value for kdbus
authorDaniel Mack <zonque@gmail.com>
Tue, 26 Nov 2013 16:24:18 +0000 (17:24 +0100)
committerDaniel Mack <zonque@gmail.com>
Fri, 29 Nov 2013 13:06:50 +0000 (14:06 +0100)
kdbus returns -EALREADY if the requesting connection is already the
owner of a name, and -EEXIST if the name already exists and the
connection is not able to take it over.

Also, n->flags needs a translation as well to match the SD_BUS_* enum
values.

src/libsystemd-bus/bus-control.c

index eeeb77b5913f3d093759712d089265aff51991cc..b222175148222db02ec504d2e4d2a1ed91d576fd 100644 (file)
@@ -84,10 +84,20 @@ _public_ int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
 #endif
 
                 r = ioctl(bus->input_fd, KDBUS_CMD_NAME_ACQUIRE, n);
-                if (r < 0)
+                if (r < 0) {
+                        if (errno == -EALREADY)
+                                return SD_BUS_NAME_ALREADY_OWNER;
+
+                        if (errno == -EEXIST)
+                                return SD_BUS_NAME_EXISTS;
+
                         return -errno;
+                }
 
-                return n->flags;
+                if (n->flags & KDBUS_NAME_IN_QUEUE)
+                        return SD_BUS_NAME_IN_QUEUE;
+
+                return SD_BUS_NAME_PRIMARY_OWNER;
         } else {
                 r = sd_bus_call_method(
                                 bus,