[systemd-commits] 4 commits - TODO src/core src/libsystemd-bus src/login src/machine src/socket-proxy src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Thu Nov 21 16:57:46 PST 2013


 TODO                                  |    2 
 src/core/dbus.c                       |   77 ++++++++--------
 src/libsystemd-bus/bus-message.c      |    6 +
 src/libsystemd-bus/bus-objects.c      |  162 ++++++++++++++++------------------
 src/libsystemd-bus/libsystemd-bus.sym |    5 -
 src/libsystemd-bus/sd-bus.c           |    6 +
 src/libsystemd-bus/sd-event.c         |    2 
 src/libsystemd-bus/test-bus-objects.c |    2 
 src/libsystemd-bus/test-event.c       |    8 -
 src/login/logind-seat-dbus.c          |    4 
 src/login/logind-seat.h               |    4 
 src/login/logind-session-dbus.c       |    4 
 src/login/logind-session.h            |    4 
 src/login/logind-user-dbus.c          |    4 
 src/login/logind-user.h               |    4 
 src/machine/machine-dbus.c            |    4 
 src/machine/machine.h                 |    3 
 src/machine/machined.h                |    2 
 src/socket-proxy/socket-proxyd.c      |    6 -
 src/systemd/sd-bus.h                  |    7 +
 src/systemd/sd-event.h                |    3 
 21 files changed, 167 insertions(+), 152 deletions(-)

New commits:
commit 52c7f2b2d58394c791ea0c6cf706082fd418f5bc
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Nov 22 01:51:19 2013 +0100

    bus: deal with duplicate values from enumerators

diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c
index 7c8a774..659f7ce 100644
--- a/src/libsystemd-bus/bus-objects.c
+++ b/src/libsystemd-bus/bus-objects.c
@@ -135,6 +135,8 @@ static int add_enumerated_to_set(
                         }
 
                         r = set_consume(s, *k);
+                        if (r == -EEXIST)
+                                r = 0;
                 }
 
                 free(children);

commit adcc4ca30dc8ca0cddfcab64ad2eab6f6ab6fe21
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Nov 22 01:28:45 2013 +0100

    event: rename sd_event_get() to sd_event_source_get_event()

diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index f8c60b4..9cf06c4 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -235,8 +235,6 @@ global:
         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;
@@ -254,6 +252,7 @@ global:
         sd_event_source_get_time_accuracy;
         sd_event_source_get_signal;
         sd_event_source_get_child_pid;
+        sd_event_source_get_event;
 
         /* sd-utf8 function */
         sd_utf8_is_valid;
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 2a8eac6..6a6581b 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -984,7 +984,7 @@ _public_ sd_event_source* sd_event_source_unref(sd_event_source *s) {
         return NULL;
 }
 
