summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/analyze/analyze.c2
-rw-r--r--src/hostname/hostnamectl.c2
-rw-r--r--src/locale/localectl.c1
-rw-r--r--src/login/loginctl.c6
-rw-r--r--src/machine/machinectl.c3
-rw-r--r--src/resolve/resolve-tool.c2
-rw-r--r--src/run/run.c1
-rw-r--r--src/shared/bus-util.c25
-rw-r--r--src/shared/bus-util.h12
-rw-r--r--src/systemctl/systemctl.c24
-rw-r--r--src/timedate/timedatectl.c1
11 files changed, 60 insertions, 19 deletions
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index 22f634ac5c..74f4d545ea 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -473,6 +473,7 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
hostname_map,
+ BUS_MAP_STRDUP,
&error,
NULL,
host);
@@ -483,6 +484,7 @@ static int acquire_host_info(sd_bus *bus, struct host_info **hi) {
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
manager_map,
+ BUS_MAP_STRDUP,
&error,
NULL,
host);
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index baa48c7f71..b230277496 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -170,6 +170,7 @@ static int show_all_names(sd_bus *bus, sd_bus_error *error) {
"org.freedesktop.hostname1",
"/org/freedesktop/hostname1",
hostname_map,
+ 0,
error,
&host_message,
&info);
@@ -180,6 +181,7 @@ static int show_all_names(sd_bus *bus, sd_bus_error *error) {
"org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
manager_map,
+ 0,
error,
&manager_message,
&info);
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 550e97b3ed..b068990b22 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -162,6 +162,7 @@ static int show_status(int argc, char **argv, void *userdata) {
"org.freedesktop.locale1",
"/org/freedesktop/locale1",
map,
+ 0,
&error,
&m,
&info);
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 7554faeda3..6ad0a277c9 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -439,7 +439,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li
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));
@@ -570,7 +570,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line)
_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));
@@ -644,7 +644,7 @@ static int print_seat_status_info(sd_bus *bus, const char *path, bool *new_line)
_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));
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 78a7ce2fa3..fc194929a1 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -811,6 +811,7 @@ static int show_machine_info(const char *verb, sd_bus *bus, const char *path, bo
"org.freedesktop.machine1",
path,
map,
+ 0,
&error,
&m,
&info);
@@ -1092,6 +1093,7 @@ static int show_image_info(sd_bus *bus, const char *path, bool *new_line) {
"org.freedesktop.machine1",
path,
map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&info);
@@ -1152,6 +1154,7 @@ static int show_pool_info(sd_bus *bus) {
"org.freedesktop.machine1",
"/org/freedesktop/machine1",
map,
+ 0,
&error,
&m,
&info);
diff --git a/src/resolve/resolve-tool.c b/src/resolve/resolve-tool.c
index 9208bf1167..49c34bc09b 100644
--- a/src/resolve/resolve-tool.c
+++ b/src/resolve/resolve-tool.c
@@ -1235,6 +1235,7 @@ static int status_ifindex(sd_bus *bus, int ifindex, const char *name, bool *empt
"org.freedesktop.resolve1",
p,
property_map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&link_info);
@@ -1446,6 +1447,7 @@ static int status_global(sd_bus *bus, bool *empty_line) {
"org.freedesktop.resolve1",
"/org/freedesktop/resolve1",
property_map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&global_info);
diff --git a/src/run/run.c b/src/run/run.c
index 1da185dde9..f5914f7d64 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -875,6 +875,7 @@ static int run_context_update(RunContext *c, const char *path) {
"org.freedesktop.systemd1",
path,
map,
+ BUS_MAP_STRDUP,
&error,
NULL,
c);
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;
diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h
index e42198ff1c..eb9fae7228 100644
--- a/src/shared/bus-util.h
+++ b/src/shared/bus-util.h
@@ -49,11 +49,17 @@ struct bus_properties_map {
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);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index d23bddc99a..42fbb35541 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1686,6 +1686,7 @@ static int list_dependencies_get_dependencies(sd_bus *bus, const char *name, cha
"org.freedesktop.systemd1",
path,
map[arg_dependency],
+ 0,
&error,
NULL,
&info);
@@ -1892,7 +1893,15 @@ static int get_machine_properties(sd_bus *bus, struct machine_info *mi) {
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;
@@ -5018,6 +5027,7 @@ static int show_one(
"org.freedesktop.systemd1",
path,
show_mode == SYSTEMCTL_SHOW_STATUS ? status_map : property_map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&reply,
&info);
@@ -5151,7 +5161,15 @@ static int show_system_status(sd_bus *bus) {
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));
@@ -6090,7 +6108,7 @@ static int unit_exists(LookupPaths *lp, const char *unit) {
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));
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index a9bb8aacde..cd44019934 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -161,6 +161,7 @@ static int show_status(int argc, char **argv, void *userdata) {
"org.freedesktop.timedate1",
"/org/freedesktop/timedate1",
map,
+ BUS_MAP_BOOLEAN_AS_BOOL,
&error,
&m,
&info);