bus-util: unify loop around bus_append_unit_property_assignment()
This is done exactly the same way a couple of times at various places, let's unify this into one version.
This commit is contained in:
parent
622a0f628c
commit
8673cf13c0
|
@ -68,7 +68,6 @@ int register_machine(
|
|||
local_ifindex > 0 ? 1 : 0, local_ifindex);
|
||||
} else {
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
|
||||
char **i;
|
||||
unsigned j;
|
||||
|
||||
r = sd_bus_message_new_method_call(
|
||||
|
@ -157,11 +156,9 @@ int register_machine(
|
|||
return bus_log_create_error(r);
|
||||
}
|
||||
|
||||
STRV_FOREACH(i, properties) {
|
||||
r = bus_append_unit_property_assignment(m, *i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
r = bus_append_unit_property_assignment_many(m, properties);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
|
|
|
@ -410,18 +410,15 @@ static int parse_argv(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
static int transient_unit_set_properties(sd_bus_message *m, char **properties) {
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
r = sd_bus_message_append(m, "(sv)", "Description", "s", arg_description);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
STRV_FOREACH(i, properties) {
|
||||
r = bus_append_unit_property_assignment(m, *i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
r = bus_append_unit_property_assignment_many(m, properties);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -568,6 +568,21 @@ finish:
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bus_append_unit_property_assignment_many(sd_bus_message *m, char **l) {
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
assert(m);
|
||||
|
||||
STRV_FOREACH(i, l) {
|
||||
r = bus_append_unit_property_assignment(m, *i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct BusWaitForJobs {
|
||||
sd_bus *bus;
|
||||
Set *jobs;
|
||||
|
|
|
@ -41,6 +41,7 @@ typedef struct UnitInfo {
|
|||
int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u);
|
||||
|
||||
int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignment);
|
||||
int bus_append_unit_property_assignment_many(sd_bus_message *m, char **l);
|
||||
|
||||
typedef struct BusWaitForJobs BusWaitForJobs;
|
||||
|
||||
|
|
|
@ -5093,7 +5093,6 @@ static int set_property(int argc, char *argv[], void *userdata) {
|
|||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||
_cleanup_free_ char *n = NULL;
|
||||
sd_bus *bus;
|
||||
char **i;
|
||||
int r;
|
||||
|
||||
r = acquire_bus(BUS_MANAGER, &bus);
|
||||
|
@ -5124,11 +5123,9 @@ static int set_property(int argc, char *argv[], void *userdata) {
|
|||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
|
||||
STRV_FOREACH(i, strv_skip(argv, 2)) {
|
||||
r = bus_append_unit_property_assignment(m, *i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
r = bus_append_unit_property_assignment_many(m, strv_skip(argv, 2));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
|
|
Loading…
Reference in a new issue