chiark / gitweb /
tree-wide: remove Lennart's copyright lines
[elogind.git] / src / libelogind / sd-bus / bus-message.c
index b7948a6ca810bf31ed7d69d6f7cc78a437d691cf..2958648ec11e2f1e7e95a7cb9810475fa304db22 100644 (file)
@@ -1,41 +1,28 @@
-/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-
+/* SPDX-License-Identifier: LGPL-2.1+ */
 /***
-  This file is part of systemd.
-
-  Copyright 2013 Lennart Poettering
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <errno.h>
 #include <fcntl.h>
 #include <sys/mman.h>
 
-#include "util.h"
-#include "utf8.h"
-#include "strv.h"
-#include "time-util.h"
-#include "memfd-util.h"
-
 #include "sd-bus.h"
-#include "bus-message.h"
+
+#include "alloc-util.h"
+#include "bus-gvariant.h"
 #include "bus-internal.h"
-#include "bus-type.h"
+#include "bus-message.h"
 #include "bus-signature.h"
-#include "bus-gvariant.h"
+#include "bus-type.h"
 #include "bus-util.h"
+#include "fd-util.h"
+#include "io-util.h"
+#include "memfd-util.h"
+#include "string-util.h"
+#include "strv.h"
+#include "time-util.h"
+#include "utf8.h"
+#include "util.h"
 
 static int message_append_basic(sd_bus_message *m, char type, const void *p, const void **stored);
 
@@ -60,22 +47,9 @@ static void message_free_part(sd_bus_message *m, struct bus_body_part *part) {
         assert(m);
         assert(part);
 
-        if (part->memfd >= 0) {
-                /* If we can reuse the memfd, try that. For that it
-                 * can't be sealed yet. */
-
-                if (!part->sealed) {
-                        assert(part->memfd_offset == 0);
-                        assert(part->data == part->mmap_begin);
-                        bus_kernel_push_memfd(m->bus, part->memfd, part->data, part->mapped, part->allocated);
-                } else {
-                        if (part->mapped > 0)
-                                assert_se(munmap(part->mmap_begin, part->mapped) == 0);
-
-                        safe_close(part->memfd);
-                }
-
-        } else if (part->munmap_this)
+        if (part->memfd >= 0)
+                close_and_munmap(part->memfd, part->mmap_begin, part->mapped);
+        else if (part->munmap_this)
                 munmap(part->mmap_begin, part->mapped);
         else if (part->free_this)
                 free(part->data);
@@ -113,14 +87,13 @@ static void message_reset_containers(sd_bus_message *m) {
                 free(m->containers[i].offsets);
         }
 
-        free(m->containers);
-        m->containers = NULL;
+        m->containers = mfree(m->containers);
 
         m->n_containers = m->containers_allocated = 0;
         m->root_container.index = 0;
 }
 
