chiark / gitweb /
sd-bus: sd_bus_message_get_errno should only return positive errno
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Mon, 15 Sep 2014 20:36:43 +0000 (22:36 +0200)
committerThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Tue, 16 Sep 2014 19:31:15 +0000 (21:31 +0200)
sd_bus_message_get_errno can currently return either a number of
different poitive errno values (from bus-error-mapping), or a negative
EINVAL if passed null as parameter.

The check for null parameter was introduced in 40ca29a1370379d43e44c0ed425eecc7218dcbca
at the same as the function was renamed from bus_message_to_errno and
made public API. Before becoming public the function used to return
only negative values.

It is weird to have a function return both positive and negative errno
and it generally looks like a mistake. The function is guarded by the
--enable-kdbus flags so I wonder if we still have time to fix it up?
It does not have any documentation yet. However, except for a few details
it is just a convenient way to call sd_bus_error_get_errno which is documented
to return only positive errno.

This patch makes it return only positive errno and fixes up the two
calls to the function that tried to cope with both positive and negative
values.

src/libsystemd/sd-bus/bus-message.c
src/libsystemd/sd-bus/sd-bus.c
src/network/networkd-link.c

index bfb14fcce613d409f3fe375381bde3cabb91ac9a..1fa3ad2611f2171e10b1f0319aca0ec9310b8b42 100644 (file)
@@ -5337,7 +5337,7 @@ int bus_header_message_size(struct bus_header *h, size_t *sum) {
 }
 
 _public_ int sd_bus_message_get_errno(sd_bus_message *m) {
 }
 
 _public_ int sd_bus_message_get_errno(sd_bus_message *m) {
-        assert_return(m, -EINVAL);
+        assert_return(m, EINVAL);
 
         if (m->header->type != SD_BUS_MESSAGE_METHOD_ERROR)
                 return 0;
 
         if (m->header->type != SD_BUS_MESSAGE_METHOD_ERROR)
                 return 0;
index 33b65aba72e30acf1881de19849a62b7a727edef..28b993b7ba42b783d43b2df5839d49b1e86084f1 100644 (file)
@@ -349,8 +349,6 @@ static int hello_callback(sd_bus *bus, sd_bus_message *reply, void *userdata, sd
         assert(reply);
 
         r = sd_bus_message_get_errno(reply);
         assert(reply);
 
         r = sd_bus_message_get_errno(reply);
-        if (r < 0)
-                return r;
         if (r > 0)
                 return -r;
 
         if (r > 0)
                 return -r;
 
index 9bf1a811c9f973d3fe654fe3f9307ac4edcb9a4e..427f6953c5f1ccef7597c1704ecb8a1bee9355f0 100644 (file)
@@ -725,8 +725,6 @@ static int set_hostname_handler(sd_bus *bus, sd_bus_message *m, void *userdata,
                 return 1;
 
         r = sd_bus_message_get_errno(m);
                 return 1;
 
         r = sd_bus_message_get_errno(m);
-        if (r < 0)
-                r = -r;
         if (r > 0)
                 log_warning_link(link, "Could not set hostname: %s",
                                  strerror(r));
         if (r > 0)
                 log_warning_link(link, "Could not set hostname: %s",
                                  strerror(r));