[systemd-commits] 5 commits - src/libsystemd-bus src/systemd

Lennart Poettering lennart at kemper.freedesktop.org
Thu Oct 10 20:22:29 PDT 2013


 src/libsystemd-bus/sd-bus.c           |   75 ++++++++++++++++++++--------------
 src/libsystemd-bus/sd-event.c         |   28 ++++++++++--
 src/libsystemd-bus/test-bus-objects.c |   52 +++++++++++++++++++----
 src/systemd/sd-bus.h                  |   14 ++++--
 src/systemd/sd-event.h                |    2 
 5 files changed, 123 insertions(+), 48 deletions(-)

New commits:
commit 62b5c2aec12e6a3d305445ee1a88bc18ca0a1548
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 11 05:22:00 2013 +0200

    bus: make PropertiesChanged emission work

diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 542b5e8..11194af 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -3994,18 +3994,16 @@ static int emit_properties_changed_on_interface(
 
                 if (streq(c->interface, interface))
                         break;
-
-                r = node_vtable_get_userdata(bus, path, c, &u);
-                if (r < 0)
-                        return r;
-                if (r > 0)
-                        break;
         }
 
         if (!c)
                 return 0;
 
-        r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus", "PropertiesChanged", &m);
+        r = node_vtable_get_userdata(bus, path, c, &u);
+        if (r <= 0)
+                return r;
+
+        r = sd_bus_message_new_signal(bus, path, "org.freedesktop.DBus.Properties", "PropertiesChanged", &m);
         if (r < 0)
                 return r;
 
@@ -4042,7 +4040,7 @@ static int emit_properties_changed_on_interface(
                 if (r < 0)
                         return r;
 
-                r = sd_bus_message_append(m, "s", *n);
+                r = sd_bus_message_append(m, "s", *property);
                 if (r < 0)
                         return r;
 
diff --git a/src/libsystemd-bus/test-bus-objects.c b/src/libsystemd-bus/test-bus-objects.c
index f3571cb..b4facda 100644
--- a/src/libsystemd-bus/test-bus-objects.c
+++ b/src/libsystemd-bus/test-bus-objects.c
@@ -36,8 +36,6 @@
 
 /* Test:
  *
- *   sd_bus_emit_properties_changed()
- *
  *   Add in:
  *
  *   automatic properties
@@ -134,6 +132,16 @@ static int value_handler(sd_bus *bus, const char *path, const char *interface, c
 
         assert_se(PTR_TO_UINT(userdata) == 30);
 
+        return 1;
+}
+
+static int notify_test(sd_bus *bus, sd_bus_message *m, void *userdata) {
+        int r;
+
+        assert_se(sd_bus_emit_properties_changed(bus, m->path, "org.freedesktop.systemd.ValueTest", "Value", NULL) >= 0);
+
+        r = sd_bus_reply_method_return(bus, m, NULL);
+        assert_se(r >= 0);
 
         return 1;
 }
@@ -148,7 +156,8 @@ static const sd_bus_vtable vtable[] = {
 
 static const sd_bus_vtable vtable2[] = {
         SD_BUS_VTABLE_START(0),
-        SD_BUS_PROPERTY("Value", "s", value_handler, 10, 0),
+        SD_BUS_METHOD("NotifyTest", "", "", 0, notify_test),
+        SD_BUS_PROPERTY("Value", "s", value_handler, 10, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_VTABLE_END
 };
 
@@ -347,6 +356,18 @@ static int client(struct context *c) {
         sd_bus_message_unref(reply);
         reply = NULL;
 
+        r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.systemd.ValueTest", "NotifyTest", &error, NULL, "");
+        assert_se(r >= 0);
+
+        r = sd_bus_process(bus, &reply);
+        assert_se(r > 0);
+
+        assert_se(sd_bus_message_is_signal(reply, "org.freedesktop.DBus.Properties", "PropertiesChanged"));
+        bus_message_dump(reply);
+
+        sd_bus_message_unref(reply);
+        reply = NULL;
+
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Exit", &error, NULL, "");
         assert_se(r >= 0);
 

commit 90d184b234fbb72cb06636571655f30ba9858887
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 11 05:21:08 2013 +0200

    bus: decorate API calls with gcc attributes where appropriate

diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 101e751..9268247 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -39,6 +39,10 @@ extern "C" {
 #  endif
 #endif
 
+#ifndef _sd_sentinel_attr_
+#  define _sd_sentinel_attr_ __attribute__((sentinel))
+#endif
+
 /* Types */
 
 typedef struct sd_bus sd_bus;
@@ -137,7 +141,7 @@ int sd_bus_message_new_signal(sd_bus *bus, const char *path, const char *interfa
 int sd_bus_message_new_method_call(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message **m);
 int sd_bus_message_new_method_return(sd_bus *bus, sd_bus_message *call, sd_bus_message **m);
 int sd_bus_message_new_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e, sd_bus_message **m);
-int sd_bus_message_new_method_errorf(sd_bus *bus, sd_bus_message *call, sd_bus_message **m, const char *name, const char *format, ...);
+int sd_bus_message_new_method_errorf(sd_bus *bus, sd_bus_message *call, sd_bus_message **m, const char *name, const char *format, ...) _sd_printf_attr_(5, 0);
 
 sd_bus_message* sd_bus_message_ref(sd_bus_message *m);
 sd_bus_message* sd_bus_message_unref(sd_bus_message *m);
@@ -209,17 +213,17 @@ int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path,
 int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, const char *type, ...);
 int sd_bus_reply_method_return(sd_bus *bus, sd_bus_message *call, const char *types, ...);
 int sd_bus_reply_method_error(sd_bus *bus, sd_bus_message *call, const sd_bus_error *e);