-static void message_free(sd_bus_message *m) {
+static sd_bus_message* message_free(sd_bus_message *m) {
         assert(m);
 
         if (m->free_header)
@@ -128,12 +101,6 @@ static void message_free(sd_bus_message *m) {
 
         message_reset_parts(m);
 
-        if (m->release_kdbus)
-                bus_kernel_cmd_free(m->bus, (uint8_t *) m->kdbus - (uint8_t *) m->bus->kdbus_buffer);
-
-        if (m->free_kdbus)
-                free(m->kdbus);
-
         sd_bus_unref(m->bus);
 
         if (m->free_fds) {
@@ -144,11 +111,6 @@ static void message_free(sd_bus_message *m) {
         if (m->iovec != m->iovec_fixed)
                 free(m->iovec);
 
-        if (m->destination_ptr) {
-                free(m->destination_ptr);
-                m->destination_ptr = NULL;
-        }
-
         message_reset_containers(m);
         free(m->root_container.signature);
         free(m->root_container.offsets);
@@ -156,9 +118,11 @@ static void message_free(sd_bus_message *m) {
         free(m->root_container.peeked_signature);
 
         bus_creds_done(&m->creds);
-        free(m);
+        return mfree(m);
 }
 
+DEFINE_TRIVIAL_CLEANUP_FUNC(sd_bus_message*, message_free);
+
 static void *message_extend_fields(sd_bus_message *m, size_t align, size_t sz, bool add_offset) {
         void *op, *np;
         size_t old_size, new_size, start;
@@ -184,7 +148,7 @@ static void *message_extend_fields(sd_bus_message *m, size_t align, size_t sz, b
                 if (!np)
                         goto poison;
         } else {
-                /* Initially, the header is allocated as part of of
+                /* Initially, the header is allocated as part of
                  * the sd_bus_message itself, let's replace it by
                  * dynamic data */
 
@@ -434,7 +398,7 @@ int bus_message_from_header(
                 size_t footer_accessible,
                 size_t message_size,
                 int *fds,
-                unsigned n_fds,
+                size_t n_fds,
                 const char *label,
                 size_t extra,
                 sd_bus_message **ret) {
@@ -535,8 +499,7 @@ int bus_message_from_header(
         }
 
         m->bus = sd_bus_ref(bus);
-        *ret = m;
-        m = NULL;
+        *ret = TAKE_PTR(m);
 
         return 0;
 }
@@ -546,11 +509,11 @@ int bus_message_from_malloc(
                 void *buffer,
                 size_t length,
                 int *fds,
-                unsigned n_fds,
+                size_t n_fds,
                 const char *label,
                 sd_bus_message **ret) {
 
-        sd_bus_message *m;
+        _cleanup_(message_freep) sd_bus_message *m = NULL;
         size_t sz;
         int r;
 
@@ -581,42 +544,46 @@ int bus_message_from_malloc(
 
         r = bus_message_parse_fields(m);
         if (r < 0)
-                goto fail;
+                return r;
 
         /* We take possession of the memory and fds now */
         m->free_header = true;
         m->free_fds = true;
 
-        *ret = m;
+        *ret = TAKE_PTR(m);
         return 0;
-
-fail:
-        message_free(m);
-        return r;
 }
 
-static sd_bus_message *message_new(sd_bus *bus, uint8_t type) {
-        sd_bus_message *m;
+_public_ int sd_bus_message_new(
+                sd_bus *bus,
+                sd_bus_message **m,
+                uint8_t type) {
 
-        assert(bus);
+        sd_bus_message *t;
 
-        m = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(struct bus_header));
-        if (!m)
-                return NULL;
+        assert_return(bus, -ENOTCONN);
+        assert_return(bus->state != BUS_UNSET, -ENOTCONN);
+        assert_return(m, -EINVAL);
+        assert_return(type < _SD_BUS_MESSAGE_TYPE_MAX, -EINVAL);
 
-        m->n_ref = 1;
-        m->header = (struct bus_header*) ((uint8_t*) m + ALIGN(sizeof(struct sd_bus_message)));
-        m->header->endian = BUS_NATIVE_ENDIAN;
-        m->header->type = type;
-        m->header->version = bus ? bus->message_version : 1;
-        m->allow_fds = !bus || bus->can_fds || (bus->state != BUS_HELLO && bus->state != BUS_RUNNING);
-        m->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(m);
-        m->bus = sd_bus_ref(bus);
+        t = malloc0(ALIGN(sizeof(sd_bus_message)) + sizeof(struct bus_header));
+        if (!t)
+                return -ENOMEM;
+
+        t->n_ref = 1;
+        t->header = (struct bus_header*) ((uint8_t*) t + ALIGN(sizeof(struct sd_bus_message)));
+        t->header->endian = BUS_NATIVE_ENDIAN;
+        t->header->type = type;
+        t->header->version = bus->message_version;
+        t->allow_fds = bus->can_fds || !IN_SET(bus->state, BUS_HELLO, BUS_RUNNING);
+        t->root_container.need_offsets = BUS_MESSAGE_IS_GVARIANT(t);
+        t->bus = sd_bus_ref(bus);
 
         if (bus->allow_interactive_authorization)
-                m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+                t->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
 
-        return m;
+        *m = t;
+        return 0;
 }
 
 _public_ int sd_bus_message_new_signal(
@@ -626,7 +593,7 @@ _public_ int sd_bus_message_new_signal(
                 const char *interface,
                 const char *member) {
 
-        sd_bus_message *t;
+        _cleanup_(sd_bus_message_unrefp) sd_bus_message *t = NULL;
         int r;
 
         assert_return(bus, -ENOTCONN);
@@ -636,28 +603,26 @@ _public_ int sd_bus_message_new_signal(
         assert_return(member_name_is_valid(member), -EINVAL);
         assert_return(m, -EINVAL);
 
-        t = message_new(bus, SD_BUS_MESSAGE_SIGNAL);
-        if (!t)
+        r = sd_bus_message_new(bus, &t, SD_BUS_MESSAGE_SIGNAL);
+        if (r < 0)
                 return -ENOMEM;
 
+        assert(t);
+
         t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
 
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_PATH, SD_BUS_TYPE_OBJECT_PATH, path, &t->path);
         if (r < 0)
-                goto fail;
+                return r;
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_INTERFACE, SD_BUS_TYPE_STRING, interface, &t->interface);
         if (r < 0)
-                goto fail;
+                return r;
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_MEMBER, SD_BUS_TYPE_STRING, member, &t->member);
         if (r < 0)
-                goto fail;
+                return r;
 
-        *m = t;
+        *m = TAKE_PTR(t);
         return 0;
-
-fail:
-        sd_bus_message_unref(t);
-        return r;
 }
 
 _public_ int sd_bus_message_new_method_call(
@@ -668,7 +633,7 @@ _public_ int sd_bus_message_new_method_call(
                 const char *interface,
                 const char *member) {
 
-        sd_bus_message *t;
+        _cleanup_(message_freep) sd_bus_message *t = NULL;
         int r;
 
         assert_return(bus, -ENOTCONN);
@@ -679,35 +644,33 @@ _public_ int sd_bus_message_new_method_call(
         assert_return(member_name_is_valid(member), -EINVAL);
         assert_return(m, -EINVAL);
 
-        t = message_new(bus, SD_BUS_MESSAGE_METHOD_CALL);
-        if (!t)
+        r = sd_bus_message_new(bus, &t, SD_BUS_MESSAGE_METHOD_CALL);
+        if (r < 0)
                 return -ENOMEM;
 
+        assert(t);
+
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_PATH, SD_BUS_TYPE_OBJECT_PATH, path, &t->path);
         if (r < 0)
-                goto fail;
+                return r;
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_MEMBER, SD_BUS_TYPE_STRING, member, &t->member);
         if (r < 0)
-                goto fail;
+                return r;
 
         if (interface) {
                 r = message_append_field_string(t, BUS_MESSAGE_HEADER_INTERFACE, SD_BUS_TYPE_STRING, interface, &t->interface);
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
         if (destination) {
                 r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &t->destination);
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
-        *m = t;
+        *m = TAKE_PTR(t);
         return 0;
-
-fail:
-        message_free(t);
-        return r;
 }
 
 static int message_new_reply(
@@ -715,7 +678,8 @@ static int message_new_reply(
                 uint8_t type,
                 sd_bus_message **m) {
 
-        sd_bus_message *t;
+        _cleanup_(message_freep) sd_bus_message *t = NULL;
+        uint64_t cookie;
         int r;
 
         assert_return(call, -EINVAL);
@@ -724,34 +688,33 @@ static int message_new_reply(
         assert_return(call->bus->state != BUS_UNSET, -ENOTCONN);
         assert_return(m, -EINVAL);
 
-        t = message_new(call->bus, type);
-        if (!t)
+        cookie = BUS_MESSAGE_COOKIE(call);
+        if (cookie == 0)
+                return -EOPNOTSUPP;
+
+        r = sd_bus_message_new(call->bus, &t, type);
+        if (r < 0)
                 return -ENOMEM;
 
-        t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
-        t->reply_cookie = BUS_MESSAGE_COOKIE(call);
-        if (t->reply_cookie == 0)
-                return -EOPNOTSUPP;
+        assert(t);
 
+        t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
+        t->reply_cookie = cookie;
         r = message_append_reply_cookie(t, t->reply_cookie);
         if (r < 0)
-                goto fail;
+                return r;
 
         if (call->sender) {
                 r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, call->sender, &t->destination);
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
         t->dont_send = !!(call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED);
         t->enforced_reply_signature = call->enforced_reply_signature;
 
-        *m = t;
+        *m = TAKE_PTR(t);
         return 0;
-
-fail:
-        message_free(t);
-        return r;
 }
 
 _public_ int sd_bus_message_new_method_return(
@@ -766,7 +729,7 @@ _public_ int sd_bus_message_new_method_error(
                 sd_bus_message **m,
                 const sd_bus_error *e) {
 
-        sd_bus_message *t;
+        _cleanup_(message_freep) sd_bus_message *t = NULL;
         int r;
 
         assert_return(sd_bus_error_is_set(e), -EINVAL);
@@ -778,22 +741,18 @@ _public_ int sd_bus_message_new_method_error(
 
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name);
         if (r < 0)
-                goto fail;
+                return r;
 
         if (e->message) {
                 r = message_append_basic(t, SD_BUS_TYPE_STRING, e->message, (const void**) &t->error.message);
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
         t->error._need_free = -1;
 
-        *m = t;
+        *m = TAKE_PTR(t);
         return 0;
-
-fail:
-        message_free(t);
-        return r;
 }
 
 _public_ int sd_bus_message_new_method_errorf(
@@ -803,7 +762,7 @@ _public_ int sd_bus_message_new_method_errorf(
                 const char *format,
                 ...) {
 
-        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
         va_list ap;
 
         assert_return(name, -EINVAL);
@@ -822,7 +781,7 @@ _public_ int sd_bus_message_new_method_errno(
                 int error,
                 const sd_bus_error *p) {
 
-        _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL;
 
         if (sd_bus_error_is_set(p))
                 return sd_bus_message_new_method_error(call, m, p);
@@ -832,8 +791,6 @@ _public_ int sd_bus_message_new_method_errno(
         return sd_bus_message_new_method_error(call, m, &berror);
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_new_method_errnof(
                 sd_bus_message *call,
                 sd_bus_message **m,
@@ -841,7 +798,7 @@ _public_ int sd_bus_message_new_method_errnof(
                 const char *format,
                 ...) {
 
-        _cleanup_bus_error_free_ sd_bus_error berror = SD_BUS_ERROR_NULL;
+        _cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL;
         va_list ap;
 
         va_start(ap, format);
@@ -850,7 +807,6 @@ _public_ int sd_bus_message_new_method_errnof(
 
         return sd_bus_message_new_method_error(call, m, &berror);
 }
-#endif // 0
 
 void bus_message_set_sender_local(sd_bus *bus, sd_bus_message *m) {
         assert(bus);
@@ -876,54 +832,54 @@ int bus_message_new_synthetic_error(
                 const sd_bus_error *e,
                 sd_bus_message **m) {
 
-        sd_bus_message *t;
+        _cleanup_(message_freep) sd_bus_message *t = NULL;
         int r;
 
         assert(bus);
         assert(sd_bus_error_is_set(e));
         assert(m);
 
-        t = message_new(bus, SD_BUS_MESSAGE_METHOD_ERROR);
-        if (!t)
+        r = sd_bus_message_new(bus, &t, SD_BUS_MESSAGE_METHOD_ERROR);
+        if (r < 0)
                 return -ENOMEM;
 
+        assert(t);
+
         t->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
         t->reply_cookie = cookie;
 
         r = message_append_reply_cookie(t, t->reply_cookie);
         if (r < 0)
-                goto fail;
+                return r;
 
         if (bus && bus->unique_name) {
                 r = message_append_field_string(t, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, bus->unique_name, &t->destination);
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
         r = message_append_field_string(t, BUS_MESSAGE_HEADER_ERROR_NAME, SD_BUS_TYPE_STRING, e->name, &t->error.name);
         if (r < 0)
-                goto fail;
+                return r;
 
         if (e->message) {
                 r = message_append_basic(t, SD_BUS_TYPE_STRING, e->message, (const void**) &t->error.message);
                 if (r < 0)
-                        goto fail;
+                        return r;
         }
 
         t->error._need_free = -1;
 
         bus_message_set_sender_driver(bus, t);
 
-        *m = t;
+        *m = TAKE_PTR(t);
         return 0;
-
-fail:
-        message_free(t);
-        return r;
 }
 
 _public_ sd_bus_message* sd_bus_message_ref(sd_bus_message *m) {
-        assert_return(m, NULL);
+
+        if (!m)
+                return NULL;
 
         assert(m->n_ref > 0);
         m->n_ref++;
@@ -942,12 +898,9 @@ _public_ sd_bus_message* sd_bus_message_unref(sd_bus_message *m) {
         if (m->n_ref > 0)
                 return NULL;
 
-        message_free(m);
-        return NULL;
+        return message_free(m);
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type) {
         assert_return(m, -EINVAL);
         assert_return(type, -EINVAL);
@@ -993,7 +946,6 @@ _public_ int sd_bus_message_get_auto_start(sd_bus_message *m) {
 
         return !(m->header->flags & BUS_MESSAGE_NO_AUTO_START);
 }
-#endif // 0
 
 _public_ int sd_bus_message_get_allow_interactive_authorization(sd_bus_message *m) {
         assert_return(m, -EINVAL);
@@ -1034,13 +986,13 @@ _public_ const char *sd_bus_message_get_sender(sd_bus_message *m) {
 
 _public_ const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m) {
         assert_return(m, NULL);
-        assert_return(sd_bus_error_is_set(&m->error), NULL);
+
+        if (!sd_bus_error_is_set(&m->error))
+                return NULL;
 
         return &m->error;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_get_monotonic_usec(sd_bus_message *m, uint64_t *usec) {
         assert_return(m, -EINVAL);
         assert_return(usec, -EINVAL);
@@ -1073,7 +1025,6 @@ _public_ int sd_bus_message_get_seqnum(sd_bus_message *m, uint64_t *seqnum) {
         *seqnum = m->seqnum;
         return 0;
 }
-#endif // 0
 
 _public_ sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m) {
         assert_return(m, NULL);
@@ -1084,8 +1035,6 @@ _public_ sd_bus_creds *sd_bus_message_get_creds(sd_bus_message *m) {
         return &m->creds;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_is_signal(
                 sd_bus_message *m,
                 const char *interface,
@@ -1096,15 +1045,14 @@ _public_ int sd_bus_message_is_signal(
         if (m->header->type != SD_BUS_MESSAGE_SIGNAL)
                 return 0;
 
-        if (interface && (!m->interface || !streq(m->interface, interface)))
+        if (interface && !streq_ptr(m->interface, interface))
                 return 0;
 
-        if (member &&  (!m->member || !streq(m->member, member)))
+        if (member && !streq_ptr(m->member, member))
                 return 0;
 
         return 1;
 }
-#endif // 0
 
 _public_ int sd_bus_message_is_method_call(
                 sd_bus_message *m,
@@ -1116,10 +1064,10 @@ _public_ int sd_bus_message_is_method_call(
         if (m->header->type != SD_BUS_MESSAGE_METHOD_CALL)
                 return 0;
 
-        if (interface && (!m->interface || !streq(m->interface, interface)))
+        if (interface && !streq_ptr(m->interface, interface))
                 return 0;
 
-        if (member &&  (!m->member || !streq(m->member, member)))
+        if (member && !streq_ptr(m->member, member))
                 return 0;
 
         return 1;
@@ -1131,54 +1079,39 @@ _public_ int sd_bus_message_is_method_error(sd_bus_message *m, const char *name)
         if (m->header->type != SD_BUS_MESSAGE_METHOD_ERROR)
                 return 0;
 
-        if (name && (!m->error.name || !streq(m->error.name, name)))
+        if (name && !streq_ptr(m->error.name, name))
                 return 0;
 
         return 1;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_set_expect_reply(sd_bus_message *m, int b) {
         assert_return(m, -EINVAL);
         assert_return(!m->sealed, -EPERM);
         assert_return(m->header->type == SD_BUS_MESSAGE_METHOD_CALL, -EPERM);
 
-        if (b)
-                m->header->flags &= ~BUS_MESSAGE_NO_REPLY_EXPECTED;
-        else
-                m->header->flags |= BUS_MESSAGE_NO_REPLY_EXPECTED;
+        SET_FLAG(m->header->flags, BUS_MESSAGE_NO_REPLY_EXPECTED, !b);
 
         return 0;
 }
-#endif // 0
 
 _public_ int sd_bus_message_set_auto_start(sd_bus_message *m, int b) {
         assert_return(m, -EINVAL);
         assert_return(!m->sealed, -EPERM);
 
-        if (b)
-                m->header->flags &= ~BUS_MESSAGE_NO_AUTO_START;
-        else
-                m->header->flags |= BUS_MESSAGE_NO_AUTO_START;
+        SET_FLAG(m->header->flags, BUS_MESSAGE_NO_AUTO_START, !b);
 
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_set_allow_interactive_authorization(sd_bus_message *m, int b) {
         assert_return(m, -EINVAL);
         assert_return(!m->sealed, -EPERM);
 
-        if (b)
-                m->header->flags |= BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
-        else
-                m->header->flags &= ~BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION;
+        SET_FLAG(m->header->flags, BUS_MESSAGE_ALLOW_INTERACTIVE_AUTHORIZATION, b);
 
         return 0;
 }
-#endif // 0
 
 static struct bus_container *message_get_container(sd_bus_message *m) {
         assert(m);
@@ -1215,7 +1148,7 @@ struct bus_body_part *message_append_part(sd_bus_message *m) {
 
         part->memfd = -1;
         m->body_end = part;
-        m->n_body_parts ++;
+        m->n_body_parts++;
 
         return part;
 }
@@ -1241,7 +1174,6 @@ static int part_make_space(
                 void **q) {
 
         void *n;
-        int r;
 
         assert(m);
         assert(part);
@@ -1250,61 +1182,19 @@ static int part_make_space(
         if (m->poisoned)
                 return -ENOMEM;
 
-        if (!part->data && part->memfd < 0) {
-                part->memfd = bus_kernel_pop_memfd(m->bus, &part->data, &part->mapped, &part->allocated);
-                part->mmap_begin = part->data;
-        }
-
-        if (part->memfd >= 0) {
-
-                if (part->allocated == 0 || sz > part->allocated) {
-                        uint64_t new_allocated;
-
-                        new_allocated = PAGE_ALIGN(sz > 0 ? 2 * sz : 1);
-                        r = memfd_set_size(part->memfd, new_allocated);
-                        if (r < 0) {
-                                m->poisoned = true;
-                                return r;
-                        }
-
-                        part->allocated = new_allocated;
-                }
-
-                if (!part->data || sz > part->mapped) {
-                        size_t psz;
-
-                        psz = PAGE_ALIGN(sz > 0 ? sz : 1);
-                        if (part->mapped <= 0)
-                                n = mmap(NULL, psz, PROT_READ|PROT_WRITE, MAP_SHARED, part->memfd, 0);
-                        else
-                                n = mremap(part->mmap_begin, part->mapped, psz, MREMAP_MAYMOVE);
-
-                        if (n == MAP_FAILED) {
-                                m->poisoned = true;
-                                return -errno;
-                        }
+        if (part->allocated == 0 || sz > part->allocated) {
+                size_t new_allocated;
 
-                        part->mmap_begin = part->data = n;
-                        part->mapped = psz;
-                        part->memfd_offset = 0;
+                new_allocated = sz > 0 ? 2 * sz : 64;
+                n = realloc(part->data, new_allocated);
+                if (!n) {
+                        m->poisoned = true;
+                        return -ENOMEM;
                 }
 
-                part->munmap_this = true;
-        } else {
-                if (part->allocated == 0 || sz > part->allocated) {
-                        size_t new_allocated;
-
-                        new_allocated = sz > 0 ? 2 * sz : 64;
-                        n = realloc(part->data, new_allocated);
-                        if (!n) {
-                                m->poisoned = true;
-                                return -ENOMEM;
-                        }
-
-                        part->data = n;
-                        part->allocated = new_allocated;
-                        part->free_this = true;
-                }
+                part->data = n;
+                part->allocated = new_allocated;
+                part->free_this = true;
         }
 
         if (q)
@@ -1390,7 +1280,9 @@ static void *message_extend_body(
                         m->n_body_parts <= 0 ||
                         m->body_end->sealed ||
                         (padding != ALIGN_TO(m->body_end->size, align) - m->body_end->size) ||
-                        (force_inline && m->body_end->size > MEMFD_MIN_SIZE); /* if this must be an inlined extension, let's create a new part if the previous part is large enough to be inlined */
+                        (force_inline && m->body_end->size > MEMFD_MIN_SIZE);
+                        /* If this must be an inlined extension, let's create a new part if
+                         * the previous part is large enough to be inlined. */
 
                 if (add_new_part) {
                         if (padding > 0) {
@@ -1437,7 +1329,7 @@ static void *message_extend_body(
                 }
         } else
                 /* Return something that is not NULL and is aligned */
-                p = (uint8_t *) NULL + align;
+                p = (uint8_t*) align;
 
         m->body_size = end_body;
         message_extend_containers(m, added);
@@ -1468,7 +1360,7 @@ static int message_push_fd(sd_bus_message *m, int fd) {
         if (copy < 0)
                 return -errno;
 
-        f = realloc(m->fds, sizeof(int) * (m->n_fds + 1));
+        f = reallocarray(m->fds, sizeof(int), m->n_fds + 1);
         if (!f) {
                 m->poisoned = true;
                 safe_close(copy);
@@ -1524,7 +1416,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
                 case SD_BUS_TYPE_STRING:
                         p = strempty(p);
 
-                        /* Fall through... */
+                        _fallthrough_;
                 case SD_BUS_TYPE_OBJECT_PATH:
                         if (!p)
                                 return -EINVAL;
@@ -1584,7 +1476,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
                          * into the empty string */
                         p = strempty(p);
 
-                        /* Fall through... */
+                        _fallthrough_;
                 case SD_BUS_TYPE_OBJECT_PATH:
 
                         if (!p)
@@ -1638,7 +1530,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
                 if (!a)
                         return -ENOMEM;
 
-                if (type == SD_BUS_TYPE_STRING || type == SD_BUS_TYPE_OBJECT_PATH) {
+                if (IN_SET(type, SD_BUS_TYPE_STRING, SD_BUS_TYPE_OBJECT_PATH)) {
                         *(uint32_t*) a = sz - 5;
                         memcpy((uint8_t*) a + 4, p, sz - 4);
 
@@ -1660,7 +1552,7 @@ int message_append_basic(sd_bus_message *m, char type, const void *p, const void
         }
 
         if (type == SD_BUS_TYPE_UNIX_FD)
-                m->n_fds ++;
+                m->n_fds++;
 
         if (c->enclosing != SD_BUS_TYPE_ARRAY)
                 c->index++;
@@ -1730,12 +1622,10 @@ _public_ int sd_bus_message_append_string_space(
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_append_string_iovec(
                 sd_bus_message *m,
                 const struct iovec *iov,
-                unsigned n) {
+                unsigned n /* should be size_t, but is API now… ðŸ˜ž */) {
 
         size_t size;
         unsigned i;
@@ -1765,7 +1655,6 @@ _public_ int sd_bus_message_append_string_iovec(
 
         return 0;
 }
-#endif // 0
 
 static int bus_message_open_array(
                 sd_bus_message *m,
@@ -2062,7 +1951,7 @@ _public_ int sd_bus_message_open_container(
 
         struct bus_container *c, *w;
         uint32_t *array_size = NULL;
-        char *signature;
+        _cleanup_free_ char *signature = NULL;
         size_t before, begin = 0;
         bool need_offsets = false;
         int r;
@@ -2101,16 +1990,13 @@ _public_ int sd_bus_message_open_container(
                 r = bus_message_open_dict_entry(m, c, contents, &begin, &need_offsets);
         else
                 r = -EINVAL;
-
-        if (r < 0) {
-                free(signature);
+        if (r < 0)
                 return r;
-        }
 
         /* OK, let's fill it in */
         w = m->containers + m->n_containers++;
         w->enclosing = type;
-        w->signature = signature;
+        w->signature = TAKE_PTR(signature);
         w->index = 0;
         w->array_size = array_size;
         w->before = before;
@@ -2320,7 +2206,7 @@ _public_ int sd_bus_message_close_container(sd_bus_message *m) {
                 r = bus_message_close_array(m, c);
         else if (c->enclosing == SD_BUS_TYPE_VARIANT)
                 r = bus_message_close_variant(m, c);
-        else if (c->enclosing == SD_BUS_TYPE_STRUCT || c->enclosing == SD_BUS_TYPE_DICT_ENTRY)
+        else if (IN_SET(c->enclosing, SD_BUS_TYPE_STRUCT, SD_BUS_TYPE_DICT_ENTRY))
                 r = bus_message_close_struct(m, c, true);
         else
                 assert_not_reached("Unknown container type");
@@ -2370,7 +2256,7 @@ static int type_stack_pop(TypeStack *stack, unsigned max, unsigned *i, const cha
         return 1;
 }
 
-int bus_message_append_ap(
+_public_ int sd_bus_message_appendv(
                 sd_bus_message *m,
                 const char *types,
                 va_list ap) {
@@ -2380,10 +2266,10 @@ int bus_message_append_ap(
         unsigned stack_ptr = 0;
         int r;
 
-        assert(m);
-
-        if (!types)
-                return 0;
+        assert_return(m, -EINVAL);
+        assert_return(types, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->poisoned, -ESTALE);
 
         n_array = (unsigned) -1;
         n_struct = strlen(types);
@@ -2407,9 +2293,9 @@ int bus_message_append_ap(
 
                 t = types;
                 if (n_array != (unsigned) -1)
-                        n_array --;
+                        n_array--;
                 else {
-                        types ++;
+                        types++;
                         n_struct--;
                 }
 
@@ -2584,7 +2470,7 @@ _public_ int sd_bus_message_append(sd_bus_message *m, const char *types, ...) {
         assert_return(!m->poisoned, -ESTALE);
 
         va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
+        r = sd_bus_message_appendv(m, types, ap);
         va_end(ap);
 
         return r;
@@ -2651,19 +2537,16 @@ _public_ int sd_bus_message_append_array(
         if (r < 0)
                 return r;
 
-        if (size > 0)
-                memcpy(p, ptr, size);
+        memcpy_safe(p, ptr, size);
 
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_append_array_iovec(
                 sd_bus_message *m,
                 char type,
                 const struct iovec *iov,
-                unsigned n) {
+                unsigned n /* should be size_t, but is API now… ðŸ˜ž */) {
 
         size_t size;
         unsigned i;
@@ -2710,7 +2593,7 @@ _public_ int sd_bus_message_append_array_memfd(
         int r;
 
         assert_return(m, -EINVAL);
-        assert_return(memfd >= 0, -EINVAL);
+        assert_return(memfd >= 0, -EBADF);
         assert_return(bus_type_is_trivial(type), -EINVAL);
         assert_return(size > 0, -EINVAL);
         assert_return(!m->sealed, -EPERM);
@@ -2720,7 +2603,7 @@ _public_ int sd_bus_message_append_array_memfd(
         if (r < 0)
                 return r;
 
-        copy_fd = dup(memfd);
+        copy_fd = fcntl(memfd, F_DUPFD_CLOEXEC, 3);
         if (copy_fd < 0)
                 return copy_fd;
 
@@ -2786,7 +2669,7 @@ _public_ int sd_bus_message_append_string_memfd(
         int r;
 
         assert_return(m, -EINVAL);
-        assert_return(memfd >= 0, -EINVAL);
+        assert_return(memfd >= 0, -EBADF);
         assert_return(size > 0, -EINVAL);
         assert_return(!m->sealed, -EPERM);
         assert_return(!m->poisoned, -ESTALE);
@@ -2795,7 +2678,7 @@ _public_ int sd_bus_message_append_string_memfd(
         if (r < 0)
                 return r;
 
-        copy_fd = dup(memfd);
+        copy_fd = fcntl(memfd, FD_CLOEXEC, 3);
         if (copy_fd < 0)
                 return copy_fd;
 
@@ -2869,7 +2752,6 @@ _public_ int sd_bus_message_append_string_memfd(
 
         return 0;
 }
-#endif // 0
 
 _public_ int sd_bus_message_append_strv(sd_bus_message *m, char **l) {
         char **i;
@@ -2898,7 +2780,7 @@ static int bus_message_close_header(sd_bus_message *m) {
 
         /* The actual user data is finished now, we just complete the
            variant and struct now (at least on gvariant). Remember
-           this position, so that during parsing we know where to to
+           this position, so that during parsing we know where to
            put the outer container end. */
         m->user_body_size = m->body_size;
 
@@ -2952,13 +2834,13 @@ static int bus_message_close_header(sd_bus_message *m) {
         return 0;
 }
 
-int bus_message_seal(sd_bus_message *m, uint64_t cookie, usec_t timeout) {
+_public_ int sd_bus_message_seal(sd_bus_message *m, uint64_t cookie, uint64_t timeout_usec) {
         struct bus_body_part *part;
         size_t a;
         unsigned i;
         int r;
 
-        assert(m);
+        assert_return(m, -EINVAL);
 
         if (m->sealed)
                 return -EPERM;
@@ -3008,7 +2890,7 @@ int bus_message_seal(sd_bus_message *m, uint64_t cookie, usec_t timeout) {
         else
                 m->header->dbus1.serial = (uint32_t) cookie;
 
-        m->timeout = m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED ? 0 : timeout;
+        m->timeout = m->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED ? 0 : timeout_usec;
 
         /* Add padding at the end of the fields part, since we know
          * the body needs to start at an 8 byte alignment. We made
@@ -3170,8 +3052,6 @@ static bool message_end_of_array(sd_bus_message *m, size_t index) {
         }
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
         assert_return(m, -EINVAL);
         assert_return(m->sealed, -EPERM);
@@ -3187,7 +3067,6 @@ _public_ int sd_bus_message_at_end(sd_bus_message *m, int complete) {
 
         return false;
 }
-#endif // 0
 
 static struct bus_body_part* find_part(sd_bus_message *m, size_t index, size_t sz, void **p) {
         struct bus_body_part *part;
@@ -3269,9 +3148,7 @@ static int container_next_item(sd_bus_message *m, struct bus_container *c, size_
 
                 c->offset_index++;
 
-        } else if (c->enclosing == 0 ||
-                   c->enclosing == SD_BUS_TYPE_STRUCT ||
-                   c->enclosing == SD_BUS_TYPE_DICT_ENTRY) {
+        } else if (IN_SET(c->enclosing, 0, SD_BUS_TYPE_STRUCT, SD_BUS_TYPE_DICT_ENTRY)) {
 
                 int alignment;
                 size_t n, j;
@@ -3315,7 +3192,6 @@ end:
         return 0;
 }
 
-
 static int message_peek_body(
                 sd_bus_message *m,
                 size_t *rindex,
@@ -3893,7 +3769,7 @@ static int build_struct_offsets(
                 if (r < 0)
                         return r;
                 if (r == 0 && p[n] != 0) /* except the last item */
-                        n_variable ++;
+                        n_variable++;
                 n_total++;
 
                 p += n;
@@ -4092,9 +3968,9 @@ _public_ int sd_bus_message_enter_container(sd_bus_message *m,
                                             const char *contents) {
         struct bus_container *c, *w;
         uint32_t *array_size = NULL;
-        char *signature;
+        _cleanup_free_ char *signature = NULL;
         size_t before;
-        size_t *offsets = NULL;
+        _cleanup_free_ size_t *offsets = NULL;
         size_t n_offsets = 0, item_size = 0;
         int r;
 
@@ -4168,17 +4044,13 @@ _public_ int sd_bus_message_enter_container(sd_bus_message *m,
                 r = bus_message_enter_dict_entry(m, c, contents, &item_size, &offsets, &n_offsets);
         else
                 r = -EINVAL;
-
-        if (r <= 0) {
-                free(signature);
-                free(offsets);
+        if (r <= 0)
                 return r;
-        }
 
         /* OK, let's fill it in */
         w = m->containers + m->n_containers++;
         w->enclosing = type;
-        w->signature = signature;
+        w->signature = TAKE_PTR(signature);
         w->peeked_signature = NULL;
         w->index = 0;
 
@@ -4195,7 +4067,7 @@ _public_ int sd_bus_message_enter_container(sd_bus_message *m,
 
         w->array_size = array_size;
         w->item_size = item_size;
-        w->offsets = offsets;
+        w->offsets = TAKE_PTR(offsets);
         w->n_offsets = n_offsets;
         w->offset_index = 0;
 
@@ -4319,8 +4191,7 @@ _public_ int sd_bus_message_peek_type(sd_bus_message *m, char *type, const char
                 return 1;
         }
 
-        if (c->signature[c->index] == SD_BUS_TYPE_STRUCT_BEGIN ||
-            c->signature[c->index] == SD_BUS_TYPE_DICT_ENTRY_BEGIN) {
+        if (IN_SET(c->signature[c->index], SD_BUS_TYPE_STRUCT_BEGIN, SD_BUS_TYPE_DICT_ENTRY_BEGIN)) {
 
                 if (contents) {
                         size_t l;
@@ -4493,9 +4364,9 @@ static int message_read_ap(
 
                 t = types;
                 if (n_array != (unsigned) -1)
-                        n_array --;
+                        n_array--;
                 else {
-                        types ++;
+                        types++;
                         n_struct--;
                 }
 
@@ -4861,7 +4732,7 @@ _public_ int sd_bus_message_read_array(
         if (sz == 0)
                 /* Zero length array, let's return some aligned
                  * pointer that is not NULL */
-                p = (uint8_t*) NULL + align;
+                p = (uint8_t*) align;
         else {
                 r = message_peek_body(m, &m->rindex, align, sz, &p);
                 if (r < 0)
@@ -5158,8 +5029,7 @@ static int message_skip_fields(
 
                         (*signature)++;
 
-                } else if (t == SD_BUS_TYPE_STRUCT ||
-                           t == SD_BUS_TYPE_DICT_ENTRY) {
+                } else if (IN_SET(t, SD_BUS_TYPE_STRUCT, SD_BUS_TYPE_DICT_ENTRY)) {
 
                         r = signature_element_length(*signature, &l);
                         if (r < 0)
@@ -5404,14 +5274,13 @@ int bus_message_parse_fields(sd_bus_message *m) {
 
                         r = message_peek_field_string(m, service_name_is_valid, &ri, item_size, &m->sender);
 
-                        if (r >= 0 && m->sender[0] == ':' && m->bus->bus_client && !m->bus->is_kernel) {
+                        if (r >= 0 && m->sender[0] == ':' && m->bus->bus_client) {
                                 m->creds.unique_name = (char*) m->sender;
                                 m->creds.mask |= SD_BUS_CREDS_UNIQUE_NAME & m->bus->creds_mask;
                         }
 
                         break;
 
-
                 case BUS_MESSAGE_HEADER_SIGNATURE: {
                         const char *s;
                         char *c;
@@ -5433,8 +5302,7 @@ int bus_message_parse_fields(sd_bus_message *m) {
                         if (!c)
                                 return -ENOMEM;
 
-                        free(m->root_container.signature);
-                        m->root_container.signature = c;
+                        free_and_replace(m->root_container.signature, c);
                         break;
                 }
 
@@ -5571,12 +5439,20 @@ _public_ int sd_bus_message_set_destination(sd_bus_message *m, const char *desti
         return message_append_field_string(m, BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
 }
 
-/// UNNEEDED by elogind
-#if 0
+_public_ int sd_bus_message_set_sender(sd_bus_message *m, const char *sender) {
+        assert_return(m, -EINVAL);
+        assert_return(sender, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+        assert_return(!m->sender, -EEXIST);
+
+        return message_append_field_string(m, BUS_MESSAGE_HEADER_SENDER, SD_BUS_TYPE_STRING, sender, &m->sender);
+}
+
+#if 0 /// UNNEEDED by elogind
 int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
         size_t total;
         void *p, *e;
-        unsigned i;
+        size_t i;
         struct bus_body_part *part;
 
         assert(m);
@@ -5629,7 +5505,7 @@ int bus_message_read_strv_extend(sd_bus_message *m, char ***l) {
 }
 
 _public_ int sd_bus_message_read_strv(sd_bus_message *m, char ***l) {
-        char **strv = NULL;
+        _cleanup_strv_free_ char **strv = NULL;
         int r;
 
         assert_return(m, -EINVAL);
@@ -5637,30 +5513,30 @@ _public_ int sd_bus_message_read_strv(sd_bus_message *m, char ***l) {
         assert_return(l, -EINVAL);
 
         r = bus_message_read_strv_extend(m, &strv);
-        if (r <= 0) {
-                strv_free(strv);
+        if (r <= 0)
                 return r;
-        }
 
-        *l = strv;
+        *l = TAKE_PTR(strv);
         return 1;
 }
 
-int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str, char ***strv) {
-        const char *contents;
+static int bus_message_get_arg_skip(
+                sd_bus_message *m,
+                unsigned i,
+                char *_type,
+                const char **_contents) {
+
         unsigned j;
-        char type;
         int r;
 
-        assert(m);
-        assert(str);
-        assert(strv);
-
         r = sd_bus_message_rewind(m, true);
         if (r < 0)
                 return r;
 
         for (j = 0;; j++) {
+                const char *contents;
+                char type;
+
                 r = sd_bus_message_peek_type(m, &type, &contents);
                 if (r < 0)
                         return r;
@@ -5672,31 +5548,56 @@ int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str, char **
                     !(type == SD_BUS_TYPE_ARRAY && STR_IN_SET(contents, "s", "o", "g")))
                         return -ENXIO;
 
-                if (j >= i)
-                        break;
+                if (j >= i) {
+                        if (_contents)
+                                *_contents = contents;
+                        if (_type)
+                                *_type = type;
+                        return 0;
+                }
 
                 r = sd_bus_message_skip(m, NULL);
                 if (r < 0)
                         return r;
         }
 
-        if (type == SD_BUS_TYPE_ARRAY) {
+}
 
-                r = sd_bus_message_read_strv(m, strv);
-                if (r < 0)
-                        return r;
+int bus_message_get_arg(sd_bus_message *m, unsigned i, const char **str) {
+        char type;
+        int r;
 
-                *str = NULL;
+        assert(m);
+        assert(str);
 
-        } else {
-                r = sd_bus_message_read_basic(m, type, str);
-                if (r < 0)
-                        return r;
+        r = bus_message_get_arg_skip(m, i, &type, NULL);
+        if (r < 0)
+                return r;
 
-                *strv = NULL;
-        }
+        if (!IN_SET(type, SD_BUS_TYPE_STRING, SD_BUS_TYPE_OBJECT_PATH, SD_BUS_TYPE_SIGNATURE))
+                return -ENXIO;
 
-        return 0;
+        return sd_bus_message_read_basic(m, type, str);
+}
+
+int bus_message_get_arg_strv(sd_bus_message *m, unsigned i, char ***strv) {
+        const char *contents;
+        char type;
+        int r;
+
+        assert(m);
+        assert(strv);
+
+        r = bus_message_get_arg_skip(m, i, &type, &contents);
+        if (r < 0)
+                return r;
+
+        if (type != SD_BUS_TYPE_ARRAY)
+                return -ENXIO;
+        if (!STR_IN_SET(contents, "s", "o", "g"))
+                return -ENXIO;
+
+        return sd_bus_message_read_strv(m, strv);
 }
 
 _public_ int sd_bus_message_get_errno(sd_bus_message *m) {
@@ -5717,8 +5618,6 @@ _public_ const char* sd_bus_message_get_signature(sd_bus_message *m, int complet
         return strempty(c->signature);
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_is_empty(sd_bus_message *m) {
         assert_return(m, -EINVAL);
 
@@ -5730,7 +5629,6 @@ _public_ int sd_bus_message_has_signature(sd_bus_message *m, const char *signatu
 
         return streq(strempty(m->root_container.signature), strempty(signature));
 }
-#endif // 0
 
 _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int all) {
         bool done_something = false;
@@ -5796,9 +5694,7 @@ _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int
 
                 assert(r > 0);
 
-                if (type == SD_BUS_TYPE_OBJECT_PATH ||
-                    type == SD_BUS_TYPE_SIGNATURE ||
-                    type == SD_BUS_TYPE_STRING)
+                if (IN_SET(type, SD_BUS_TYPE_OBJECT_PATH, SD_BUS_TYPE_SIGNATURE, SD_BUS_TYPE_STRING))
                         r = sd_bus_message_append_basic(m, type, basic.string);
                 else
                         r = sd_bus_message_append_basic(m, type, &basic);
@@ -5811,8 +5707,6 @@ _public_ int sd_bus_message_copy(sd_bus_message *m, sd_bus_message *source, int
         return done_something;
 }
 
-/// UNNEEDED by elogind
-#if 0
 _public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char *contents) {
         const char *c;
         char t;
@@ -5837,7 +5731,6 @@ _public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char
 
         return 1;
 }
-#endif // 0
 
 _public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
         assert_return(m, NULL);
@@ -5846,7 +5739,7 @@ _public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
 }
 
 int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
-        _cleanup_bus_message_unref_ sd_bus_message *n = NULL;
+        _cleanup_(sd_bus_message_unrefp) sd_bus_message *n = NULL;
         usec_t timeout;
         int r;
 
@@ -5873,10 +5766,12 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
         case SD_BUS_MESSAGE_METHOD_RETURN:
         case SD_BUS_MESSAGE_METHOD_ERROR:
 
-                n = message_new(bus, (*m)->header->type);
-                if (!n)
+                r = sd_bus_message_new(bus, &n, (*m)->header->type);
+                if (r < 0)
                         return -ENOMEM;
 
+                assert(n);
+
                 n->reply_cookie = (*m)->reply_cookie;
 
                 r = message_append_reply_cookie(n, n->reply_cookie);
@@ -5919,19 +5814,17 @@ int bus_message_remarshal(sd_bus *bus, sd_bus_message **m) {
         if (timeout == 0 && !((*m)->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED))
                 timeout = BUS_DEFAULT_TIMEOUT;
 
-        r = bus_message_seal(n, BUS_MESSAGE_COOKIE(*m), timeout);
+        r = sd_bus_message_seal(n, BUS_MESSAGE_COOKIE(*m), timeout);
         if (r < 0)
                 return r;
 
         sd_bus_message_unref(*m);
-        *m = n;
-        n = NULL;
+        *m = TAKE_PTR(n);
 
         return 0;
 }
 
-/// UNNEEDED by elogind
-#if 0
+#if 0 /// UNNEEDED by elogind
 int bus_message_append_sender(sd_bus_message *m, const char *sender) {
         assert(m);
         assert(sender);
@@ -5941,6 +5834,7 @@ int bus_message_append_sender(sd_bus_message *m, const char *sender) {
 
         return message_append_field_string(m, BUS_MESSAGE_HEADER_SENDER, SD_BUS_TYPE_STRING, sender, &m->sender);
 }
+#endif // 0
 
 _public_ int sd_bus_message_get_priority(sd_bus_message *m, int64_t *priority) {
         assert_return(m, -EINVAL);
@@ -5957,4 +5851,3 @@ _public_ int sd_bus_message_set_priority(sd_bus_message *m, int64_t priority) {
         m->priority = priority;
         return 0;
 }
-#endif // 0