diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-04-09 19:44:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-05-24 17:01:57 +0200 |
commit | 19017acb9f3e5e7edad18f59acb872bfb8dda949 (patch) | |
tree | 6880b1435eb490220cd888bb77d29fa8a3dbbe91 /src/shared/bus-util.c | |
parent | 9b06c1e1ad3289653819af724415e30e377d5880 (diff) | |
download | systemd-19017acb9f3e5e7edad18f59acb872bfb8dda949.tar.gz |
machined: move bus_reply_pair_array() into generic utilities
This way, we can reuse it in portabled.
Diffstat (limited to 'src/shared/bus-util.c')
-rw-r--r-- | src/shared/bus-util.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index ed30edfb60..998134ec8c 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1847,3 +1847,34 @@ int bus_request_name_async_may_reload_dbus(sd_bus *bus, sd_bus_slot **ret_slot, return sd_bus_request_name_async(bus, ret_slot, name, flags, request_name_handler_may_reload_dbus, data); } + +int bus_reply_pair_array(sd_bus_message *m, char **l) { + _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; + char **k, **v; + int r; + + assert(m); + + /* Reply to the specified message with a message containing a dictionary put together from the specified + * strv */ + + r = sd_bus_message_new_method_return(m, &reply); + if (r < 0) + return r; + + r = sd_bus_message_open_container(reply, 'a', "{ss}"); + if (r < 0) + return r; + + STRV_FOREACH_PAIR(k, v, l) { + r = sd_bus_message_append(reply, "{ss}", *k, *v); + if (r < 0) + return r; + } + + r = sd_bus_message_close_container(reply); + if (r < 0) + return r; + + return sd_bus_send(NULL, reply, NULL); +} |