tree-wide: make bus_map_all_properties return a proper sd_bus_error
And then show it, to make things a bit friendlier to the user if we fail acquiring some props. In fact, this fixes a number of actual bugs, where we used an error structure for output that we actually never got an error in.
This commit is contained in:
@@ -137,10 +137,8 @@ static int show_one_name(sd_bus *bus, const char* attr) {
|
||||
"org.freedesktop.hostname1",
|
||||
attr,
|
||||
&error, &reply, "s");
|
||||
if (r < 0) {
|
||||
log_error("Could not get property: %s", bus_error_message(&error, -r));
|
||||
return r;
|
||||
}
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Could not get property: %s", bus_error_message(&error, r));
|
||||
|
||||
r = sd_bus_message_read(reply, "s", &s);
|
||||
if (r < 0)
|
||||
@@ -151,7 +149,7 @@ static int show_one_name(sd_bus *bus, const char* attr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int show_all_names(sd_bus *bus) {
|
||||
static int show_all_names(sd_bus *bus, sd_bus_error *error) {
|
||||
StatusInfo info = {};
|
||||
|
||||
static const struct bus_properties_map hostname_map[] = {
|
||||
@@ -181,6 +179,7 @@ static int show_all_names(sd_bus *bus) {
|
||||
"org.freedesktop.hostname1",
|
||||
"/org/freedesktop/hostname1",
|
||||
hostname_map,
|
||||
error,
|
||||
&info);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
@@ -189,6 +188,7 @@ static int show_all_names(sd_bus *bus) {
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
manager_map,
|
||||
error,
|
||||
&info);
|
||||
|
||||
print_status_info(&info);
|
||||
@@ -212,6 +212,8 @@ fail:
|
||||
}
|
||||
|
||||
static int show_status(sd_bus *bus, char **args, unsigned n) {
|
||||
int r;
|
||||
|
||||
assert(args);
|
||||
|
||||
if (arg_pretty || arg_static || arg_transient) {
|
||||
@@ -226,8 +228,15 @@ static int show_status(sd_bus *bus, char **args, unsigned n) {
|
||||
arg_static ? "StaticHostname" : "Hostname";
|
||||
|
||||
return show_one_name(bus, attr);
|
||||
} else
|
||||
return show_all_names(bus);
|
||||
} else {
|
||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
|
||||
r = show_all_names(bus, &error);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to query system properties: %s", bus_error_message(&error, r));
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int set_simple_string(sd_bus *bus, const char *method, const char *value) {
|
||||
|
||||
Reference in New Issue
Block a user