[systemd-commits] 11 commits - Makefile.am src/hostname src/journal src/libsystemd-bus src/locale src/login src/machine src/network src/nspawn src/run src/socket-proxy src/systemctl src/systemd src/timedate

Lennart Poettering lennart at kemper.freedesktop.org
Mon Nov 11 15:13:14 PST 2013


 Makefile.am                                    |   52 ++++
 src/hostname/hostnamed.c                       |    4 
 src/journal/journal-gatewayd.c                 |    2 
 src/libsystemd-bus/bus-control.c               |   48 ++--
 src/libsystemd-bus/bus-convenience.c           |    4 
 src/libsystemd-bus/bus-internal.h              |    3 
 src/libsystemd-bus/bus-message.c               |  284 +------------------------
 src/libsystemd-bus/bus-message.h               |    1 
 src/libsystemd-bus/bus-util.c                  |    8 
 src/libsystemd-bus/busctl.c                    |   15 +
 src/libsystemd-bus/libsystemd-bus.sym          |   11 
 src/libsystemd-bus/sd-bus.c                    |   99 +++++++-
 src/libsystemd-bus/sd-event.c                  |   48 ++++
 src/libsystemd-bus/test-bus-chat.c             |    6 
 src/libsystemd-bus/test-bus-kernel-benchmark.c |    2 
 src/libsystemd-bus/test-bus-kernel.c           |    1 
 src/libsystemd-bus/test-bus-marshal.c          |    1 
 src/libsystemd-bus/test-bus-server.c           |    2 
 src/libsystemd-bus/test-bus-zero-copy.c        |    1 
 src/libsystemd-bus/test-event.c                |    4 
 src/locale/localectl.c                         |    2 
 src/locale/localed.c                           |    6 
 src/login/inhibit.c                            |    2 
 src/login/logind-dbus.c                        |    2 
 src/login/logind.c                             |    4 
 src/machine/machined-dbus.c                    |    2 
 src/machine/machined.c                         |    4 
 src/network/networkd-manager.c                 |    2 
 src/nspawn/nspawn.c                            |    2 
 src/run/run.c                                  |    2 
 src/socket-proxy/socket-proxyd.c               |    2 
 src/systemctl/systemctl.c                      |    6 
 src/systemd/_sd-common.h                       |    4 
 src/systemd/sd-bus.h                           |   12 -
 src/systemd/sd-event.h                         |    6 
 src/systemd/sd-id128.h                         |    8 
 src/systemd/sd-utf8.h                          |    4 
 src/timedate/timedated.c                       |    4 
 38 files changed, 310 insertions(+), 360 deletions(-)

New commits:
commit 2b5c5383e48137d748681645ad7176f02b50ba30
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Nov 12 00:12:08 2013 +0100

    bus: beautify bus_message_dump() output a bit

diff --git a/Makefile.am b/Makefile.am
index 55a945b..8710462 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2006,6 +2006,17 @@ libsystemd_bus_internal_la_CFLAGS = \
 noinst_LTLIBRARIES += \
 	libsystemd-bus-internal.la
 
+libsystemd_bus_dump_la_SOURCES = \
+	src/libsystemd-bus/bus-dump.c \
+	src/libsystemd-bus/bus-dump.h
+
+libsystemd_bus_dump_la_CFLAGS = \
+	$(AM_CFLAGS)
+	$(CAP_CFLAGS)
+
+noinst_LTLIBRARIES += \
+	libsystemd-bus-dump.la
+
 tests += \
 	test-bus-marshal \
 	test-bus-signature \
@@ -2032,13 +2043,17 @@ test_bus_marshal_LDADD = \
 	libsystemd-id128-internal.la \
 	libsystemd-daemon-internal.la \
 	libsystemd-shared.la \
+	libsystemd-bus-dump.la \
+	libsystemd-capability.la \
 	$(GLIB_LIBS) \
-	$(DBUS_LIBS)
+	$(DBUS_LIBS) \
+	$(CAP_LIBS)
 
 test_bus_marshal_CFLAGS = \
 	$(AM_CFLAGS) \
 	$(GLIB_CFLAGS) \
-	$(DBUS_CFLAGS)
+	$(DBUS_CFLAGS) \
+	$(CAP_CFLAGS)
 
 test_bus_signature_SOURCES = \
 	src/libsystemd-bus/test-bus-signature.c
@@ -2078,13 +2093,17 @@ test_bus_objects_SOURCES = \
 
 test_bus_objects_CFLAGS = \
 	$(AM_CFLAGS) \
+	$(CAP_CFLAGS) \
 	-pthread
 
 test_bus_objects_LDADD = \
 	libsystemd-bus-internal.la \
 	libsystemd-id128-internal.la \
 	libsystemd-daemon-internal.la \
-	libsystemd-shared.la
+	libsystemd-shared.la \
+	libsystemd-bus-dump.la \
+	libsystemd-capability.la \
+	$(CAP_LIBS)
 
 test_bus_match_SOURCES = \
 	src/libsystemd-bus/test-bus-match.c
@@ -2102,7 +2121,14 @@ test_bus_kernel_LDADD = \
 	libsystemd-bus-internal.la \
 	libsystemd-id128-internal.la \
 	libsystemd-daemon-internal.la \
-	libsystemd-shared.la
+	libsystemd-shared.la \
+	libsystemd-bus-dump.la \
+	libsystemd-capability.la \
+	$(CAP_LIBS)
+
+test_bus_kernel_CFLAGS = \
+	$(AM_CFLAGS) \
+	$(CAP_CFLAGS)
 
 test_bus_kernel_bloom_SOURCES = \
 	src/libsystemd-bus/test-bus-kernel-bloom.c
@@ -2136,7 +2162,14 @@ test_bus_zero_copy_LDADD = \
 	libsystemd-bus-internal.la \
 	libsystemd-id128-internal.la \
 	libsystemd-daemon-internal.la \
-	libsystemd-shared.la
+	libsystemd-shared.la \
+	libsystemd-bus-dump.la \
+	libsystemd-capability.la \
+	$(CAP_LIBS)
+
+test_bus_zero_copy_CFLAGS = \
+	$(AM_CFLAGS) \
+	$(CAP_CFLAGS)
 
 test_bus_introspect_SOURCES = \
 	src/libsystemd-bus/test-bus-introspect.c
@@ -2161,7 +2194,14 @@ busctl_LDADD = \
 	libsystemd-bus-internal.la \
 	libsystemd-id128-internal.la \
 	libsystemd-daemon-internal.la \
-	libsystemd-shared.la
+	libsystemd-shared.la \
+	libsystemd-bus-dump.la \
+	libsystemd-capability.la \
+	$(CAP_LIBS)
+
+busctl_CFLAGS = \
+	$(AM_CFLAGS) \
+	$(CAP_CFLAGS)
 
 # ------------------------------------------------------------------------------
 if ENABLE_GTK_DOC
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index d7774db..4f21db5 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -4205,272 +4205,6 @@ _public_ int sd_bus_message_set_destination(sd_bus_message *m, const char *desti
         return message_append_field_string(m, SD_BUS_MESSAGE_HEADER_DESTINATION, SD_BUS_TYPE_STRING, destination, &m->destination);
 }
 
