diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2020-03-31 07:28:01 -0700 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-02 10:26:18 +0200 |
commit | 935052a8aa11329061cbee234c99b03973163594 (patch) | |
tree | c7cfa8ca6f19ba042c3e83a6cba22bdf10b5a941 /src | |
parent | c51c6f2f574e8c107994057c13a6506d93966a23 (diff) | |
download | systemd-935052a8aa11329061cbee234c99b03973163594.tar.gz |
sd-bus: add va_list variants of variadic convenience functions
Consumers of the sd-bus convenience API can't make convenience
helpers of their own without va_list variants.
This commit is a mechanical change splitting out the existing function
bodies into bare va_list variants having a 'v' suffixed to the names.
The original functions now simply create the va_list before forwarding
the call on to the va_list variant, and the va_list variants dispense
with those steps.
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/libsystemd.sym | 7 | ||||
-rw-r--r-- | src/libsystemd/sd-bus/bus-convenience.c | 176 | ||||
-rw-r--r-- | src/systemd/sd-bus.h | 7 |
3 files changed, 151 insertions, 39 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 2c1bcab576..1cfe355089 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -700,6 +700,13 @@ global: LIBSYSTEMD_246 { global: + sd_bus_call_methodv; + sd_bus_call_method_asyncv; + sd_bus_emit_signalv; + sd_bus_reply_method_errnofv; + sd_bus_reply_method_errorfv; + sd_bus_reply_method_returnv; + sd_bus_set_propertyv; sd_path_lookup; sd_path_lookup_strv; } LIBSYSTEMD_245; diff --git a/src/libsystemd/sd-bus/bus-convenience.c b/src/libsystemd/sd-bus/bus-convenience.c index 89547a252d..a5672a831f 100644 --- a/src/libsystemd/sd-bus/bus-convenience.c +++ b/src/libsystemd/sd-bus/bus-convenience.c @@ -10,12 +10,12 @@ #include "bus-util.h" #include "string-util.h" -_public_ int sd_bus_emit_signal( +_public_ int sd_bus_emit_signalv( sd_bus *bus, const char *path, const char *interface, const char *member, - const char *types, ...) { + const char *types, va_list ap) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; @@ -32,11 +32,7 @@ _public_ int sd_bus_emit_signal( return r; if (!isempty(types)) { - va_list ap; - - va_start(ap, types); r = sd_bus_message_appendv(m, types, ap); - va_end(ap); if (r < 0) return r; } @@ -44,7 +40,24 @@ _public_ int sd_bus_emit_signal( return sd_bus_send(bus, m, NULL); } -_public_ int sd_bus_call_method_async( +_public_ int sd_bus_emit_signal( + sd_bus *bus, + const char *path, + const char *interface, + const char *member, + const char *types, ...) { + + va_list ap; + int r; + + va_start(ap, types); + r = sd_bus_emit_signalv(bus, path, interface, member, types, ap); + va_end(ap); + + return r; +} + +_public_ int sd_bus_call_method_asyncv( sd_bus *bus, sd_bus_slot **slot, const char *destination, @@ -53,7 +66,7 @@ _public_ int sd_bus_call_method_async( const char *member, sd_bus_message_handler_t callback, void *userdata, - const char *types, ...) { + const char *types, va_list ap) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; @@ -70,11 +83,7 @@ _public_ int sd_bus_call_method_async( return r; if (!isempty(types)) { - va_list ap; - - va_start(ap, types); r = sd_bus_message_appendv(m, types, ap); - va_end(ap); if (r < 0) return r; } @@ -82,7 +91,28 @@ _public_ int sd_bus_call_method_async( return sd_bus_call_async(bus, slot, m, callback, userdata, 0); } -_public_ int sd_bus_call_method( +_public_ int sd_bus_call_method_async( + sd_bus *bus, + sd_bus_slot **slot, + const char *destination, + const char *path, + const char *interface, + const char *member, + sd_bus_message_handler_t callback, + void *userdata, + const char *types, ...) { + + va_list ap; + int r; + + va_start(ap, types); + r = sd_bus_call_method_asyncv(bus, slot, destination, path, interface, member, callback, userdata, types, ap); + va_end(ap); + + return r; +} + +_public_ int sd_bus_call_methodv( sd_bus *bus, const char *destination, const char *path, @@ -90,7 +120,7 @@ _public_ int sd_bus_call_method( const char *member, sd_bus_error *error, sd_bus_message **reply, - const char *types, ...) { + const char *types, va_list ap) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; @@ -109,11 +139,7 @@ _public_ int sd_bus_call_method( goto fail; if (!isempty(types)) { - va_list ap; - - va_start(ap, types); r = sd_bus_message_appendv(m, types, ap); - va_end(ap); if (r < 0) goto fail; } @@ -124,10 +150,30 @@ fail: return sd_bus_error_set_errno(error, r); } -_public_ int sd_bus_reply_method_return( - sd_bus_message *call, +_public_ int sd_bus_call_method( + sd_bus *bus, + const char *destination, + const char *path, + const char *interface, + const char *member, + sd_bus_error *error, + sd_bus_message **reply, const char *types, ...) { + va_list ap; + int r; + + va_start(ap, types); + r = sd_bus_call_methodv(bus, destination, path, interface, member, error, reply, types, ap); + va_end(ap); + + return r; +} + +_public_ int sd_bus_reply_method_returnv( + sd_bus_message *call, + const char *types, va_list ap) { + _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; int r; @@ -148,11 +194,7 @@ _public_ int sd_bus_reply_method_return( return r; if (!isempty(types)) { - va_list ap; - - va_start(ap, types); r = sd_bus_message_appendv(m, types, ap); - va_end(ap); if (r < 0) return r; } @@ -160,6 +202,20 @@ _public_ int sd_bus_reply_method_return( return sd_bus_send(call->bus, m, NULL); } +_public_ int sd_bus_reply_method_return( + sd_bus_message *call, + const char *types, ...) { + + va_list ap; + int r; + + va_start(ap, types); + r = sd_bus_reply_method_returnv(call, types, ap); + va_end(ap); + + return r; +} + _public_ int sd_bus_reply_method_error( sd_bus_message *call, const sd_bus_error *e) { @@ -187,14 +243,13 @@ _public_ int sd_bus_reply_method_error( return sd_bus_send(call->bus, m, NULL); } -_public_ int sd_bus_reply_method_errorf( +_public_ int sd_bus_reply_method_errorfv( sd_bus_message *call, const char *name, const char *format, - ...) { + va_list ap) { _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL; - va_list ap; assert_return(call, -EINVAL); assert_return(call->sealed, -EPERM); @@ -208,13 +263,27 @@ _public_ int sd_bus_reply_method_errorf( if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; - va_start(ap, format); bus_error_setfv(&error, name, format, ap); - va_end(ap); return sd_bus_reply_method_error(call, &error); } +_public_ int sd_bus_reply_method_errorf( + sd_bus_message *call, + const char *name, + const char *format, + ...) { + + va_list ap; + int r; + + va_start(ap, format); + r = sd_bus_reply_method_errorfv(call, name, format, ap); + va_end(ap); + + return r; +} + _public_ int sd_bus_reply_method_errno( sd_bus_message *call, int error, @@ -242,14 +311,13 @@ _public_ int sd_bus_reply_method_errno( return sd_bus_reply_method_error(call, &berror); } -_public_ int sd_bus_reply_method_errnof( +_public_ int sd_bus_reply_method_errnofv( sd_bus_message *call, int error, const char *format, - ...) { + va_list ap) { _cleanup_(sd_bus_error_free) sd_bus_error berror = SD_BUS_ERROR_NULL; - va_list ap; assert_return(call, -EINVAL); assert_return(call->sealed, -EPERM); @@ -263,13 +331,27 @@ _public_ int sd_bus_reply_method_errnof( if (call->header->flags & BUS_MESSAGE_NO_REPLY_EXPECTED) return 0; - va_start(ap, format); sd_bus_error_set_errnofv(&berror, error, format, ap); - va_end(ap); return sd_bus_reply_method_error(call, &berror); } +_public_ int sd_bus_reply_method_errnof( + sd_bus_message *call, + int error, + const char *format, + ...) { + + va_list ap; + int r; + + va_start(ap, format); + r = sd_bus_reply_method_errnofv(call, error, format, ap); + va_end(ap); + + return r; +} + _public_ int sd_bus_get_property( sd_bus *bus, const char *destination, @@ -452,17 +534,16 @@ fail: return sd_bus_error_set_errno(error, r); } -_public_ int sd_bus_set_property( +_public_ int sd_bus_set_propertyv( sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *error, - const char *type, ...) { + const char *type, va_list ap) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL; - va_list ap; int r; bus_assert_return(bus, -EINVAL, error); @@ -489,9 +570,7 @@ _public_ int sd_bus_set_property( if (r < 0) goto fail; - va_start(ap, type); r = sd_bus_message_appendv(m, type, ap); - va_end(ap); if (r < 0) goto fail; @@ -505,6 +584,25 @@ fail: return sd_bus_error_set_errno(error, r); } +_public_ 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, ...) { + + va_list ap; + int r; + + va_start(ap, type); + r = sd_bus_set_propertyv(bus, destination, path, interface, member, error, type, ap); + va_end(ap); + + return r; +} + _public_ int sd_bus_query_sender_creds(sd_bus_message *call, uint64_t mask, sd_bus_creds **creds) { sd_bus_creds *c; diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h index 8e4866671c..bc58a5fc9c 100644 --- a/src/systemd/sd-bus.h +++ b/src/systemd/sd-bus.h @@ -352,20 +352,27 @@ int sd_bus_get_name_machine_id(sd_bus *bus, const char *name, sd_id128_t *machin /* Convenience calls */ +int sd_bus_call_methodv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *types, va_list ap); int sd_bus_call_method(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *types, ...); +int sd_bus_call_method_asyncv(sd_bus *bus, sd_bus_slot **slot, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, va_list ap); int sd_bus_call_method_async(sd_bus *bus, sd_bus_slot **slot, const char *destination, const char *path, const char *interface, const char *member, sd_bus_message_handler_t callback, void *userdata, const char *types, ...); int sd_bus_get_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, sd_bus_message **reply, const char *type); int sd_bus_get_property_trivial(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char type, void *ret_ptr); int sd_bus_get_property_string(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char **ret); /* free the result! */ int sd_bus_get_property_strv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, char ***ret); /* free the result! */ +int sd_bus_set_propertyv(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, const char *type, va_list ap); int sd_bus_set_property(sd_bus *bus, const char *destination, const char *path, const char *interface, const char *member, sd_bus_error *ret_error, const char *type, ...); +int sd_bus_reply_method_returnv(sd_bus_message *call, const char *types, va_list ap); int sd_bus_reply_method_return(sd_bus_message *call, const char *types, ...); int sd_bus_reply_method_error(sd_bus_message *call, const sd_bus_error *e); +int sd_bus_reply_method_errorfv(sd_bus_message *call, const char *name, const char *format, va_list ap) _sd_printf_(3, 0); int sd_bus_reply_method_errorf(sd_bus_message *call, const char *name, const char *format, ...) _sd_printf_(3, 4); int sd_bus_reply_method_errno(sd_bus_message *call, int error, const sd_bus_error *e); +int sd_bus_reply_method_errnofv(sd_bus_message *call, int error, const char *format, va_list ap) _sd_printf_(3, 0); int sd_bus_reply_method_errnof(sd_bus_message *call, int error, const char *format, ...) _sd_printf_(3, 4); +int sd_bus_emit_signalv(sd_bus *bus, const char *path, const char *interface, const char *member, const char *types, va_list ap); 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); |