summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-02-01 21:31:44 +0100
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commitda9c99f94c4f13ac9e19c41b67c1b8fac3f69d6b (patch)
treeafeb5480606c71cbf7dcc789a306e7a33eb1fe34 /src/shared
parent0f23ea0bef55d39322dcd3b73a7613efaa8e5b61 (diff)
shared: simplify parsing of bus properties a bit
Let's write the property name and value in one call, when that's possible, shorthing our code a bit.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/bus-util.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index 5b7b48baf..ee6af0a32 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -1409,15 +1409,9 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
if (streq(field, "CPUQuota")) {
- if (isempty(eq)) {
-
- r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, "CPUQuotaPerSecUSec");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "v", "t", USEC_INFINITY);
-
- } else if (endswith(eq, "%")) {
+ if (isempty(eq))
+ r = sd_bus_message_append(m, "sv", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
+ else if (endswith(eq, "%")) {
double percent;
if (sscanf(eq, "%lf%%", &percent) != 1 || percent <= 0) {
@@ -1425,11 +1419,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
return -EINVAL;
}
- r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, "CPUQuotaPerSecUSec");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "v", "t", (usec_t) percent * USEC_PER_SEC / 100);
+ r = sd_bus_message_append(m, "sv", "CPUQuotaPerSecUSec", "t", (usec_t) percent * USEC_PER_SEC / 100);
} else {
log_error("CPU quota needs to be in percent.");
return -EINVAL;
@@ -1442,11 +1432,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
} else if (streq(field, "EnvironmentFile")) {
- r = sd_bus_message_append_basic(m, SD_BUS_TYPE_STRING, "EnvironmentFiles");
- if (r < 0)
- return bus_log_create_error(r);
-
- r = sd_bus_message_append(m, "v", "a(sb)", 1,
+ r = sd_bus_message_append(m, "sv", "EnvironmentFiles", "a(sb)", 1,
eq[0] == '-' ? eq + 1 : eq,
eq[0] == '-');
if (r < 0)