-int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header) {
-        const char *u = NULL, *uu = NULL, *s = NULL;
-        char **cmdline = NULL;
-        unsigned level = 1;
-        int r;
-        uid_t owner, audit_loginuid;
-        uint32_t audit_sessionid;
-
-        assert(m);
-
-        if (!f)
-                f = stdout;
-
-        if (with_header) {
-                fprintf(f,
-                        "Message %p\n"
-                        "\tn_ref=%u\n"
-                        "\tendian=%c\n"
-                        "\ttype=%i\n"
-                        "\tflags=%u\n"
-                        "\tversion=%u\n"
-                        "\tserial=%u\n"
-                        "\tfields_size=%u\n"
-                        "\tbody_size=%u\n"
-                        "\tpath=%s\n"
-                        "\tinterface=%s\n"
-                        "\tmember=%s\n"
-                        "\tdestination=%s\n"
-                        "\tsender=%s\n"
-                        "\tsignature=%s\n"
-                        "\treply_serial=%u\n"
-                        "\tsealed=%s\n"
-                        "\tn_body_parts=%u\n",
-                        m,
-                        m->n_ref,
-                        m->header->endian,
-                        m->header->type,
-                        m->header->flags,
-                        m->header->version,
-                        BUS_MESSAGE_SERIAL(m),
-                        BUS_MESSAGE_FIELDS_SIZE(m),
-                        BUS_MESSAGE_BODY_SIZE(m),
-                        strna(m->path),
-                        strna(m->interface),
-                        strna(m->member),
-                        strna(m->destination),
-                        strna(m->sender),
-                        strna(m->root_container.signature),
-                        m->reply_serial,
-                        yes_no(m->sealed),
-                        m->n_body_parts);
-
-                if (sd_bus_error_is_set(&m->error))
-                        fprintf(f,
-                                "\terror.name=%s\n"
-                                "\terror.message=%s\n",
-                                strna(m->error.name),
-                                strna(m->error.message));
-
-                if (m->pid != 0)
-                        fprintf(f, "\tpid=%lu\n", (unsigned long) m->pid);
-                if (m->tid != 0)
-                        fprintf(f, "\ttid=%lu\n", (unsigned long) m->tid);
-                if (m->uid_valid)
-                        fprintf(f, "\tuid=%lu\n", (unsigned long) m->uid);
-                if (m->gid_valid)
-                        fprintf(f, "\tgid=%lu\n", (unsigned long) m->gid);
-                if (m->pid_starttime != 0)
-                        fprintf(f, "\tpid_starttime=%llu\n", (unsigned long long) m->pid_starttime);
-                if (m->monotonic != 0)
-                        fprintf(f, "\tmonotonic=%llu\n", (unsigned long long) m->monotonic);
-                if (m->realtime != 0)
-                        fprintf(f, "\trealtime=%llu\n", (unsigned long long) m->realtime);
-                if (m->exe)
-                        fprintf(f, "\texe=[%s]\n", m->exe);
-                if (m->comm)
-                        fprintf(f, "\tcomm=[%s]\n", m->comm);
-                if (m->tid_comm)
-                        fprintf(f, "\ttid_comm=[%s]\n", m->tid_comm);
-                if (m->label)
-                        fprintf(f, "\tlabel=[%s]\n", m->label);
-                if (m->cgroup)
-                        fprintf(f, "\tcgroup=[%s]\n", m->cgroup);
-
-                sd_bus_message_get_unit(m, &u);
-                if (u)
-                        fprintf(f, "\tunit=[%s]\n", u);
-                sd_bus_message_get_user_unit(m, &uu);
-                if (uu)
-                        fprintf(f, "\tuser_unit=[%s]\n", uu);
-                sd_bus_message_get_session(m, &s);
-                if (s)
-                        fprintf(f, "\tsession=[%s]\n", s);
-                if (sd_bus_message_get_owner_uid(m, &owner) >= 0)
-                        fprintf(f, "\towner_uid=%lu\n", (unsigned long) owner);
-                if (sd_bus_message_get_audit_loginuid(m, &audit_loginuid) >= 0)
-                        fprintf(f, "\taudit_loginuid=%lu\n", (unsigned long) audit_loginuid);
-                if (sd_bus_message_get_audit_sessionid(m, &audit_sessionid) >= 0)
-                        fprintf(f, "\taudit_sessionid=%lu\n", (unsigned long) audit_sessionid);
-
-                r = sd_bus_message_has_effective_cap(m, 5);
-                if (r >= 0)
-                        fprintf(f, "\tCAP_KILL=%s\n", yes_no(r));
-
-                if (sd_bus_message_get_cmdline(m, &cmdline) >= 0) {
-                        char **c;
-
-                        fputs("\tcmdline=[", f);
-                        STRV_FOREACH(c, cmdline) {
-                                if (c != cmdline)
-                                        fputc(' ', f);
-
-                                fputs(*c, f);
-                        }
-
-                        fputs("]\n", f);
-                }
-        }
-
-        r = sd_bus_message_rewind(m, true);
-        if (r < 0) {
-                log_error("Failed to rewind: %s", strerror(-r));
-                return r;
-        }
-
-        fprintf(f, "MESSAGE \"%s\" {\n", strempty(m->root_container.signature));
-
-        for(;;) {
-                _cleanup_free_ char *prefix = NULL;
-                const char *contents = NULL;
-                char type;
-                union {
-                        uint8_t u8;
-                        uint16_t u16;
-                        int16_t s16;
-                        uint32_t u32;
-                        int32_t s32;
-                        uint64_t u64;
-                        int64_t s64;
-                        double d64;
-                        const char *string;
-                        int i;
-                } basic;
-
-                r = sd_bus_message_peek_type(m, &type, &contents);
-                if (r < 0) {
-                        log_error("Failed to peek type: %s", strerror(-r));
-                        return r;
-                }
-
-                if (r == 0) {
-                        if (level <= 1)
-                                break;
-
-                        r = sd_bus_message_exit_container(m);
-                        if (r < 0) {
-                                log_error("Failed to exit container: %s", strerror(-r));
-                                return r;
-                        }
-
-                        level--;
-
-                        prefix = strrep("\t", level);
-                        if (!prefix)
-                                return log_oom();
-
-                        fprintf(f, "%s};\n", prefix);
-                        continue;
-                }
-
-                prefix = strrep("\t", level);
-                if (!prefix)
-                        return log_oom();
-
-                if (bus_type_is_container(type) > 0) {
-                        r = sd_bus_message_enter_container(m, type, contents);
-                        if (r < 0) {
-                                log_error("Failed to enter container: %s", strerror(-r));
-                                return r;
-                        }
-
-                        if (type == SD_BUS_TYPE_ARRAY)
-                                fprintf(f, "%sARRAY \"%s\" {\n", prefix, contents);
-                        else if (type == SD_BUS_TYPE_VARIANT)
-                                fprintf(f, "%sVARIANT \"%s\" {\n", prefix, contents);
-                        else if (type == SD_BUS_TYPE_STRUCT)
-                                fprintf(f, "%sSTRUCT \"%s\" {\n", prefix, contents);
-                        else if (type == SD_BUS_TYPE_DICT_ENTRY)
-                                fprintf(f, "%sDICT_ENTRY \"%s\" {\n", prefix, contents);
-
-                        level ++;
-
-                        continue;
-                }
-
-                r = sd_bus_message_read_basic(m, type, &basic);
-                if (r < 0) {
-                        log_error("Failed to get basic: %s", strerror(-r));
-                        return r;
-                }
-
-                assert(r > 0);
-
-                switch (type) {
-
-                case SD_BUS_TYPE_BYTE:
-                        fprintf(f, "%sBYTE %u;\n", prefix, basic.u8);
-                        break;
-
-                case SD_BUS_TYPE_BOOLEAN:
-                        fprintf(f, "%sBOOLEAN %s;\n", prefix, yes_no(basic.i));
-                        break;
-
-                case SD_BUS_TYPE_INT16:
-                        fprintf(f, "%sINT16 %i;\n", prefix, basic.s16);
-                        break;
-
-                case SD_BUS_TYPE_UINT16:
-                        fprintf(f, "%sUINT16 %u;\n", prefix, basic.u16);
-                        break;
-
-                case SD_BUS_TYPE_INT32:
-                        fprintf(f, "%sINT32 %i;\n", prefix, basic.s32);
-                        break;
-
-                case SD_BUS_TYPE_UINT32:
-                        fprintf(f, "%sUINT32 %u;\n", prefix, basic.u32);
-                        break;
-
-                case SD_BUS_TYPE_INT64:
-                        fprintf(f, "%sINT64 %lli;\n", prefix, (long long) basic.s64);
-                        break;
-
-                case SD_BUS_TYPE_UINT64:
-                        fprintf(f, "%sUINT64 %llu;\n", prefix, (unsigned long long) basic.u64);
-                        break;
-
-                case SD_BUS_TYPE_DOUBLE:
-                        fprintf(f, "%sDOUBLE %g;\n", prefix, basic.d64);
-                        break;
-
-                case SD_BUS_TYPE_STRING:
-                        fprintf(f, "%sSTRING \"%s\";\n", prefix, basic.string);
-                        break;
-
-                case SD_BUS_TYPE_OBJECT_PATH:
-                        fprintf(f, "%sOBJECT_PATH \"%s\";\n", prefix, basic.string);
-                        break;
-
-                case SD_BUS_TYPE_SIGNATURE:
-                        fprintf(f, "%sSIGNATURE \"%s\";\n", prefix, basic.string);
-                        break;
-
-                case SD_BUS_TYPE_UNIX_FD:
-                        fprintf(f, "%sUNIX_FD %i;\n", prefix, basic.i);
-                        break;
-
-                default:
-                        assert_not_reached("Unknown basic type.");
-                }
-        }
-
-        fprintf(f, "};\n");
-        return 0;
-}
-
 int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz) {
         size_t total;
         void *p, *e;
diff --git a/src/libsystemd-bus/bus-message.h b/src/libsystemd-bus/bus-message.h
index d0f11d8..aec6f75 100644
--- a/src/libsystemd-bus/bus-message.h
+++ b/src/libsystemd-bus/bus-message.h
@@ -190,7 +190,6 @@ static inline void* BUS_MESSAGE_FIELDS(sd_bus_message *m) {
 }
 
 int bus_message_seal(sd_bus_message *m, uint64_t serial);
-int bus_message_dump(sd_bus_message *m, FILE *f, bool with_header);
 int bus_message_get_blob(sd_bus_message *m, void **buffer, size_t *sz);
 int bus_message_read_strv_extend(sd_bus_message *m, char ***l);
 
diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c
index d5ac2fe..b9b3305 100644
--- a/src/libsystemd-bus/busctl.c
+++ b/src/libsystemd-bus/busctl.c
@@ -31,6 +31,7 @@
 #include "bus-message.h"
 #include "bus-internal.h"
 #include "bus-util.h"
+#include "bus-dump.h"
 
 static bool arg_no_pager = false;
 static char *arg_address = NULL;
diff --git a/src/libsystemd-bus/test-bus-kernel.c b/src/libsystemd-bus/test-bus-kernel.c
index e498801..511c547 100644
--- a/src/libsystemd-bus/test-bus-kernel.c
+++ b/src/libsystemd-bus/test-bus-kernel.c
@@ -29,6 +29,7 @@
 #include "bus-error.h"
 #include "bus-kernel.h"
 #include "bus-util.h"
+#include "bus-dump.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_close_ int bus_ref = -1;
diff --git a/src/libsystemd-bus/test-bus-marshal.c b/src/libsystemd-bus/test-bus-marshal.c
index 8f36a71..cbf5e1a 100644
--- a/src/libsystemd-bus/test-bus-marshal.c
+++ b/src/libsystemd-bus/test-bus-marshal.c
@@ -37,6 +37,7 @@
 #include "sd-bus.h"
 #include "bus-message.h"
 #include "bus-util.h"
+#include "bus-dump.h"
 
 int main(int argc, char *argv[]) {
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *copy = NULL;
diff --git a/src/libsystemd-bus/test-bus-zero-copy.c b/src/libsystemd-bus/test-bus-zero-copy.c
index 0c07a33..032449a 100644
--- a/src/libsystemd-bus/test-bus-zero-copy.c
+++ b/src/libsystemd-bus/test-bus-zero-copy.c
@@ -30,6 +30,7 @@
 #include "bus-message.h"
 #include "bus-error.h"
 #include "bus-kernel.h"
+#include "bus-dump.h"
 
 #define FIRST_ARRAY 17
 #define SECOND_ARRAY 33

commit 7b0b392f7bce4bb1b17fec54d1baf27daa85777f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 23:45:36 2013 +0100

    busctl: show machine name of all registered names

diff --git a/src/libsystemd-bus/busctl.c b/src/libsystemd-bus/busctl.c
index 088111c..d5ac2fe 100644
--- a/src/libsystemd-bus/busctl.c
+++ b/src/libsystemd-bus/busctl.c
@@ -70,11 +70,12 @@ static int list_bus_names(sd_bus *bus, char **argv) {
         STRV_FOREACH(i, l)
                 max_i = MAX(max_i, strlen(*i));
 
-        printf("%-*s %*s %-*s %-*s CONNECTION\n",
-               (int) max_i, "NAME", 10, "PID", 15, "PROCESS", 16, "USER");
+        printf("%-*s %*s %-*s %-*s %-*s MACHINE\n",
+               (int) max_i, "NAME", 10, "PID", 15, "PROCESS", 16, "USER", 20, "CONNECTION");
 
         STRV_FOREACH(i, l) {
                 _cleanup_free_ char *owner = NULL;
+                sd_id128_t mid;
                 pid_t pid;
                 uid_t uid;
 
@@ -111,8 +112,15 @@ static int list_bus_names(sd_bus *bus, char **argv) {
 
                 r = sd_bus_get_owner(bus, *i, &owner);
                 if (r >= 0)
-                        printf(" %s\n", owner);
+                        printf(" %-20s", owner);
                 else
+                        printf(" -                   ");
+
+                r = sd_bus_get_owner_machine_id(bus, *i, &mid);
+                if (r >= 0) {
+                        char m[SD_ID128_STRING_MAX];
+                        printf(" %s\n", sd_id128_to_string(mid, m));
+                } else
                         printf(" -\n");
         }
 

commit 8d162091c0512e0c2bb0e7ac22b927f1f5af95b4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 23:44:00 2013 +0100

    bus: set no_auto_start flag for GetMachineId calls, so that we don't auto-start if we want to know the machine of a bus service

diff --git a/src/libsystemd-bus/bus-control.c b/src/libsystemd-bus/bus-control.c
index 4b43331..f217269 100644
--- a/src/libsystemd-bus/bus-control.c
+++ b/src/libsystemd-bus/bus-control.c
@@ -225,14 +225,10 @@ _public_ int sd_bus_get_owner(sd_bus *bus, const char *name, char **owner) {
         const char *found;
         int r;
 
-        if (!bus)
-                return -EINVAL;
-        if (!name)
-                return -EINVAL;
-        if (!BUS_IS_OPEN(bus->state))
-                return -ENOTCONN;
-        if (bus_pid_changed(bus))
-                return -ECHILD;
+        assert_return(bus, -EINVAL);
+        assert_return(name, -EINVAL);
+        assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
 
         r = sd_bus_call_method(
                         bus,
@@ -539,31 +535,33 @@ int bus_remove_match_internal(
 }
 
 _public_ int sd_bus_get_owner_machine_id(sd_bus *bus, const char *name, sd_id128_t *machine) {
-        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+        _cleanup_bus_message_unref_ sd_bus_message *reply = NULL, *m = NULL;
         const char *mid;
         int r;
 
-        if (!bus)
-                return -EINVAL;
-        if (!name)
-                return -EINVAL;
-        if (!BUS_IS_OPEN(bus->state))
-                return -ENOTCONN;
-        if (bus_pid_changed(bus))
-                return -ECHILD;
+        assert_return(bus, -EINVAL);
+        assert_return(name, -EINVAL);
+        assert_return(machine, -EINVAL);
+        assert_return(BUS_IS_OPEN(bus->state), -ENOTCONN);
+        assert_return(!bus_pid_changed(bus), -ECHILD);
 
         if (streq_ptr(name, bus->unique_name))
                 return sd_id128_get_machine(machine);
 
-        r = sd_bus_call_method(bus,
-                               name,
-                               "/",
-                               "org.freedesktop.DBus.Peer",
-                               "GetMachineId",
-                               NULL,
-                               &reply,
-                               NULL);
+        r = sd_bus_message_new_method_call(
+                        bus,
+                        name,
+                        "/",
+                        "org.freedesktop.DBus.Peer",
+                        "GetMachineId", &m);
+        if (r < 0)
+                return r;
+
+        r = sd_bus_message_set_no_auto_start(m, true);
+        if (r < 0)
+                return r;
 
+        r = sd_bus_call(bus, m, 0, NULL, &reply);
         if (r < 0)
                 return r;
 

commit a8a07f892c6f64d88a9848deed56a9f3b778301a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 23:42:30 2013 +0100

    bus: detect blocking message calls to our own connection and return ELOOP early

diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 3ecda17..89437c1 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1637,6 +1637,19 @@ _public_ int sd_bus_call(
 
                                 sd_bus_message_unref(incoming);
                                 return -EIO;
+
+                        } else if (incoming->header->serial == serial &&
+                                   bus->unique_name &&
+                                   incoming->sender &&
+                                   streq(bus->unique_name, incoming->sender)) {
+
+                                /* Our own message? Somebody is trying
+                                 * to send its own client a message,
+                                 * let's not dead-lock, let's fail
+                                 * immediately. */
+
+                                sd_bus_message_unref(incoming);
+                                return -ELOOP;
                         }
 
                         /* There's already guaranteed to be room for

commit 1fee9de5096fe9955b89523aedecf8962ab0e8c5
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 23:42:00 2013 +0100

    bus: add api to control auto start message flag

diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index b26d446..d7774db 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -777,6 +777,12 @@ _public_ int sd_bus_message_get_no_reply(sd_bus_message *m) {
         return m->header->type == SD_BUS_MESSAGE_METHOD_CALL ? !!(m->header->flags & SD_BUS_MESSAGE_NO_REPLY_EXPECTED) : 0;
 }
 
+_public_ int sd_bus_message_get_no_auto_start(sd_bus_message *m) {
+        assert_return(m, -EINVAL);
+
+        return !!(m->header->flags & SD_BUS_MESSAGE_NO_AUTO_START);
+}
+
 _public_ const char *sd_bus_message_get_path(sd_bus_message *m) {
         assert_return(m, NULL);
 
@@ -1100,6 +1106,18 @@ _public_ int sd_bus_message_set_no_reply(sd_bus_message *m, int b) {
         return 0;
 }
 
+_public_ int sd_bus_message_set_no_auto_start(sd_bus_message *m, int b) {
+        assert_return(m, -EINVAL);
+        assert_return(!m->sealed, -EPERM);
+
+        if (b)
+                m->header->flags |= SD_BUS_MESSAGE_NO_AUTO_START;
+        else
+                m->header->flags &= ~SD_BUS_MESSAGE_NO_AUTO_START;
+
+        return 0;
+}
+
 static struct bus_container *message_get_container(sd_bus_message *m) {
         assert(m);
 
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index b6ad84b..8f1dba2 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -85,6 +85,7 @@ global:
         sd_bus_message_get_serial;
         sd_bus_message_get_reply_serial;
         sd_bus_message_get_no_reply;
+        sd_bus_message_get_no_auto_start;
         sd_bus_message_get_signature;
         sd_bus_message_get_path;
         sd_bus_message_get_interface;
@@ -117,6 +118,7 @@ global:
         sd_bus_message_is_method_call;
         sd_bus_message_is_method_error;
         sd_bus_message_set_no_reply;
+        sd_bus_message_set_no_auto_start;
         sd_bus_message_set_destination;
         sd_bus_message_append;
         sd_bus_message_append_basic;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index ef5984f..61f232c 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -149,6 +149,7 @@ int sd_bus_message_get_type(sd_bus_message *m, uint8_t *type);
 int sd_bus_message_get_serial(sd_bus_message *m, uint64_t *serial);
 int sd_bus_message_get_reply_serial(sd_bus_message *m, uint64_t *serial);
 int sd_bus_message_get_no_reply(sd_bus_message *m);
+int sd_bus_message_get_no_auto_start(sd_bus_message *m);
 
 const char *sd_bus_message_get_signature(sd_bus_message *m, int complete);
 const char *sd_bus_message_get_path(sd_bus_message *m);
@@ -185,6 +186,7 @@ int sd_bus_message_is_method_call(sd_bus_message *m, const char *interface, cons
 int sd_bus_message_is_method_error(sd_bus_message *m, const char *name);
 
 int sd_bus_message_set_no_reply(sd_bus_message *m, int b);
+int sd_bus_message_set_no_auto_start(sd_bus_message *m, int b);
 int sd_bus_message_set_destination(sd_bus_message *m, const char *destination);
 
 int sd_bus_message_append(sd_bus_message *m, const char *types, ...);

commit 9b271c0316e59185f9ab5574c74d22b78bf6701d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 23:40:41 2013 +0100

    id128: introduce SD_ID128_STRING_MAX consant for sizing id128 strings

diff --git a/src/systemd/sd-id128.h b/src/systemd/sd-id128.h
index 5bae965..015ffb0 100644
--- a/src/systemd/sd-id128.h
+++ b/src/systemd/sd-id128.h
@@ -38,7 +38,9 @@ union sd_id128 {
         uint64_t qwords[2];
 };
 
-char *sd_id128_to_string(sd_id128_t id, char s[33]);
+#define SD_ID128_STRING_MAX 33
+
+char *sd_id128_to_string(sd_id128_t id, char s[SD_ID128_STRING_MAX]);
 
 int sd_id128_from_string(const char *s, sd_id128_t *ret);
 
@@ -61,7 +63,7 @@ int sd_id128_get_boot(sd_id128_t *ret);
 #define SD_ID128_FORMAT_VAL(x) (x).bytes[0], (x).bytes[1], (x).bytes[2], (x).bytes[3], (x).bytes[4], (x).bytes[5], (x).bytes[6], (x).bytes[7], (x).bytes[8], (x).bytes[9], (x).bytes[10], (x).bytes[11], (x).bytes[12], (x).bytes[13], (x).bytes[14], (x).bytes[15]
 
 #define SD_ID128_CONST_STR(x)                                           \
-        ((char[33]) {                                                   \
+        ((char[SD_ID128_STRING_MAX]) {                                  \
                 ((x).bytes[0] >> 4) >= 10 ? 'a' + ((x).bytes[0] >> 4) - 10 : '0' + ((x).bytes[0] >> 4), \
                 ((x).bytes[0] & 15) >= 10 ? 'a' + ((x).bytes[0] & 15) - 10 : '0' + ((x).bytes[0] & 15), \
                 ((x).bytes[1] >> 4) >= 10 ? 'a' + ((x).bytes[1] >> 4) - 10 : '0' + ((x).bytes[1] >> 4), \
@@ -96,7 +98,7 @@ int sd_id128_get_boot(sd_id128_t *ret);
                 ((x).bytes[15] & 15) >= 10 ? 'a' + ((x).bytes[15] & 15) - 10 : '0' + ((x).bytes[15] & 15), \
                 0 })
 
-static inline int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
+_sd_pure_ static inline int sd_id128_equal(sd_id128_t a, sd_id128_t b) {
         return memcmp(&a, &b, 16) == 0;
 }
 

commit 98f91566cc7d43c6b86a711fa1d196ed5876b2f3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 23:40:00 2013 +0100

    bus: export utf8 validator calls as pure functions

diff --git a/src/systemd/_sd-common.h b/src/systemd/_sd-common.h
index b0c48aa..594ff3d 100644
--- a/src/systemd/_sd-common.h
+++ b/src/systemd/_sd-common.h
@@ -40,6 +40,10 @@
 #  define _sd_packed_ __attribute__((packed))
 #endif
 
+#ifndef _sd_pure_
+#  define _sd_pure_ __attribute__((pure))
+#endif
+
 #ifndef _SD_STRINGIFY
 #  define _SD_XSTRINGIFY(x) #x
 #  define _SD_STRINGIFY(x) _SD_XSTRINGIFY(x)
diff --git a/src/systemd/sd-utf8.h b/src/systemd/sd-utf8.h
index 4a43eb7..205ee42 100644
--- a/src/systemd/sd-utf8.h
+++ b/src/systemd/sd-utf8.h
@@ -26,8 +26,8 @@
 
 _SD_BEGIN_DECLARATIONS;
 
-const char *sd_utf8_is_valid(const char *s);
-const char *sd_ascii_is_valid(const char *s);
+_sd_pure_ const char *sd_utf8_is_valid(const char *s);
+_sd_pure_ const char *sd_ascii_is_valid(const char *s);
 
 _SD_END_DECLARATIONS;
 

commit 76b543756ef69ce69784d571aefe8de65eaeb331
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 22:00:48 2013 +0100

    bus: introduce concept of a default bus for each thread and make use of it everywhere
    
    We want to emphasize bus connections as per-thread communication
    primitives, hence introduce a concept of a per-thread default bus, and
    make use of it everywhere.

diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index d2f0b02..4363b09 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -579,7 +579,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
         assert(event);
         assert(_bus);
 
-        r = sd_bus_open_system(&bus);
+        r = sd_bus_default_system(&bus);
         if (r < 0) {
                 log_error("Failed to get system bus connection: %s", strerror(-r));
                 return r;
diff --git a/src/journal/journal-gatewayd.c b/src/journal/journal-gatewayd.c
index c51afbf..384137b 100644
--- a/src/journal/journal-gatewayd.c
+++ b/src/journal/journal-gatewayd.c
@@ -746,7 +746,7 @@ static int get_virtualization(char **v) {
         char *b;
         int r;
 
-        r = sd_bus_open_system(&bus);
+        r = sd_bus_default_system(&bus);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index cd9f37e..4f9d941 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -249,6 +249,9 @@ struct sd_bus {
         sd_event *event;
 
         sd_bus_message *current;
+
+        sd_bus **default_bus_ptr;
+        pid_t tid;
 };
 
 #define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index d277e1e..33bdf38 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -944,9 +944,9 @@ int bus_open_transport(BusTransport transport, const char *host, bool user, sd_b
 
         case BUS_TRANSPORT_LOCAL:
                 if (user)
-                        r = sd_bus_open_user(bus);
+                        r = sd_bus_default_user(bus);
                 else
-                        r = sd_bus_open_system(bus);
+                        r = sd_bus_default_system(bus);
 
                 break;
 
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index 796a395..b6ad84b 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -12,6 +12,8 @@ global:
         /* Same order as in sd-bus.h should be used */
 
         /* Connections */
+        sd_bus_default_user;
+        sd_bus_default_system;
         sd_bus_open_user;
         sd_bus_open_system;
         sd_bus_open_system_remote;
@@ -49,6 +51,7 @@ global:
         sd_bus_wait;
         sd_bus_flush;
         sd_bus_get_current;
+        sd_bus_get_tid;
         sd_bus_attach_event;
         sd_bus_detach_event;
         sd_bus_add_filter;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index fdfbbeb..3ecda17 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2370,16 +2370,21 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
         int r;
 
         assert_return(bus, -EINVAL);
-        assert_return(event, -EINVAL);
         assert_return(!bus->event, -EBUSY);
 
         assert(!bus->input_io_event_source);
         assert(!bus->output_io_event_source);
         assert(!bus->time_event_source);
 
-        bus->event = sd_event_ref(event);
+        if (event)
+                bus->event = sd_event_ref(event);
+        else  {
+                r = sd_event_default(&bus->event);
+                if (r < 0)
+                        return r;
+        }
 
-        r = sd_event_add_io(event, bus->input_fd, 0, io_callback, bus, &bus->input_io_event_source);
+        r = sd_event_add_io(bus->event, bus->input_fd, 0, io_callback, bus, &bus->input_io_event_source);
         if (r < 0)
                 goto fail;
 
@@ -2388,7 +2393,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
                 goto fail;
 
         if (bus->output_fd != bus->input_fd) {
-                r = sd_event_add_io(event, bus->output_fd, 0, io_callback, bus, &bus->output_io_event_source);
+                r = sd_event_add_io(bus->event, bus->output_fd, 0, io_callback, bus, &bus->output_io_event_source);
                 if (r < 0)
                         goto fail;
 
@@ -2401,7 +2406,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
         if (r < 0)
                 goto fail;
 
-        r = sd_event_add_monotonic(event, 0, 0, time_callback, bus, &bus->time_event_source);
+        r = sd_event_add_monotonic(bus->event, 0, 0, time_callback, bus, &bus->time_event_source);
         if (r < 0)
                 goto fail;
 
@@ -2409,7 +2414,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
         if (r < 0)
                 goto fail;
 
-        r = sd_event_add_quit(event, quit_callback, bus, &bus->quit_event_source);
+        r = sd_event_add_quit(bus->event, quit_callback, bus, &bus->quit_event_source);
         if (r < 0)
                 goto fail;
 
@@ -2442,8 +2447,63 @@ _public_ int sd_bus_detach_event(sd_bus *bus) {
         return 0;
 }
 
-sd_bus_message* sd_bus_get_current(sd_bus *bus) {
+_public_ sd_bus_message* sd_bus_get_current(sd_bus *bus) {
         assert_return(bus, NULL);
 
         return bus->current;
 }
+
+static int bus_default(int (*bus_open)(sd_bus **), sd_bus **default_bus, sd_bus **ret) {
+        sd_bus *b = NULL;
+        int r;
+
+        assert(bus_open);
+        assert(default_bus);
+
+        if (!ret)
+                return !!*default_bus;
+
+        if (*default_bus) {
+                *ret = sd_bus_ref(*default_bus);
+                return 0;
+        }
+
+        r = bus_open(&b);
+        if (r < 0)
+                return r;
+
+        b->default_bus_ptr = default_bus;
+        b->tid = gettid();
+        *default_bus = b;
+
+        *ret = b;
+        return 1;
+}
+
+_public_ int sd_bus_default_system(sd_bus **ret) {
+        static __thread sd_bus *default_system_bus = NULL;
+
+        return bus_default(sd_bus_open_system, &default_system_bus, ret);
+}
+
+_public_ int sd_bus_default_user(sd_bus **ret) {
+        static __thread sd_bus *default_user_bus = NULL;
+
+        return bus_default(sd_bus_open_user, &default_user_bus, ret);
+}
+
+_public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) {
+        assert_return(b, -EINVAL);
+        assert_return(tid, -EINVAL);
+        assert_return(!bus_pid_changed(b), -ECHILD);
+
+        if (b->tid != 0) {
+                *tid = b->tid;
+                return 0;
+        }
+
+        if (b->event)
+                return sd_event_get_tid(b->event, tid);
+
+        return -ENXIO;
+}
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 8025d24..0996316 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -1906,8 +1906,12 @@ _public_ int sd_event_default(sd_event **ret) {
 _public_ int sd_event_get_tid(sd_event *e, pid_t *tid) {
         assert_return(e, -EINVAL);
         assert_return(tid, -EINVAL);
-        assert_return(e->tid != 0, -ENXIO);
+        assert_return(!event_pid_changed(e), -ECHILD);
 
-        *tid = e->tid;
-        return 0;
+        if (e->tid != 0) {
+                *tid = e->tid;
+                return 0;
+        }
+
+        return -ENXIO;
 }
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 32d52a9..78250d6 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -1061,7 +1061,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
         assert(event);
         assert(_bus);
 
-        r = sd_bus_open_system(&bus);
+        r = sd_bus_default_system(&bus);
         if (r < 0) {
                 log_error("Failed to get system bus connection: %s", strerror(-r));
                 return r;
diff --git a/src/login/inhibit.c b/src/login/inhibit.c
index 10de54b..48c2ec4 100644
--- a/src/login/inhibit.c
+++ b/src/login/inhibit.c
@@ -233,7 +233,7 @@ int main(int argc, char *argv[]) {
         if (r == 0)
                 return EXIT_SUCCESS;
 
-        r = sd_bus_open_system(&bus);
+        r = sd_bus_default_system(&bus);
         if (r < 0) {
                 log_error("Failed to connect to bus: %s", strerror(-r));
                 return EXIT_FAILURE;
diff --git a/src/login/logind.c b/src/login/logind.c
index b54689e..1d16eaa 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -605,7 +605,7 @@ static int manager_connect_bus(Manager *m) {
         assert(m);
         assert(!m->bus);
 
-        r = sd_bus_open_system(&m->bus);
+        r = sd_bus_default_system(&m->bus);
         if (r < 0) {
                 log_error("Failed to connect to system bus: %s", strerror(-r));
                 return r;
diff --git a/src/machine/machined.c b/src/machine/machined.c
index ee6a6d6..01b2caa 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -129,7 +129,7 @@ static int manager_connect_bus(Manager *m) {
         assert(m);
         assert(!m->bus);
 
-        r = sd_bus_open_system(&m->bus);
+        r = sd_bus_default_system(&m->bus);
         if (r < 0) {
                 log_error("Failed to connect to system bus: %s", strerror(-r));
                 return r;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 06d627c..2778cd8 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -965,7 +965,7 @@ static int terminate_machine(pid_t pid) {
         const char *path;
         int r;
 
-        r = sd_bus_open_system(&bus);
+        r = sd_bus_default_system(&bus);
         if (r < 0) {
                 log_error("Failed to open system bus: %s", strerror(-r));
                 return r;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index b31cfaa..ef5984f 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -57,6 +57,9 @@ typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *path, char ***
 
 /* Connections */
 
+int sd_bus_default_user(sd_bus **ret);
+int sd_bus_default_system(sd_bus **ret);
+
 int sd_bus_open_user(sd_bus **ret);
 int sd_bus_open_system(sd_bus **ret);
 int sd_bus_open_system_remote(const char *host, sd_bus **ret);
@@ -101,6 +104,7 @@ int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec);
 int sd_bus_flush(sd_bus *bus);
 
 sd_bus_message* sd_bus_get_current(sd_bus *bus);
+int sd_bus_get_tid(sd_bus *bus, pid_t *tid);
 
 int sd_bus_attach_event(sd_bus *bus, sd_event *e, int priority);
 int sd_bus_detach_event(sd_bus *bus);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 8fb7f6e..0ae93d8 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -795,7 +795,7 @@ static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) {
         assert(event);
         assert(_bus);
 
-        r = sd_bus_open_system(&bus);
+        r = sd_bus_default_system(&bus);
         if (r < 0) {
                 log_error("Failed to get system bus connection: %s", strerror(-r));
                 return r;

commit afc6adb5ec7e73bc13156c43f52fb015cd80cc68
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 19:34:13 2013 +0100

    bus: introduce concept of a "default" event loop per-thread and make use of it everywhere
    
    Try to emphasize a bit that there should be a mapping between event
    loops and threads, hence introduce a logic that there's one "default"
    event loop for each thread, that can be queried via
    "sd_event_default()".

diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 35dccf8..d2f0b02 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -643,7 +643,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = sd_event_new(&event);
+        r = sd_event_default(&event);
         if (r < 0) {
                 log_error("Failed to allocate event loop: %s", strerror(-r));
                 goto finish;
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index 2c4f07d..796a395 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -197,6 +197,8 @@ global:
         sd_memfd_set_size;
 
         /* sd-event functions */
+        sd_event_default;
+
         sd_event_new;
         sd_event_ref;
         sd_event_unref;
@@ -213,15 +215,17 @@ global:
         sd_event_loop;
 
         sd_event_get_state;
+        sd_event_get_tid;
         sd_event_get_quit;
         sd_event_request_quit;
         sd_event_get_now_realtime;
         sd_event_get_now_monotonic;
-        sd_event_get;
 
         sd_event_source_ref;
         sd_event_source_unref;
 
+        sd_event_get;
+
         sd_event_source_set_prepare;
         sd_event_source_get_pending;
         sd_event_source_get_priority;
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 97e6db2..8025d24 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -23,12 +23,13 @@
 #include <sys/timerfd.h>
 #include <sys/wait.h>
 
+#include "sd-id128.h"
 #include "macro.h"
 #include "prioq.h"
 #include "hashmap.h"
 #include "util.h"
 #include "time-util.h"
-#include "sd-id128.h"
+#include "missing.h"
 
 #include "sd-event.h"
 
@@ -138,6 +139,9 @@ struct sd_event {
 
         bool quit_requested:1;
         bool need_process_child:1;
+
+        pid_t tid;
+        sd_event **default_event_ptr;
 };
 
 static int pending_prioq_compare(const void *a, const void *b) {
@@ -304,6 +308,9 @@ static int quit_prioq_compare(const void *a, const void *b) {
 static void event_free(sd_event *e) {
         assert(e);
 
+        if (e->default_event_ptr)
+                *(e->default_event_ptr) = NULL;
+
         if (e->epoll_fd >= 0)
                 close_nointr_nofail(e->epoll_fd);
 
@@ -1869,3 +1876,38 @@ _public_ int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec) {
         *usec = e->timestamp.monotonic;
         return 0;
 }
+
+_public_ int sd_event_default(sd_event **ret) {
+
+        static __thread sd_event *default_event = NULL;
+        sd_event *e;
+        int r;
+
+        if (!ret)
+                return !!default_event;
+
+        if (default_event) {
+                *ret = sd_event_ref(default_event);
+                return 0;
+        }
+
+        r = sd_event_new(&e);
+        if (r < 0)
+                return r;
+
+        e->default_event_ptr = &default_event;
+        e->tid = gettid();
+        default_event = e;
+
+        *ret = e;
+        return 1;
+}
+
+_public_ int sd_event_get_tid(sd_event *e, pid_t *tid) {
+        assert_return(e, -EINVAL);
+        assert_return(tid, -EINVAL);
+        assert_return(e->tid != 0, -ENXIO);
+
+        *tid = e->tid;
+        return 0;
+}
diff --git a/src/libsystemd-bus/test-event.c b/src/libsystemd-bus/test-event.c
index 65c1c29..ba60a47 100644
--- a/src/libsystemd-bus/test-event.c
+++ b/src/libsystemd-bus/test-event.c
@@ -163,7 +163,7 @@ int main(int argc, char *argv[]) {
         assert_se(pipe(b) >= 0);
         assert_se(pipe(d) >= 0);
 
-        assert_se(sd_event_new(&e) >= 0);
+        assert_se(sd_event_default(&e) >= 0);
 
         got_a = false, got_b = false, got_c = false, got_d = 0;
 
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 7e03d82..32d52a9 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -1115,7 +1115,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = sd_event_new(&event);
+        r = sd_event_default(&event);
         if (r < 0) {
                 log_error("Failed to allocate event loop: %s", strerror(-r));
                 goto finish;
diff --git a/src/login/logind.c b/src/login/logind.c
index c4227f1..b54689e 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -90,7 +90,7 @@ Manager *manager_new(void) {
                 return NULL;
         }
 
-        r = sd_event_new(&m->event);
+        r = sd_event_default(&m->event);
         if (r < 0) {
                 manager_free(m);
                 return NULL;
diff --git a/src/machine/machined.c b/src/machine/machined.c
index d6dd984..ee6a6d6 100644
--- a/src/machine/machined.c
+++ b/src/machine/machined.c
@@ -53,7 +53,7 @@ Manager *manager_new(void) {
                 return NULL;
         }
 
-        r = sd_event_new(&m->event);
+        r = sd_event_default(&m->event);
         if (r < 0) {
                 manager_free(m);
                 return NULL;
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c
index 6a57a80..8378e92 100644
--- a/src/network/networkd-manager.c
+++ b/src/network/networkd-manager.c
@@ -31,7 +31,7 @@ int manager_new(Manager **ret) {
         if (!m)
                 return -ENOMEM;
 
-        r = sd_event_new(&m->event);
+        r = sd_event_default(&m->event);
         if (r < 0)
                 return r;
 
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index 56e660d..8cba8e0 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -626,7 +626,7 @@ int main(int argc, char *argv[]) {
         if (r <= 0)
                 goto finish;
 
-        r = sd_event_new(&event);
+        r = sd_event_default(&event);
         if (r < 0) {
                 log_error("Failed to allocate event loop: %s", strerror(-r));
                 goto finish;
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index 8262e13..919b661 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -72,6 +72,8 @@ typedef int (*sd_defer_handler_t)(sd_event_source *s, void *userdata);
 typedef int (*sd_prepare_handler_t)(sd_event_source *s, void *userdata);
 typedef int (*sd_quit_handler_t)(sd_event_source *s, void *userdata);
 
+int sd_event_default(sd_event **e);
+
 int sd_event_new(sd_event **e);
 sd_event* sd_event_ref(sd_event *e);
 sd_event* sd_event_unref(sd_event *e);
@@ -88,15 +90,17 @@ int sd_event_run(sd_event *e, uint64_t timeout);
 int sd_event_loop(sd_event *e);
 
 int sd_event_get_state(sd_event *e);
+int sd_event_get_tid(sd_event *e, pid_t *tid);
 int sd_event_get_quit(sd_event *e);
 int sd_event_request_quit(sd_event *e);
 int sd_event_get_now_realtime(sd_event *e, uint64_t *usec);
 int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec);
-sd_event *sd_event_get(sd_event_source *s);
 
 sd_event_source* sd_event_source_ref(sd_event_source *s);
 sd_event_source* sd_event_source_unref(sd_event_source *s);
 
+sd_event *sd_event_get(sd_event_source *s);
+
 int sd_event_source_set_prepare(sd_event_source *s, sd_prepare_handler_t callback);
 int sd_event_source_get_pending(sd_event_source *s);
 int sd_event_source_get_priority(sd_event_source *s, int *priority);
diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c
index 163b276..8fb7f6e 100644
--- a/src/timedate/timedated.c
+++ b/src/timedate/timedated.c
@@ -854,7 +854,7 @@ int main(int argc, char *argv[]) {
                 goto finish;
         }
 
-        r = sd_event_new(&event);
+        r = sd_event_default(&event);
         if (r < 0) {
                 log_error("Failed to allocate event loop: %s", strerror(-r));
                 goto finish;

commit d5e4ec5b1ee1e3f04a2cb0871490490eb47ef34a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 19:09:02 2013 +0100

    test: fix minor memory leak in test-event

diff --git a/src/libsystemd-bus/test-event.c b/src/libsystemd-bus/test-event.c
index 60194b9..65c1c29 100644
--- a/src/libsystemd-bus/test-event.c
+++ b/src/libsystemd-bus/test-event.c
@@ -219,6 +219,8 @@ int main(int argc, char *argv[]) {
         sd_event_source_unref(z);
         sd_event_source_unref(q);
 
+        sd_event_source_unref(w);
+
         sd_event_unref(e);
 
         close_pipe(a);

commit c49b30a23583ff39daaa26696bcab478d2fee0bb
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 11 18:55:34 2013 +0100

    bus: rename sd_bus_send_with_reply_and_block() to sd_bus_call()
    
    The call is one of the most important ones we expose, where we place
    major emphasis on. We should make sure to give it a short, memorable
    name.

diff --git a/src/libsystemd-bus/bus-convenience.c b/src/libsystemd-bus/bus-convenience.c
index 4dc65b9..9bf2e2c 100644
--- a/src/libsystemd-bus/bus-convenience.c
+++ b/src/libsystemd-bus/bus-convenience.c
@@ -87,7 +87,7 @@ _public_ int sd_bus_call_method(
                         return r;
         }
 
-        return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
+        return sd_bus_call(bus, m, 0, error, reply);
 }
 
 _public_ int sd_bus_reply_method_return(
@@ -422,5 +422,5 @@ _public_ int sd_bus_set_property(
         if (r < 0)
                 return r;
 
-        return sd_bus_send_with_reply_and_block(bus, m, 0, error, NULL);
+        return sd_bus_call(bus, m, 0, error, NULL);
 }
diff --git a/src/libsystemd-bus/bus-util.c b/src/libsystemd-bus/bus-util.c
index e92c318..d277e1e 100644
--- a/src/libsystemd-bus/bus-util.c
+++ b/src/libsystemd-bus/bus-util.c
@@ -236,7 +236,7 @@ static void async_polkit_query_free(sd_bus *b, AsyncPolkitQuery *q) {
                 return;
 
         if (q->serial >  0 && b)
-                sd_bus_send_with_reply_cancel(b, q->serial);
+                sd_bus_call_async_cancel(b, q->serial);
 
         sd_bus_message_unref(q->request);
         sd_bus_message_unref(q->reply);
@@ -362,7 +362,7 @@ int bus_verify_polkit_async(
                 return r;
         }
 
-        r = sd_bus_send_with_reply(bus, pk, async_polkit_callback, q, 0, &q->serial);
+        r = sd_bus_call_async(bus, pk, async_polkit_callback, q, 0, &q->serial);
         if (r < 0)
                 return r;
 
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index fceab50..fdfbbeb 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -396,7 +396,7 @@ static int bus_send_hello(sd_bus *bus) {
         if (r < 0)
                 return r;
 
-        return sd_bus_send_with_reply(bus, m, hello_callback, NULL, 0, &bus->hello_serial);
+        return sd_bus_call_async(bus, m, hello_callback, NULL, 0, &bus->hello_serial);
 }
 
 int bus_start_running(sd_bus *bus) {
@@ -1440,7 +1440,7 @@ static int timeout_compare(const void *a, const void *b) {
         return 0;
 }
 
-_public_ int sd_bus_send_with_reply(
+_public_ int sd_bus_call_async(
                 sd_bus *bus,
                 sd_bus_message *m,
                 sd_bus_message_handler_t callback,
@@ -1492,21 +1492,21 @@ _public_ int sd_bus_send_with_reply(
                 r = prioq_put(bus->reply_callbacks_prioq, c, &c->prioq_idx);
                 if (r < 0) {
                         c->timeout = 0;
-                        sd_bus_send_with_reply_cancel(bus, c->serial);
+                        sd_bus_call_async_cancel(bus, c->serial);
                         return r;
                 }
         }
 
         r = sd_bus_send(bus, m, serial);
         if (r < 0) {
-                sd_bus_send_with_reply_cancel(bus, c->serial);
+                sd_bus_call_async_cancel(bus, c->serial);
                 return r;
         }
 
         return r;
 }
 
-_public_ int sd_bus_send_with_reply_cancel(sd_bus *bus, uint64_t serial) {
+_public_ int sd_bus_call_async_cancel(sd_bus *bus, uint64_t serial) {
         struct reply_callback *c;
 
         assert_return(bus, -EINVAL);
@@ -1549,7 +1549,7 @@ int bus_ensure_running(sd_bus *bus) {
         }
 }
 
-_public_ int sd_bus_send_with_reply_and_block(
+_public_ int sd_bus_call(
                 sd_bus *bus,
                 sd_bus_message *m,
                 uint64_t usec,
diff --git a/src/libsystemd-bus/test-bus-chat.c b/src/libsystemd-bus/test-bus-chat.c
index a29fbdf..67411f1 100644
--- a/src/libsystemd-bus/test-bus-chat.c
+++ b/src/libsystemd-bus/test-bus-chat.c
@@ -437,7 +437,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        r = sd_bus_send_with_reply_and_block(bus, m, 0, &error, &reply);
+        r = sd_bus_call(bus, m, 0, &error, &reply);
         if (r < 0) {
                 log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
                 goto finish;
@@ -469,7 +469,7 @@ static void* client2(void*p) {
         sd_bus_message_unref(reply);
         reply = NULL;
 
-        r = sd_bus_send_with_reply_and_block(bus, m, 200 * USEC_PER_MSEC, &error, &reply);
+        r = sd_bus_call(bus, m, 200 * USEC_PER_MSEC, &error, &reply);
         if (r < 0)
                 log_info("Failed to issue method call: %s", bus_error_message(&error, -r));
         else
@@ -490,7 +490,7 @@ static void* client2(void*p) {
                 goto finish;
         }
 
-        r = sd_bus_send_with_reply(bus, m, quit_callback, &quit, 200 * USEC_PER_MSEC, NULL);
+        r = sd_bus_call_async(bus, m, quit_callback, &quit, 200 * USEC_PER_MSEC, NULL);
         if (r < 0) {
                 log_info("Failed to issue method call: %s", bus_error_message(&error, -r));
                 goto finish;
diff --git a/src/libsystemd-bus/test-bus-kernel-benchmark.c b/src/libsystemd-bus/test-bus-kernel-benchmark.c
index 666c74c..18b08ed 100644
--- a/src/libsystemd-bus/test-bus-kernel-benchmark.c
+++ b/src/libsystemd-bus/test-bus-kernel-benchmark.c
@@ -82,7 +82,7 @@ static void transaction(sd_bus *b, size_t sz) {
 
         memset(p, 0x80, sz);
 
-        assert_se(sd_bus_send_with_reply_and_block(b, m, 0, NULL, &reply) >= 0);
+        assert_se(sd_bus_call(b, m, 0, NULL, &reply) >= 0);
 }
 
 static void client_bisect(const char *address) {
diff --git a/src/libsystemd-bus/test-bus-server.c b/src/libsystemd-bus/test-bus-server.c
index 478a81e..a9db1f4 100644
--- a/src/libsystemd-bus/test-bus-server.c
+++ b/src/libsystemd-bus/test-bus-server.c
@@ -151,7 +151,7 @@ static int client(struct context *c) {
                 return r;
         }
 
-        r = sd_bus_send_with_reply_and_block(bus, m, 0, &error, &reply);
+        r = sd_bus_call(bus, m, 0, &error, &reply);
         if (r < 0) {
                 log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
                 return r;
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index ed66668..d8dd66a 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -164,7 +164,7 @@ static int set_locale(sd_bus *bus, char **args, unsigned n) {
         if (r < 0)
                 return bus_log_create_error(r);
 
-        r = sd_bus_send_with_reply_and_block(bus, m, 0, &error, NULL);
+        r = sd_bus_call(bus, m, 0, &error, NULL);
         if (r < 0) {
                 log_error("Failed to issue method call: %s", bus_error_message(&error, -r));
                 return r;
diff --git a/src/locale/localed.c b/src/locale/localed.c
index 744d304..7e03d82 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -382,7 +382,7 @@ static int locale_update_system_manager(Context *c, sd_bus *bus) {
         if (r < 0)
                 return r;
 
-        r = sd_bus_send_with_reply_and_block(bus, m, 0, &error, NULL);
+        r = sd_bus_call(bus, m, 0, &error, NULL);
         if (r < 0)
                 log_error("Failed to update the manager environment: %s", strerror(-r));
 
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index 7e22b84..0f25e23 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -2216,7 +2216,7 @@ int manager_start_scope(
         if (r < 0)
                 return r;
 
-        r = sd_bus_send_with_reply_and_block(manager->bus, m, 0, error, &reply);
+        r = sd_bus_call(manager->bus, m, 0, error, &reply);
         if (r < 0)
                 return r;
 
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 71f9853..2b25f07 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -529,7 +529,7 @@ int manager_start_scope(
         if (r < 0)
                 return r;
 
-        r = sd_bus_send_with_reply_and_block(manager->bus, m, 0, error, &reply);
+        r = sd_bus_call(manager->bus, m, 0, error, &reply);
         if (r < 0)
                 return r;
 
diff --git a/src/run/run.c b/src/run/run.c
index 1eeb5c6..539db6f 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -237,7 +237,7 @@ static int message_start_transient_unit_send(sd_bus *bus, sd_bus_message *m, sd_
         if (r < 0)
                 return r;
 
-        return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
+        return sd_bus_call(bus, m, 0, error, reply);
 }
 
 static int start_transient_service(
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 0e833ab..8b6dae2 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -3845,7 +3845,7 @@ static int set_property(sd_bus *bus, char **args) {
         if (r < 0)
                 return bus_log_create_error(r);
 
-        r = sd_bus_send_with_reply_and_block(bus, m, -1, &error, NULL);
+        r = sd_bus_call(bus, m, 0, &error, NULL);
         if (r < 0) {
                 log_error("Failed to set unit properties on %s: %s", n, bus_error_message(&error, r));
                 return r;
@@ -4132,7 +4132,7 @@ static int set_environment(sd_bus *bus, char **args) {
         if (r < 0)
                 return bus_log_create_error(r);
 
-        r = sd_bus_send_with_reply_and_block(bus, m, -1, &error, NULL);
+        r = sd_bus_call(bus, m, 0, &error, NULL);
         if (r < 0) {
                 log_error("Failed to set environment: %s", bus_error_message(&error, r));
                 return r;
@@ -4443,7 +4443,7 @@ static int enable_unit(sd_bus *bus, char **args) {
                                 return bus_log_create_error(r);
                 }
 
-                r = sd_bus_send_with_reply_and_block(bus, m, -0, &error, &reply);
+                r = sd_bus_call(bus, m, 0, &error, &reply);
                 if (r < 0) {
                         log_error("Failed to execute operation: %s", bus_error_message(&error, r));
                         return r;
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 6202acb..b31cfaa 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -89,9 +89,9 @@ int sd_bus_can_send(sd_bus *bus, char type);
 int sd_bus_get_server_id(sd_bus *bus, sd_id128_t *peer);
 
 int sd_bus_send(sd_bus *bus, sd_bus_message *m, uint64_t *serial);
-int sd_bus_send_with_reply(sd_bus *bus, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec, uint64_t *serial);
-int sd_bus_send_with_reply_cancel(sd_bus *bus, uint64_t serial);
-int sd_bus_send_with_reply_and_block(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *error, sd_bus_message **r);
+int sd_bus_call(sd_bus *bus, sd_bus_message *m, uint64_t usec, sd_bus_error *error, sd_bus_message **reply);
+int sd_bus_call_async(sd_bus *bus, sd_bus_message *m, sd_bus_message_handler_t callback, void *userdata, uint64_t usec, uint64_t *serial);
+int sd_bus_call_async_cancel(sd_bus *bus, uint64_t serial);
 
 int sd_bus_get_fd(sd_bus *bus);
 int sd_bus_get_events(sd_bus *bus);



More information about the systemd-commits mailing list