chiark / gitweb /
bus: explicitly ignore failure during error handling
[elogind.git] / src / libsystemd / sd-bus / bus-message.c
index 447595764e23c952cbb85854b25b538d47b7e37f..70c38cf487be80bb14b7493c8e1727f8fc6991af 100644 (file)
@@ -27,7 +27,6 @@
 #include "utf8.h"
 #include "strv.h"
 #include "time-util.h"
-#include "cgroup-util.h"
 #include "memfd-util.h"
 
 #include "sd-bus.h"
@@ -413,6 +412,20 @@ static int message_append_field_uint64(sd_bus_message *m, uint64_t h, uint64_t x
         return 0;
 }
 
+static int message_append_reply_cookie(sd_bus_message *m, uint64_t cookie) {
+        assert(m);
+
+        if (BUS_MESSAGE_IS_GVARIANT(m))
+                return message_append_field_uint64(m, BUS_MESSAGE_HEADER_REPLY_SERIAL, cookie);
+        else {
+                /* 64bit cookies are not supported on dbus1 */
+                if (cookie > 0xffffffffUL)
+                        return -EOPNOTSUPP;
+
+                return message_append_field_uint32(m, BUS_MESSAGE_HEADER_REPLY_SERIAL, (uint32_t) cookie);
+        }
+}
+
 int bus_message_from_header(
                 sd_bus *bus,
                 void *header,
@@ -427,7 +440,7 @@ int bus_message_from_header(
                 size_t extra,
                 sd_bus_message **ret) {
 
-        sd_bus_message *m;
+        _cleanup_free_ sd_bus_message *m = NULL;
         struct bus_header *h;
         size_t a, label_sz;
 
@@ -446,15 +459,13 @@ int bus_message_from_header(
                 return -EBADMSG;
 
         h = header;
-        if (h->version != 1 &&
-            h->version != 2)
+        if (!IN_SET(h->version, 1, 2))
                 return -EBADMSG;
 
         if (h->type == _SD_BUS_MESSAGE_TYPE_INVALID)
                 return -EBADMSG;
 
-        if (h->endian != BUS_LITTLE_ENDIAN &&
-            h->endian != BUS_BIG_ENDIAN)
+        if (!IN_SET(h->endian, BUS_LITTLE_ENDIAN, BUS_BIG_ENDIAN))
                 return -EBADMSG;
 
         /* Note that we are happy with unknown flags in the flags header! */
@@ -543,6 +554,7 @@ int bus_message_from_header(
 
         m->bus = sd_bus_ref(bus);
         *ret = m;
+        m = NULL;
 
         return 0;
 }
@@ -620,6 +632,9 @@ static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
         m->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(m);
         m->bus = sd_bus_ref(bus);
 
+        if (bus->allow_interactive_authorization)
+                m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+
         return m;
 }
 
@@ -735,16 +750,9 @@ static int message_new_reply(
         t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
         t->reply_cookie = BUS_MESSAGE_COOKIE(call);
         if (t->reply_cookie == 0)
-                return -ENOTSUP;
-
-        if (BUS_MESSAGE_IS_GVARIANT(t))
-                r = message_append_field_uint64(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, t->reply_cookie);
-        else {
-                if (t->reply_cookie > 0xffffffff)
-                        return -ENOTSUP;
+                return -EOPNOTSUPP;
 
-                r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, (uint32_t) t->reply_cookie);
-        }
+        r = message_append_reply_cookie(t, t->reply_cookie);
         if (r < 0)
                 goto fail;
 
@@ -898,7 +906,7 @@ int bus_message_new_synthetic_error(
         t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
         t->reply_cookie = cookie;
 
-        r = message_append_field_uint32(t, BUS_MESSAGE_HEADER_REPLY_SERIAL, (uint32_t) t->reply_cookie);
+        r = message_append_reply_cookie(t, t->reply_cookie);
         if (r < 0)
                 goto fail;
 
@@ -1455,7 +1463,7 @@ static int message_push_fd(sd_bus_message *m, int fd) {
                 return -EINVAL;
 
         if (!m->allow_fds)
-                return -ENOTSUP;
+                return -EOPNOTSUPP;
 
         copy = fcntl(fd, F_DUPFD_CLOEXEC, 3);
         if (copy < 0)
@@ -2934,7 +2942,7 @@ int bus_message_seal(sd_bus_message *m, uint64_t cookie, usec_t timeout) {
 
         if (cookie > 0xffffffffULL &&
             !BUS_MESSAGE_IS_GVARIANT(m))
-                return -ENOTSUP;
+                return -EOPNOTSUPP;
 
         /* In vtables the return signature of method calls is listed,
          * let's check if they match if this is a response */
@@ -3481,8 +3489,6 @@ _public_ int sd_bus_message_read_basic(sd_bus_message *m, char type, void *p) {
                         return r;
         } else {
 
-                rindex = m->rindex;
-
                 if (IN_SET(type, SD_BUS_TYPE_STRING, SD_BUS_TYPE_OBJECT_PATH)) {
                         uint32_t l;
                         bool ok;
@@ -4790,7 +4796,7 @@ _public_ int sd_bus_message_read_array(
         assert_return(bus_type_is_trivial(type), -EINVAL);
         assert_return(ptr, -EINVAL);
         assert_return(size, -EINVAL);
-        assert_return(!BUS_MESSAGE_NEED_BSWAP(m), -ENOTSUP);
+        assert_return(!BUS_MESSAGE_NEED_BSWAP(m), -EOPNOTSUPP);
 
         r = sd_bus_message_enter_container(m, SD_BUS_TYPE_ARRAY, CHAR_TO_STR(type));
         if (r <= 0)
@@ -5501,7 +5507,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
 
         /* Try to read the error message, but if we can't it's a non-issue */
         if (m->header->type == SD_BUS_MESSAGE_METHOD_ERROR)
-                sd_bus_message_read(m, "s", &m->error.message);
+                (void) sd_bus_message_read(m, "s", &m->error.message);
 
         return 0;
 }
@@ -5818,7 +5824,8 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
                         return -ENOMEM;
 
                 n->reply_cookie = (*m)->reply_cookie;
-                r = message_append_field_uint32(n, BUS_MESSAGE_HEADER_REPLY_SERIAL, (uint32_t) n->reply_cookie);
+
+                r = message_append_reply_cookie(n, n->reply_cookie);
                 if (r < 0)
                         return r;