summaryrefslogtreecommitdiffstats
path: root/src/shared/bus-util.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2018-03-28 13:37:27 +0200
committerLennart Poettering <lennart@poettering.net>2018-03-28 13:37:27 +0200
commita7e4861c7471bfe563078d11acbcecbf2d755462 (patch)
tree4f66f511af7e783ef753cd4b8acc8b382d99697e /src/shared/bus-util.c
parentcore: dont't remount /sys/fs/cgroup for relabel if not needed (#8595) (diff)
downloadsystemd-a7e4861c7471bfe563078d11acbcecbf2d755462.tar.xz
systemd-a7e4861c7471bfe563078d11acbcecbf2d755462.zip
bus-util: add flags for bus_map_all_properties() (#8546)
This adds flags BUS_MAP_STRDUP and BUS_MAP_BOOLEAN_AS_BOOL. If BUS_MAP_STRDUP is set, then each "s" message is duplicated. If BUS_MAP_BOOLEAN_AS_BOOL is set, then each "b" message is written to a bool pointer. Follow-up for #8488. See https://github.com/systemd/systemd/pull/8488#discussion_r175816270.
Diffstat (limited to 'src/shared/bus-util.c')
-rw-r--r--src/shared/bus-util.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 803f75335c..df382f77a6 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -1057,7 +1057,7 @@ int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_err
return 0;
}
-static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata, bool copy_string) {
+static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, unsigned flags, sd_bus_error *error, void *userdata) {
char type;
int r;
@@ -1078,7 +1078,7 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_
if (isempty(s))
s = NULL;
- if (copy_string)
+ if (flags & BUS_MAP_STRDUP)
return free_and_strdup((char **) userdata, s);
*p = s;
@@ -1099,14 +1099,17 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_
}
case SD_BUS_TYPE_BOOLEAN: {
- unsigned b;
- bool *p = userdata;
+ int b;
r = sd_bus_message_read_basic(m, type, &b);
if (r < 0)
return r;
- *p = !!b;
+ if (flags & BUS_MAP_BOOLEAN_AS_BOOL)
+ * (bool*) userdata = !!b;
+ else
+ * (int*) userdata = b;
+
return 0;
}
@@ -1151,7 +1154,7 @@ static int map_basic(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_
int bus_message_map_all_properties(
sd_bus_message *m,
const struct bus_properties_map *map,
- bool copy_string,
+ unsigned flags,
sd_bus_error *error,
void *userdata) {
@@ -1194,7 +1197,7 @@ int bus_message_map_all_properties(
if (map[i].set)
r = prop->set(sd_bus_message_get_bus(m), member, m, error, v);
else
- r = map_basic(sd_bus_message_get_bus(m), member, m, error, v, copy_string);
+ r = map_basic(sd_bus_message_get_bus(m), member, m, flags, error, v);
if (r < 0)
return r;
@@ -1220,7 +1223,7 @@ int bus_message_map_all_properties(
int bus_message_map_properties_changed(
sd_bus_message *m,
const struct bus_properties_map *map,
- bool copy_string,
+ unsigned flags,
sd_bus_error *error,
void *userdata) {
@@ -1230,7 +1233,7 @@ int bus_message_map_properties_changed(
assert(m);
assert(map);
- r = bus_message_map_all_properties(m, map, copy_string, error, userdata);
+ r = bus_message_map_all_properties(m, map, flags, error, userdata);
if (r < 0)
return r;
@@ -1260,6 +1263,7 @@ int bus_map_all_properties(
const char *destination,
const char *path,
const struct bus_properties_map *map,
+ unsigned flags,
sd_bus_error *error,
sd_bus_message **reply,
void *userdata) {
@@ -1271,6 +1275,7 @@ int bus_map_all_properties(
assert(destination);
assert(path);
assert(map);
+ assert(reply || (flags & BUS_MAP_STRDUP));
r = sd_bus_call_method(
bus,
@@ -1284,7 +1289,7 @@ int bus_map_all_properties(
if (r < 0)
return r;
- r = bus_message_map_all_properties(m, map, !reply, error, userdata);
+ r = bus_message_map_all_properties(m, map, flags, error, userdata);
if (r < 0)
return r;