-_public_ sd_event *sd_event_get(sd_event_source *s) {
+_public_ sd_event *sd_event_source_get_event(sd_event_source *s) {
         assert_return(s, NULL);
 
         return s->event;
diff --git a/src/libsystemd-bus/test-event.c b/src/libsystemd-bus/test-event.c
index ba60a47..5360d87 100644
--- a/src/libsystemd-bus/test-event.c
+++ b/src/libsystemd-bus/test-event.c
@@ -63,7 +63,7 @@ static int child_handler(sd_event_source *s, const siginfo_t *si, void *userdata
 
         assert(userdata == INT_TO_PTR('f'));
 
-        assert_se(sd_event_request_quit(sd_event_get(s)) >= 0);
+        assert_se(sd_event_request_quit(sd_event_source_get_event(s)) >= 0);
         sd_event_source_unref(s);
 
         return 1;
@@ -91,7 +91,7 @@ static int signal_handler(sd_event_source *s, const struct signalfd_siginfo *si,
         if (pid == 0)
                 _exit(0);
 
-        assert_se(sd_event_add_child(sd_event_get(s), pid, WEXITED, child_handler, INT_TO_PTR('f'), &p) >= 0);
+        assert_se(sd_event_add_child(sd_event_source_get_event(s), pid, WEXITED, child_handler, INT_TO_PTR('f'), &p) >= 0);
         assert_se(sd_event_source_set_enabled(p, SD_EVENT_ONESHOT) >= 0);
 
         sd_event_source_unref(s);
@@ -112,7 +112,7 @@ static int defer_handler(sd_event_source *s, void *userdata) {
         assert_se(sigemptyset(&ss) >= 0);
         assert_se(sigaddset(&ss, SIGUSR1) >= 0);
         assert_se(sigprocmask(SIG_BLOCK, &ss, NULL) >= 0);
-        assert_se(sd_event_add_signal(sd_event_get(s), SIGUSR1, signal_handler, INT_TO_PTR('e'), &p) >= 0);
+        assert_se(sd_event_add_signal(sd_event_source_get_event(s), SIGUSR1, signal_handler, INT_TO_PTR('e'), &p) >= 0);
         assert_se(sd_event_source_set_enabled(p, SD_EVENT_ONESHOT) >= 0);
         raise(SIGUSR1);
 
@@ -131,7 +131,7 @@ static int time_handler(sd_event_source *s, uint64_t usec, void *userdata) {
                 if (do_quit) {
                         sd_event_source *p;
 
-                        assert_se(sd_event_add_defer(sd_event_get(s), defer_handler, INT_TO_PTR('d'), &p) >= 0);
+                        assert_se(sd_event_add_defer(sd_event_source_get_event(s), defer_handler, INT_TO_PTR('d'), &p) >= 0);
                         assert_se(sd_event_source_set_enabled(p, SD_EVENT_ONESHOT) >= 0);
                 } else {
                         assert(!got_c);
diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c
index 8cba8e0..432558d 100644
--- a/src/socket-proxy/socket-proxyd.c
+++ b/src/socket-proxy/socket-proxyd.c
@@ -287,7 +287,7 @@ static int traffic_cb(sd_event_source *s, int fd, uint32_t revents, void *userda
         if (c->client_fd == -1 && c->client_to_server_buffer_full <= 0)
                 goto quit;
 
-        r = connection_enable_event_sources(c, sd_event_get(s));
+        r = connection_enable_event_sources(c, sd_event_source_get_event(s));
         if (r < 0)
                 goto quit;
 
@@ -373,7 +373,7 @@ static int connect_cb(sd_event_source *s, int fd, uint32_t revents, void *userda
         if (r < 0)
                 goto fail;
 
-        r = connection_enable_event_sources(c, sd_event_get(s));
+        r = connection_enable_event_sources(c, sd_event_source_get_event(s));
         if (r < 0)
                 goto fail;
 
@@ -477,7 +477,7 @@ static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdat
                 getpeername_pretty(nfd, &peer);
                 log_debug("New connection from %s", strna(peer));
 
-                r = add_connection_socket(context, sd_event_get(s), nfd);
+                r = add_connection_socket(context, sd_event_source_get_event(s), nfd);
                 if (r < 0) {
                         close_nointr_nofail(fd);
                         return r;
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index e7b6c9e..63b223c 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -97,8 +97,6 @@ int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec);
 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_event_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);
@@ -116,6 +114,7 @@ int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec);
 int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec);
 int sd_event_source_get_signal(sd_event_source *s);
 int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid);
+sd_event *sd_event_source_get_event(sd_event_source *s);
 
 _SD_END_DECLARATIONS;
 

commit 2be441769f29578764835df58950ac939f4e29eb
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Nov 22 01:21:59 2013 +0100

    bus: add calls to query attached objects

diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index a0e4e2c..538a28a 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -4468,3 +4468,9 @@ _public_ int sd_bus_message_verify_type(sd_bus_message *m, char type, const char
 
         return 1;
 }
+
+_public_ sd_bus *sd_bus_message_get_bus(sd_bus_message *m) {
+        assert_return(m, NULL);
+
+        return m->bus;
+}
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index a8df513..f8c60b4 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -54,6 +54,7 @@ global:
         sd_bus_get_tid;
         sd_bus_attach_event;
         sd_bus_detach_event;
+        sd_bus_get_event;
         sd_bus_add_filter;
         sd_bus_remove_filter;
         sd_bus_add_match;
@@ -94,6 +95,7 @@ global:
         sd_bus_message_get_sender;
         sd_bus_message_get_error;
         sd_bus_message_get_errno;
+        sd_bus_message_get_bus;
         sd_bus_message_get_monotonic_timestamp;
         sd_bus_message_get_realtime_timestamp;
         sd_bus_message_get_uid;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 4df649c..85d1154 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2658,6 +2658,12 @@ _public_ int sd_bus_detach_event(sd_bus *bus) {
         return 0;
 }
 
+_public_ sd_event* sd_bus_get_event(sd_bus *bus) {
+        assert_return(bus, NULL);
+
+        return bus->event;
+}
+
 _public_ sd_bus_message* sd_bus_get_current(sd_bus *bus) {
         assert_return(bus, NULL);
 
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 8954e38..9c001b1 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -111,6 +111,7 @@ 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);
+sd_event *sd_bus_get_event(sd_bus *bus);
 
 int sd_bus_add_filter(sd_bus *bus, sd_bus_message_handler_t callback, void *userdata);
 int sd_bus_remove_filter(sd_bus *bus, sd_bus_message_handler_t callback, void *userdata);
@@ -163,6 +164,8 @@ const char *sd_bus_message_get_sender(sd_bus_message *m);
 const sd_bus_error *sd_bus_message_get_error(sd_bus_message *m);
 int sd_bus_message_get_errno(sd_bus_message *m);
 
+sd_bus* sd_bus_message_get_bus(sd_bus_message *m);
+
 int sd_bus_message_get_monotonic_timestamp(sd_bus_message *m, uint64_t *usec);
 int sd_bus_message_get_realtime_timestamp(sd_bus_message *m, uint64_t *usec);
 int sd_bus_message_get_uid(sd_bus_message *m, uid_t *uid);

commit f00c31213a2e521680c2381ef231f05e30c874a7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Nov 22 01:14:57 2013 +0100

    bus: also add error parameter to object find and enumerator callbacks
    
    Just in order to bring things inline with the method and property
    callbacks.

diff --git a/TODO b/TODO
index 6805fd6..8acc879 100644
--- a/TODO
+++ b/TODO
@@ -43,6 +43,8 @@ CGroup Rework Completion:
 
 Features:
 
+* bus: translate all EIO, EINVAL, .. errors into dbus error 1:1 and back.
+
 * add API to clone sd_bus_message objects
 
 * sd-bus: synthesized messages should get serial number (uint32_t) -1
diff --git a/src/core/dbus.c b/src/core/dbus.c
index 1cb4d0f..d130e09 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -272,7 +272,7 @@ static int selinux_filter(sd_bus *bus, sd_bus_message *message, void *userdata,
         return 0;
 }
 
-static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_job_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         Job *j;
         int r;
@@ -291,7 +291,7 @@ static int bus_job_find(sd_bus *bus, const char *path, const char *interface, vo
         return 1;
 }
 
-static Unit *find_unit(Manager *m, sd_bus *bus, const char *path) {
+static int find_unit(Manager *m, sd_bus *bus, const char *path, Unit **unit, sd_bus_error *error) {
         Unit *u;
         int r;
 
@@ -305,25 +305,28 @@ static Unit *find_unit(Manager *m, sd_bus *bus, const char *path) {
 
                 message = sd_bus_get_current(bus);
                 if (!message)
-                        return NULL;
+                        return 0;
 
                 r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
                 if (r < 0)
-                        return NULL;
+                        return 0;
 
                 u = manager_get_unit_by_pid(m, pid);
         } else {
-                r = manager_load_unit_from_dbus_path(m, path, NULL, &u);
+                r = manager_load_unit_from_dbus_path(m, path, error, &u);
                 if (r < 0)
-                        return NULL;
+                        return 0;
         }
 
-        return u;
+        if (!u)
+                return 0;
+
+        *unit = u;
+        return 1;
 }
 
-static int bus_unit_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_unit_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
-        Unit *u;
 
         assert(bus);
         assert(path);
@@ -331,17 +334,13 @@ static int bus_unit_find(sd_bus *bus, const char *path, const char *interface, v
         assert(found);
         assert(m);
 
-        u = find_unit(m, bus, path);
-        if (!u)
-                return 0;
-
-        *found = u;
-        return 1;
+        return find_unit(m, bus, path, (Unit**) found, error);
 }
 
-static int bus_unit_interface_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_unit_interface_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         Unit *u;
+        int r;
 
         assert(bus);
         assert(path);
@@ -349,9 +348,9 @@ static int bus_unit_interface_find(sd_bus *bus, const char *path, const char *in
         assert(found);
         assert(m);
 
-        u = find_unit(m, bus, path);
-        if (!u)
-                return 0;
+        r = find_unit(m, bus, path, &u, error);
+        if (r <= 0)
+                return r;
 
         if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
                 return 0;
@@ -360,9 +359,10 @@ static int bus_unit_interface_find(sd_bus *bus, const char *path, const char *in
         return 1;
 }
 
-static int bus_unit_cgroup_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_unit_cgroup_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         Unit *u;
+        int r;
 
         assert(bus);
         assert(path);
@@ -370,9 +370,9 @@ static int bus_unit_cgroup_find(sd_bus *bus, const char *path, const char *inter
         assert(found);
         assert(m);
 
-        u = find_unit(m, bus, path);
-        if (!u)
-                return 0;
+        r = find_unit(m, bus, path, &u, error);
+        if (r <= 0)
+                return r;
 
         if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
                 return 0;
@@ -384,10 +384,11 @@ static int bus_unit_cgroup_find(sd_bus *bus, const char *path, const char *inter
         return 1;
 }
 
-static int bus_cgroup_context_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_cgroup_context_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         CGroupContext *c;
         Unit *u;
+        int r;
 
         assert(bus);
         assert(path);
@@ -395,9 +396,9 @@ static int bus_cgroup_context_find(sd_bus *bus, const char *path, const char *in
         assert(found);
         assert(m);
 
-        u = find_unit(m, bus, path);
-        if (!u)
-                return 0;
+        r = find_unit(m, bus, path, &u, error);
+        if (r <= 0)
+                return r;
 
         if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
                 return 0;
@@ -410,10 +411,11 @@ static int bus_cgroup_context_find(sd_bus *bus, const char *path, const char *in
         return 1;
 }
 
-static int bus_exec_context_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_exec_context_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         ExecContext *c;
         Unit *u;
+        int r;
 
         assert(bus);
         assert(path);
@@ -421,9 +423,9 @@ static int bus_exec_context_find(sd_bus *bus, const char *path, const char *inte
         assert(found);
         assert(m);
 
-        u = find_unit(m, bus, path);
-        if (!u)
-                return 0;
+        r = find_unit(m, bus, path, &u, error);
+        if (r <= 0)
+                return r;
 
         if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
                 return 0;
@@ -436,10 +438,11 @@ static int bus_exec_context_find(sd_bus *bus, const char *path, const char *inte
         return 1;
 }
 
-static int bus_kill_context_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+static int bus_kill_context_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         KillContext *c;
         Unit *u;
+        int r;
 
         assert(bus);
         assert(path);
@@ -447,9 +450,9 @@ static int bus_kill_context_find(sd_bus *bus, const char *path, const char *inte
         assert(found);
         assert(m);
 
-        u = find_unit(m, bus, path);
-        if (!u)
-                return 0;
+        r = find_unit(m, bus, path, &u, error);
+        if (r <= 0)
+                return r;
 
         if (!streq_ptr(interface, UNIT_VTABLE(u)->bus_interface))
                 return 0;
@@ -462,7 +465,7 @@ static int bus_kill_context_find(sd_bus *bus, const char *path, const char *inte
         return 1;
 }
 
-static int bus_job_enumerate(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+static int bus_job_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
         _cleanup_free_ char **l = NULL;
         Manager *m = userdata;
         unsigned k = 0;
@@ -489,7 +492,7 @@ static int bus_job_enumerate(sd_bus *bus, const char *path, char ***nodes, void
         return k;
 }
 
-static int bus_unit_enumerate(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+static int bus_unit_enumerate(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
         _cleanup_free_ char **l = NULL;
         Manager *m = userdata;
         unsigned k = 0;
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c
index 06be5ed..7c8a774 100644
--- a/src/libsystemd-bus/bus-objects.c
+++ b/src/libsystemd-bus/bus-objects.c
@@ -33,7 +33,8 @@ static int node_vtable_get_userdata(
                 sd_bus *bus,
                 const char *path,
                 struct node_vtable *c,
-                void **userdata) {
+                void **userdata,
+                sd_bus_error *error) {
 
         void *u;
         int r;
@@ -44,8 +45,12 @@ static int node_vtable_get_userdata(
 
         u = c->userdata;
         if (c->find) {
-                r = c->find(bus, path, c->interface, &u, u);
-                if (r <= 0)
+                r = c->find(bus, path, c->interface, u, &u, error);
+                if (r < 0)
+                        return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
+                if (r == 0)
                         return r;
         }
 
@@ -65,7 +70,8 @@ static int vtable_property_get_userdata(
                 sd_bus *bus,
                 const char *path,
                 struct vtable_member *p,
-                void **userdata) {
+                void **userdata,
+                sd_bus_error *error) {
 
         void *u;
         int r;
@@ -75,7 +81,7 @@ static int vtable_property_get_userdata(
         assert(p);
         assert(userdata);
 
-        r = node_vtable_get_userdata(bus, path, p->parent, &u);
+        r = node_vtable_get_userdata(bus, path, p->parent, &u, error);
         if (r <= 0)
                 return r;
         if (bus->nodes_modified)
@@ -89,7 +95,8 @@ static int add_enumerated_to_set(
                 sd_bus *bus,
                 const char *prefix,
                 struct node_enumerator *first,
-                Set *s) {
+                Set *s,
+                sd_bus_error *error) {
 
         struct node_enumerator *c;
         int r;
@@ -104,9 +111,11 @@ static int add_enumerated_to_set(
                 if (bus->nodes_modified)
                         return 0;
 
-                r = c->callback(bus, prefix, &children, c->userdata);
+                r = c->callback(bus, prefix, c->userdata, &children, error);
                 if (r < 0)
                         return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
 
                 STRV_FOREACH(k, children) {
                         if (r < 0) {
@@ -140,7 +149,8 @@ static int add_subtree_to_set(
                 sd_bus *bus,
                 const char *prefix,
                 struct node *n,
-                Set *s) {
+                Set *s,
+                sd_bus_error *error) {
 
         struct node *i;
         int r;
@@ -150,7 +160,7 @@ static int add_subtree_to_set(
         assert(n);
         assert(s);
 
-        r = add_enumerated_to_set(bus, prefix, n->enumerators, s);
+        r = add_enumerated_to_set(bus, prefix, n->enumerators, s, error);
         if (r < 0)
                 return r;
         if (bus->nodes_modified)
@@ -170,7 +180,7 @@ static int add_subtree_to_set(
                 if (r < 0 && r != -EEXIST)
                         return r;
 
-                r = add_subtree_to_set(bus, prefix, i, s);
+                r = add_subtree_to_set(bus, prefix, i, s, error);
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
@@ -184,7 +194,8 @@ static int get_child_nodes(
                 sd_bus *bus,
                 const char *prefix,
                 struct node *n,
-                Set **_s) {
+                Set **_s,
+                sd_bus_error *error) {
 
         Set *s = NULL;
         int r;
@@ -198,7 +209,7 @@ static int get_child_nodes(
         if (!s)
                 return -ENOMEM;
 
-        r = add_subtree_to_set(bus, prefix, n, s);
+        r = add_subtree_to_set(bus, prefix, n, s, error);
         if (r < 0) {
                 set_free_free(s);
                 return r;
@@ -258,6 +269,7 @@ static int method_callbacks_run(
                 bool require_fallback,
                 bool *found_object) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         const char *signature;
         void *u;
         int r;
@@ -270,9 +282,9 @@ static int method_callbacks_run(
         if (require_fallback && !c->parent->is_fallback)
                 return 0;
 
-        r = node_vtable_get_userdata(bus, m->path, c->parent, &u);
+        r = node_vtable_get_userdata(bus, m->path, c->parent, &u, &error);
         if (r <= 0)
-                return r;
+                return bus_maybe_reply_error(m, r, &error);
         if (bus->nodes_modified)
                 return 0;
 
@@ -291,20 +303,16 @@ static int method_callbacks_run(
         if (!signature)
                 return -EINVAL;
 
-        if (!streq(strempty(c->vtable->x.method.signature), signature)) {
+        if (!streq(strempty(c->vtable->x.method.signature), signature))
                 return sd_bus_reply_method_errorf(
                                 m,
                                 SD_BUS_ERROR_INVALID_ARGS,
                                 "Invalid arguments '%s' to call %s.%s(), expecting '%s'.",
                                 signature, c->interface, c->member, strempty(c->vtable->x.method.signature));
-        }
 
         if (c->vtable->x.method.handler) {
-                _cleanup_bus_error_free_ sd_bus_error error_buffer = SD_BUS_ERROR_NULL;
-
-                r = c->vtable->x.method.handler(bus, m, u, &error_buffer);
-
-                return bus_maybe_reply_error(m, r, &error_buffer);
+                r = c->vtable->x.method.handler(bus, m, u, &error);
+                return bus_maybe_reply_error(m, r, &error);
         }
 
         /* If the method callback is NULL, make this a successful NOP */
@@ -326,6 +334,7 @@ static int invoke_property_get(
                 sd_bus_error *error) {
 
         const void *p;
+        int r;
 
         assert(bus);
         assert(v);
@@ -334,8 +343,14 @@ static int invoke_property_get(
         assert(property);
         assert(reply);
 
-        if (v->x.property.get)
-                return v->x.property.get(bus, path, interface, property, reply, userdata, error);
+        if (v->x.property.get) {
+                r = v->x.property.get(bus, path, interface, property, reply, userdata, error);
+                if (r < 0)
+                        return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
+                return r;
+        }
 
         /* Automatic handling if no callback is defined. */
 
@@ -384,8 +399,14 @@ static int invoke_property_set(
         assert(property);
         assert(value);
 
-        if (v->x.property.set)
-                return v->x.property.set(bus, path, interface, property, value, userdata, error);
+        if (v->x.property.set) {
+                r = v->x.property.set(bus, path, interface, property, value, userdata, error);
+                if (r < 0)
+                        return r;
+                if (sd_bus_error_is_set(error))
+                        return sd_bus_error_get_errno(error);
+                return r;
+        }
 
         /*  Automatic handling if no callback is defined. */
 
@@ -446,9 +467,9 @@ static int property_get_set_callbacks_run(
         if (require_fallback && !c->parent->is_fallback)
                 return 0;
 
-        r = vtable_property_get_userdata(bus, m->path, c, &u);
+        r = vtable_property_get_userdata(bus, m->path, c, &u, &error);
         if (r <= 0)
-                return r;
+                return bus_maybe_reply_error(m, r, &error);
         if (bus->nodes_modified)
                 return 0;
 
@@ -472,9 +493,7 @@ static int property_get_set_callbacks_run(
 
                 r = invoke_property_get(bus, c->vtable, m->path, c->interface, c->member, reply, u, &error);
                 if (r < 0)
-                        return sd_bus_reply_method_errno(m, r, &error);
-                if (sd_bus_error_is_set(&error))
-                        return sd_bus_reply_method_error(m, &error);
+                        return bus_maybe_reply_error(m, r, &error);
 
                 if (bus->nodes_modified)
                         return 0;
@@ -501,9 +520,7 @@ static int property_get_set_callbacks_run(
 
                 r = invoke_property_set(bus, c->vtable, m->path, c->interface, c->member, m, u, &error);
                 if (r < 0)
-                        return sd_bus_reply_method_errno(m, r, &error);
-                if (sd_bus_error_is_set(&error))
-                        return sd_bus_reply_method_error(m, &error);
+                        return bus_maybe_reply_error(m, r, &error);
 
                 if (bus->nodes_modified)
                         return 0;
@@ -553,12 +570,8 @@ static int vtable_append_all_properties(
                         return r;
 
                 r = invoke_property_get(bus, v, path, c->interface, v->x.property.member, reply, vtable_property_convert_userdata(v, userdata), error);
-                if (sd_bus_error_is_set(error))
-                        return 0;
-                if (r < 0) {
-                        sd_bus_error_set_errno(error, r);
-                        return 0;
-                }
+                if (r < 0)
+                        return r;
                 if (bus->nodes_modified)
                         return 0;
 
@@ -611,9 +624,9 @@ static int property_get_all_callbacks_run(
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, m->path, c, &u);
+                r = node_vtable_get_userdata(bus, m->path, c, &u, &error);
                 if (r < 0)
-                        return r;
+                        return bus_maybe_reply_error(m, r, &error);
                 if (bus->nodes_modified)
                         return 0;
                 if (r == 0)
@@ -627,15 +640,7 @@ static int property_get_all_callbacks_run(
 
                 r = vtable_append_all_properties(bus, reply, m->path, c, u, &error);
                 if (r < 0)
-                        return r;
-
-                if (sd_bus_error_is_set(&error)) {
-                        r = sd_bus_reply_method_error(m, &error);
-                        if (r < 0)
-                                return r;
-
-                        return 1;
-                }
+                        return bus_maybe_reply_error(m, r, &error);
                 if (bus->nodes_modified)
                         return 0;
         }
@@ -699,11 +704,12 @@ static bool bus_node_exists(
         }
 
         LIST_FOREACH(vtables, c, n->vtables) {
+                _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
 
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                if (node_vtable_get_userdata(bus, path, c, NULL) > 0)
+                if (node_vtable_get_userdata(bus, path, c, NULL, &error) > 0)
                         return true;
                 if (bus->nodes_modified)
                         return false;
@@ -719,6 +725,7 @@ static int process_introspect(
                 bool require_fallback,
                 bool *found_object) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_set_free_free_ Set *s = NULL;
         const char *previous_interface = NULL;
@@ -732,9 +739,9 @@ static int process_introspect(
         assert(n);
         assert(found_object);
 
-        r = get_child_nodes(bus, m->path, n, &s);
+        r = get_child_nodes(bus, m->path, n, &s, &error);
         if (r < 0)
-                return r;
+                return bus_maybe_reply_error(m, r, &error);
         if (bus->nodes_modified)
                 return 0;
 
@@ -752,11 +759,15 @@ static int process_introspect(
                 if (require_fallback && !c->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, m->path, c, NULL);
-                if (r < 0)
-                        return r;
-                if (bus->nodes_modified)
-                        return 0;
+                r = node_vtable_get_userdata(bus, m->path, c, NULL, &error);
+                if (r < 0) {
+                        r = bus_maybe_reply_error(m, r, &error);
+                        goto finish;
+                }
+                if (bus->nodes_modified) {
+                        r = 0;
+                        goto finish;
+                }
                 if (r == 0)
                         continue;
 
@@ -843,7 +854,7 @@ static int object_manager_serialize_path(
                 if (require_fallback && !i->is_fallback)
                         continue;
 
-                r = node_vtable_get_userdata(bus, path, i, &u);
+                r = node_vtable_get_userdata(bus, path, i, &u, error);
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
@@ -902,8 +913,6 @@ static int object_manager_serialize_path(
                 r = vtable_append_all_properties(bus, reply, path, i, u, error);
                 if (r < 0)
                         return r;
-                if (sd_bus_error_is_set(error))
-                        return 0;
                 if (bus->nodes_modified)
                         return 0;
 
@@ -951,8 +960,6 @@ static int object_manager_serialize_path_and_fallbacks(
         r = object_manager_serialize_path(bus, reply, path, path, false, error);
         if (r < 0)
                 return r;
-        if (sd_bus_error_is_set(error))
-                return 0;
         if (bus->nodes_modified)
                 return 0;
 
@@ -962,8 +969,6 @@ static int object_manager_serialize_path_and_fallbacks(
                 r = object_manager_serialize_path(bus, reply, prefix, path, true, error);
                 if (r < 0)
                         return r;
-                if (sd_bus_error_is_set(error))
-                        return 0;
                 if (bus->nodes_modified)
                         return 0;
         }
@@ -978,6 +983,7 @@ static int process_get_managed_objects(
                 bool require_fallback,
                 bool *found_object) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
         _cleanup_set_free_free_ Set *s = NULL;
         bool empty;
@@ -991,7 +997,7 @@ static int process_get_managed_objects(
         if (!bus_node_with_object_manager(bus, n))
                 return 0;
 
-        r = get_child_nodes(bus, m->path, n, &s);
+        r = get_child_nodes(bus, m->path, n, &s, &error);
         if (r < 0)
                 return r;
         if (bus->nodes_modified)
@@ -1034,19 +1040,9 @@ static int process_get_managed_objects(
                 char *path;
 
                 SET_FOREACH(path, s, i) {
-                        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
-
                         r = object_manager_serialize_path_and_fallbacks(bus, reply, path, &error);
                         if (r < 0)
-                                return -ENOMEM;
-
-                        if (sd_bus_error_is_set(&error)) {
-                                r = sd_bus_reply_method_error(m, &error);
-                                if (r < 0)
-                                        return r;
-
-                                return 1;
-                        }
+                                return r;
 
                         if (bus->nodes_modified)
                                 return 0;
@@ -1851,6 +1847,7 @@ static int emit_properties_changed_on_interface(
                 bool require_fallback,
                 char **names) {
 
+        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
         bool has_invalidating = false, has_changing = false;
         struct vtable_member key = {};
@@ -1891,7 +1888,7 @@ static int emit_properties_changed_on_interface(
                 if (!streq(c->interface, interface))
                         continue;
 
-                r = node_vtable_get_userdata(bus, path, c, &u);
+                r = node_vtable_get_userdata(bus, path, c, &u, &error);
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
@@ -1900,7 +1897,6 @@ static int emit_properties_changed_on_interface(
                         continue;
 
                 STRV_FOREACH(property, names) {
-                        _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
                         struct vtable_member *v;
 
                         assert_return(member_name_is_valid(*property), -EINVAL);
@@ -1940,8 +1936,6 @@ static int emit_properties_changed_on_interface(
                         r = invoke_property_get(bus, v->vtable, m->path, interface, *property, m, vtable_property_convert_userdata(v->vtable, u), &error);
                         if (r < 0)
                                 return r;
-                        if (sd_bus_error_is_set(&error))
-                                return sd_bus_error_get_errno(&error);
                         if (bus->nodes_modified)
                                 return 0;
 
@@ -1974,7 +1968,7 @@ static int emit_properties_changed_on_interface(
                         if (!streq(c->interface, interface))
                                 continue;
 
-                        r = node_vtable_get_userdata(bus, path, c, &u);
+                        r = node_vtable_get_userdata(bus, path, c, &u, &error);
                         if (r < 0)
                                 return r;
                         if (bus->nodes_modified)
@@ -2106,7 +2100,7 @@ static int interfaces_added_append_one_prefix(
                 if (!streq(c->interface, interface))
                         continue;
 
-                r = node_vtable_get_userdata(bus, path, c, &u);
+                r = node_vtable_get_userdata(bus, path, c, &u, &error);
                 if (r < 0)
                         return r;
                 if (bus->nodes_modified)
diff --git a/src/libsystemd-bus/test-bus-objects.c b/src/libsystemd-bus/test-bus-objects.c
index 043aa90..95278e3 100644
--- a/src/libsystemd-bus/test-bus-objects.c
+++ b/src/libsystemd-bus/test-bus-objects.c
@@ -182,7 +182,7 @@ static const sd_bus_vtable vtable2[] = {
         SD_BUS_VTABLE_END
 };
 
-static int enumerator_callback(sd_bus *b, const char *path, char ***nodes, void *userdata) {
+static int enumerator_callback(sd_bus *b, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
 
         if (object_path_startswith("/value", path))
                 assert_se(*nodes = strv_new("/value/a", "/value/b", "/value/c", NULL));
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index 488d007..f274c0d 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -254,7 +254,7 @@ const sd_bus_vtable seat_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
-int seat_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+int seat_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         Seat *seat;
         int r;
@@ -319,7 +319,7 @@ char *seat_bus_path(Seat *s) {
         return strappend("/org/freedesktop/login1/seat/", t);
 }
 
-int seat_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
         _cleanup_strv_free_ char **l = NULL;
         Manager *m = userdata;
         Seat *seat;
diff --git a/src/login/logind-seat.h b/src/login/logind-seat.h
index 0547dec..80c6b8b 100644
--- a/src/login/logind-seat.h
+++ b/src/login/logind-seat.h
@@ -82,8 +82,8 @@ bool seat_name_is_valid(const char *name);
 
 extern const sd_bus_vtable seat_vtable[];
 
-int seat_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata);
-int seat_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *seatdata);
+int seat_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
+int seat_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
 char *seat_bus_path(Seat *s);
 
 int seat_send_signal(Seat *s, bool new_seat);
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index d2e2364..9f3217b 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -465,7 +465,7 @@ const sd_bus_vtable session_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
-int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         Session *session;
         int r;
@@ -524,7 +524,7 @@ char *session_bus_path(Session *s) {
         return strappend("/org/freedesktop/login1/session/", t);
 }
 
-int session_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+int session_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
         _cleanup_strv_free_ char **l = NULL;
         Manager *m = userdata;
         Session *session;
diff --git a/src/login/logind-session.h b/src/login/logind-session.h
index bcbd4e5..f7a9dbc 100644
--- a/src/login/logind-session.h
+++ b/src/login/logind-session.h
@@ -139,8 +139,8 @@ int session_kill(Session *s, KillWho who, int signo);
 SessionState session_get_state(Session *u);
 
 extern const sd_bus_vtable session_vtable[];
-int session_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata);
-int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata);
+int session_node_enumerator(sd_bus *bus, const char *path,void *userdata, char ***nodes, sd_bus_error *error);
+int session_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
 char *session_bus_path(Session *s);
 
 int session_send_signal(Session *s, bool new_session);
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index 3942fa9..6a77e33 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -235,7 +235,7 @@ const sd_bus_vtable user_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
-int user_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+int user_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         User *user;
         int r;
@@ -293,7 +293,7 @@ char *user_bus_path(User *u) {
         return s;
 }
 
-int user_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
         _cleanup_strv_free_ char **l = NULL;
         Manager *m = userdata;
         User *user;
diff --git a/src/login/logind-user.h b/src/login/logind-user.h
index 8d396c6..8d5f119 100644
--- a/src/login/logind-user.h
+++ b/src/login/logind-user.h
@@ -82,8 +82,8 @@ int user_kill(User *u, int signo);
 int user_check_linger_file(User *u);
 
 extern const sd_bus_vtable user_vtable[];
-int user_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata);
-int user_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata);
+int user_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
+int user_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
 char *user_bus_path(User *s);
 
 int user_send_signal(User *u, bool new_user);
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index 2c7f3a7..c6a794b 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -142,7 +142,7 @@ const sd_bus_vtable machine_vtable[] = {
         SD_BUS_VTABLE_END
 };
 
-int machine_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
+int machine_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) {
         Manager *m = userdata;
         Machine *machine;
         int r;
@@ -201,7 +201,7 @@ char *machine_bus_path(Machine *m) {
         return strappend("/org/freedesktop/machine1/machine/", e);
 }
 
-int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) {
         _cleanup_strv_free_ char **l = NULL;
         Machine *machine = NULL;
         Manager *m = userdata;
diff --git a/src/machine/machine.h b/src/machine/machine.h
index 99ee258..62e4b2b 100644
--- a/src/machine/machine.h
+++ b/src/machine/machine.h
@@ -93,7 +93,8 @@ MachineState machine_get_state(Machine *u);
 extern const sd_bus_vtable machine_vtable[];
 
 char *machine_bus_path(Machine *s);
-int machine_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata);
+int machine_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error);
+int machine_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error);
 
 int machine_send_signal(Machine *m, bool new_machine);
 int machine_send_create_reply(Machine *m, sd_bus_error *error);
diff --git a/src/machine/machined.h b/src/machine/machined.h
index 0b074c4..d4b581b 100644
--- a/src/machine/machined.h
+++ b/src/machine/machined.h
@@ -60,8 +60,6 @@ int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine);
 
 extern const sd_bus_vtable manager_vtable[];
 
-int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata);
-
 int match_reloading(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
 int match_unit_removed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
 int match_properties_changed(sd_bus *bus, sd_bus_message *message, void *userdata, sd_bus_error *error);
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 5827208..8954e38 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -49,8 +49,8 @@ typedef struct {
 typedef int (*sd_bus_message_handler_t)(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *ret_error);
 typedef int (*sd_bus_property_get_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *ret_error);
 typedef int (*sd_bus_property_set_t) (sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *ret_error);
-typedef int (*sd_bus_object_find_t) (sd_bus *bus, const char *path, const char *interface, void **found, void *userdata);
-typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *path, char ***nodes, void *userdata);
+typedef int (*sd_bus_object_find_t) (sd_bus *bus, const char *path, const char *interface, void *userdata, void **ret_found, sd_bus_error *ret_error);
+typedef int (*sd_bus_node_enumerator_t) (sd_bus *bus, const char *path, void *userdata, char ***ret_nodes, sd_bus_error *ret_error);
 
 #include "sd-bus-protocol.h"
 #include "sd-bus-vtable.h"



More information about the systemd-commits mailing list