-int sd_bus_reply_method_errorf(sd_bus *bus, sd_bus_message *call, const char *name, const char *format, ...);
+int sd_bus_reply_method_errorf(sd_bus *bus, sd_bus_message *call, const char *name, const char *format, ...) _sd_printf_attr_(4, 0);
 
 int sd_bus_emit_signal(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, ...);
 
 int sd_bus_emit_properties_changed_strv(sd_bus *bus, const char *path, const char *interface, char **names);
-int sd_bus_emit_properties_changed(sd_bus *bus, const char *path, const char *interface, const char *name, ...);
+int sd_bus_emit_properties_changed(sd_bus *bus, const char *path, const char *interface, const char *name, ...) _sd_sentinel_attr_;
 
 int sd_bus_emit_interfaces_added_strv(sd_bus *bus, const char *path, char **interfaces);   /* MISSING */
-int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...);   /* MISSING */
+int sd_bus_emit_interfaces_added(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_attr_;   /* MISSING */
 int sd_bus_emit_interfaces_removed_strv(sd_bus *bus, const char *path, char **interfaces);  /* MISSING */
-int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...);  /* MISSING */
+int sd_bus_emit_interfaces_removed(sd_bus *bus, const char *path, const char *interface, ...) _sd_sentinel_attr_;  /* MISSING */
 
 /* Bus management */
 

commit 5a037827f61a2e78f3863bc5a08f1535882d7f6a
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 11 05:20:24 2013 +0200

    bus: allow specifying NULL as type string when we want to construct messages with no payload

diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 342af4d..542b5e8 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -3398,7 +3398,6 @@ int sd_bus_emit_signal(
                 const char *types, ...) {
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        va_list ap;
         int r;
 
         if (!bus)
@@ -3412,11 +3411,15 @@ int sd_bus_emit_signal(
         if (r < 0)
                 return r;
 
-        va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
-        va_end(ap);
-        if (r < 0)
-                return r;
+        if (!isempty(types)) {
+                va_list ap;
+
+                va_start(ap, types);
+                r = bus_message_append_ap(m, types, ap);
+                va_end(ap);
+                if (r < 0)
+                        return r;
+        }
 
         return sd_bus_send(bus, m, NULL);
 }
@@ -3432,7 +3435,6 @@ int sd_bus_call_method(
                 const char *types, ...) {
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        va_list ap;
         int r;
 
         if (!bus)
@@ -3447,11 +3449,15 @@ int sd_bus_call_method(
         if (r < 0)
                 return r;
 
-        va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
-        va_end(ap);
-        if (r < 0)
-                return r;
+        if (!isempty(types)) {
+                va_list ap;
+
+                va_start(ap, types);
+                r = bus_message_append_ap(m, types, ap);
+                va_end(ap);
+                if (r < 0)
+                        return r;
+        }
 
         return sd_bus_send_with_reply_and_block(bus, m, 0, error, reply);
 }
@@ -3462,7 +3468,6 @@ int sd_bus_reply_method_return(
                 const char *types, ...) {
 
         _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-        va_list ap;
         int r;
 
         if (!bus)
@@ -3485,11 +3490,15 @@ int sd_bus_reply_method_return(
         if (r < 0)
                 return r;
 
-        va_start(ap, types);
-        r = bus_message_append_ap(m, types, ap);
-        va_end(ap);
-        if (r < 0)
-                return r;
+        if (!isempty(types)) {
+                va_list ap;
+
+                va_start(ap, types);
+                r = bus_message_append_ap(m, types, ap);
+                va_end(ap);
+                if (r < 0)
+                        return r;
+        }
 
         return sd_bus_send(bus, m, NULL);
 }

commit 5d12cc3e286c8515f18c8417d67e26e4e2b2e7cb
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 11 04:52:38 2013 +0200

    bus: make GetManagedObjects() work

diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 795007a..342af4d 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2499,6 +2499,7 @@ static int object_manager_serialize_vtable(
 static int object_manager_serialize_path(
                 sd_bus *bus,
                 sd_bus_message *reply,
+                const char *prefix,
                 const char *path,
                 bool require_fallback,
                 sd_bus_error *error) {
@@ -2509,10 +2510,11 @@ static int object_manager_serialize_path(
 
         assert(bus);
         assert(reply);
+        assert(prefix);
         assert(path);
         assert(error);
 
-        n = hashmap_get(bus->nodes, path);
+        n = hashmap_get(bus->nodes, prefix);
         if (!n)
                 return 0;
 
@@ -2566,7 +2568,7 @@ static int object_manager_serialize_path_and_fallbacks(
         assert(error);
 
         /* First, add all vtables registered for this path */
-        r = object_manager_serialize_path(bus, reply, path, false, error);
+        r = object_manager_serialize_path(bus, reply, path, path, false, error);
         if (r < 0)
                 return r;
         if (sd_bus_error_is_set(error))
@@ -2587,7 +2589,7 @@ static int object_manager_serialize_path_and_fallbacks(
 
                         *e = 0;
 
-                        r = object_manager_serialize_path(bus, reply, p, true, error);
+                        r = object_manager_serialize_path(bus, reply, p, path, true, error);
                         if (r < 0)
                                 return r;
 
@@ -2687,7 +2689,13 @@ static int process_get_managed_objects(
         return 1;
 }
 
-static int object_find_and_run(sd_bus *bus, sd_bus_message *m, const char *p, bool require_fallback, bool *found_object) {
+static int object_find_and_run(
+                sd_bus *bus,
+                sd_bus_message *m,
+                const char *p,
+                bool require_fallback,
+                bool *found_object) {
+
         struct node *n;
         struct vtable_member vtable_key, *v;
         int r;
diff --git a/src/libsystemd-bus/test-bus-objects.c b/src/libsystemd-bus/test-bus-objects.c
index a95789f..f3571cb 100644
--- a/src/libsystemd-bus/test-bus-objects.c
+++ b/src/libsystemd-bus/test-bus-objects.c
@@ -36,7 +36,6 @@
 
 /* Test:
  *
- *   sd_bus_add_object_manager()
  *   sd_bus_emit_properties_changed()
  *
  *   Add in:
@@ -179,6 +178,7 @@ static void *server(void *p) {
         assert_se(sd_bus_add_object_vtable(bus, "/foo", "org.freedesktop.systemd.test2", vtable, c) >= 0);
         assert_se(sd_bus_add_fallback_vtable(bus, "/value", "org.freedesktop.systemd.ValueTest", vtable2, NULL, UINT_TO_PTR(20)) >= 0);
         assert_se(sd_bus_add_node_enumerator(bus, "/value", enumerator_callback, NULL) >= 0);
+        assert_se(sd_bus_add_object_manager(bus, "/value") >= 0);
 
         assert_se(sd_bus_start(bus) >= 0);
 
@@ -272,7 +272,7 @@ static int client(struct context *c) {
         reply = NULL;
 
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
-        assert_se(r <= 0);
+        assert_se(r >= 0);
 
         r = sd_bus_message_read(reply, "s", &s);
         assert_se(r >= 0);
@@ -292,7 +292,7 @@ static int client(struct context *c) {
         reply = NULL;
 
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
-        assert_se(r <= 0);
+        assert_se(r >= 0);
 
         r = sd_bus_message_read(reply, "s", &s);
         assert_se(r >= 0);
@@ -302,7 +302,7 @@ static int client(struct context *c) {
         reply = NULL;
 
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
-        assert_se(r <= 0);
+        assert_se(r >= 0);
 
         r = sd_bus_message_read(reply, "s", &s);
         assert_se(r >= 0);
@@ -312,7 +312,7 @@ static int client(struct context *c) {
         reply = NULL;
 
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value/a", "org.freedesktop.DBus.Introspectable", "Introspect", &error, &reply, "");
-        assert_se(r <= 0);
+        assert_se(r >= 0);
 
         r = sd_bus_message_read(reply, "s", &s);
         assert_se(r >= 0);
@@ -322,7 +322,7 @@ static int client(struct context *c) {
         reply = NULL;
 
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.Properties", "GetAll", &error, &reply, "s", "");
-        assert_se(r <= 0);
+        assert_se(r >= 0);
 
         bus_message_dump(reply);
 
@@ -334,6 +334,19 @@ static int client(struct context *c) {
         assert_se(sd_bus_error_has_name(&error, "org.freedesktop.DBus.Error.UnknownInterface"));
         sd_bus_error_free(&error);
 
+        r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", &error, &reply, "");
+        assert_se(r < 0);
+        assert_se(sd_bus_error_has_name(&error, "org.freedesktop.DBus.Error.UnknownMethod"));
+        sd_bus_error_free(&error);
+
+        r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/value", "org.freedesktop.DBus.ObjectManager", "GetManagedObjects", &error, &reply, "");
+        assert_se(r >= 0);
+
+        bus_message_dump(reply);
+
+        sd_bus_message_unref(reply);
+        reply = NULL;
+
         r = sd_bus_call_method(bus, "org.freedesktop.systemd.test", "/foo", "org.freedesktop.systemd.test", "Exit", &error, NULL, "");
         assert_se(r >= 0);
 

commit 46e8c8257f5dd0bcf964eb1f5cbb9ce43aac5201
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Oct 11 04:36:02 2013 +0200

    event: add apis to query the timestamp of the event currently processed

diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index e9f4290..96ba2ad 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -133,6 +133,7 @@ struct sd_event {
         pid_t original_pid;
 
         unsigned iteration;
+        dual_timestamp timestamp;
         int state;
 
         bool quit_requested:1;
@@ -1692,7 +1693,6 @@ static sd_event_source* event_next_pending(sd_event *e) {
 int sd_event_run(sd_event *e, uint64_t timeout) {
         struct epoll_event ev_queue[EPOLL_QUEUE_MAX];
         sd_event_source *p;
-        dual_timestamp n;
         int r, i, m;
 
         assert_return(e, -EINVAL);
@@ -1731,7 +1731,7 @@ int sd_event_run(sd_event *e, uint64_t timeout) {
                 goto finish;
         }
 
-        dual_timestamp_get(&n);
+        dual_timestamp_get(&e->timestamp);
 
         for (i = 0; i < m; i++) {
 
@@ -1748,11 +1748,11 @@ int sd_event_run(sd_event *e, uint64_t timeout) {
                         goto finish;
         }
 
-        r = process_timer(e, n.monotonic, e->monotonic_earliest, e->monotonic_latest);
+        r = process_timer(e, e->timestamp.monotonic, e->monotonic_earliest, e->monotonic_latest);
         if (r < 0)
                 goto finish;
 
-        r = process_timer(e, n.realtime, e->realtime_earliest, e->realtime_latest);
+        r = process_timer(e, e->timestamp.realtime, e->realtime_earliest, e->realtime_latest);
         if (r < 0)
                 goto finish;
 
@@ -1821,3 +1821,23 @@ int sd_event_request_quit(sd_event *e) {
         e->quit_requested = true;
         return 0;
 }
+
+int sd_event_get_now_realtime(sd_event *e, uint64_t *usec) {
+        assert_return(e, -EINVAL);
+        assert_return(usec, -EINVAL);
+        assert_return(dual_timestamp_is_set(&e->timestamp), -ENODATA);
+        assert_return(!event_pid_changed(e), -ECHILD);
+
+        *usec = e->timestamp.realtime;
+        return 0;
+}
+
+int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec) {
+        assert_return(e, -EINVAL);
+        assert_return(usec, -EINVAL);
+        assert_return(dual_timestamp_is_set(&e->timestamp), -ENODATA);
+        assert_return(!event_pid_changed(e), -ECHILD);
+
+        *usec = e->timestamp.monotonic;
+        return 0;
+}
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index d50c124..d160520 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -79,6 +79,8 @@ int sd_event_loop(sd_event *e);
 int sd_event_get_state(sd_event *e);
 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);
 



More information about the systemd-commits mailing list