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.
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
hostname_map,
+ BUS_MAP_STRDUP,
&error,
NULL,
host);
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
manager_map,
+ BUS_MAP_STRDUP,
&error,
NULL,
host);
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
hostname_map,
+ 0,
error,
&host_message,
&info);
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
manager_map,
+ 0,
error,
&manager_message,
&info);
"org.freedesktop.locale1",
"/org/freedesktop/locale1",
map,
+ 0,
&error,
&m,
&info);
SessionStatusInfo i = {};
int r;
- r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &error, &m, &i);
+ r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
if (r < 0)
return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
_cleanup_(user_status_info_clear) UserStatusInfo i = {};
int r;
- r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &error, &m, &i);
+ r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, BUS_MAP_BOOLEAN_AS_BOOL, &error, &m, &i);
if (r < 0)
return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
_cleanup_(seat_status_info_clear) SeatStatusInfo i = {};
int r;
- r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, &error, &m, &i);
+ r = bus_map_all_properties(bus, "org.freedesktop.login1", path, map, 0, &error, &m, &i);
if (r < 0)
return log_error_errno(r, "Could not get properties: %s", bus_error_message(&error, r));
"org.freedesktop.machine1",
path,
map,
+ 0,
&error,
&m,
&info);
"org.freedesktop.machine1",
path,
map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&info);
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
map,
+ 0,
&error,
&m,
&info);
"org.freedesktop.resolve1",
p,
property_map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&link_info);
"org.freedesktop.resolve1",
"/org/freedesktop/resolve1",
property_map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&global_info);
"org.freedesktop.systemd1",
path,
map,
+ BUS_MAP_STRDUP,
&error,
NULL,
c);
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;
if (isempty(s))
s = NULL;
- if (copy_string)
+ if (flags & BUS_MAP_STRDUP)
return free_and_strdup((char **) userdata, s);
*p = s;
}
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;
}
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) {
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;
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) {
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;
const char *destination,
const char *path,
const struct bus_properties_map *map,
+ unsigned flags,
sd_bus_error *error,
sd_bus_message **reply,
void *userdata) {
assert(destination);
assert(path);
assert(map);
+ assert(reply || (flags & BUS_MAP_STRDUP));
r = sd_bus_call_method(
bus,
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;
size_t offset;
};
+enum {
+ BUS_MAP_STRDUP = 1U << 0, /* If set, each "s" message is duplicated. Thus, each pointer needs to be freed. */
+ BUS_MAP_BOOLEAN_AS_BOOL = 1U << 1, /* If set, each "b" message is written to a bool pointer. If not set, "b" is written to a int pointer. */
+};
+
int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata);
-int bus_message_map_all_properties(sd_bus_message *m, const struct bus_properties_map *map, bool copy_string, sd_bus_error *error, void *userdata);
-int bus_message_map_properties_changed(sd_bus_message *m, const struct bus_properties_map *map, bool copy_string, sd_bus_error *error, void *userdata);
-int bus_map_all_properties(sd_bus *bus, const char *destination, const char *path, const struct bus_properties_map *map, sd_bus_error *error, sd_bus_message **reply, void *userdata);
+int bus_message_map_all_properties(sd_bus_message *m, const struct bus_properties_map *map, unsigned flags, sd_bus_error *error, void *userdata);
+int bus_message_map_properties_changed(sd_bus_message *m, const struct bus_properties_map *map, unsigned flags, sd_bus_error *error, void *userdata);
+int bus_map_all_properties(sd_bus *bus, const char *destination, const char *path, const struct bus_properties_map *map,
+ unsigned flags, sd_bus_error *error, sd_bus_message **reply, void *userdata);
int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name);
"org.freedesktop.systemd1",
path,
map[arg_dependency],
+ 0,
&error,
NULL,
&info);
bus = container;
}
- r = bus_map_all_properties(bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", machine_info_property_map, NULL, NULL, mi);
+ r = bus_map_all_properties(
+ bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ machine_info_property_map,
+ BUS_MAP_STRDUP,
+ NULL,
+ NULL,
+ mi);
if (r < 0)
return r;
"org.freedesktop.systemd1",
path,
show_mode == SYSTEMCTL_SHOW_STATUS ? status_map : property_map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&reply,
&info);
if (!hn)
return log_oom();
- r = bus_map_all_properties(bus, "org.freedesktop.systemd1", "/org/freedesktop/systemd1", machine_info_property_map, &error, NULL, &mi);
+ r = bus_map_all_properties(
+ bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ machine_info_property_map,
+ BUS_MAP_STRDUP,
+ &error,
+ NULL,
+ &mi);
if (r < 0)
return log_error_errno(r, "Failed to read server status: %s", bus_error_message(&error, r));
if (r < 0)
return r;
- r = bus_map_all_properties(bus, "org.freedesktop.systemd1", path, property_map, &error, &m, &info);
+ r = bus_map_all_properties(bus, "org.freedesktop.systemd1", path, property_map, 0, &error, &m, &info);
if (r < 0)
return log_error_errno(r, "Failed to get properties: %s", bus_error_message(&error, r));
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&info);