shared/bus-unit-util: define helper for conditions and asserts
The function has "try" in the name because it dynamically checks if the field name matches.
This commit is contained in:
+36
-34
@@ -2236,6 +2236,41 @@ static int bus_append_timers_calendar(sd_bus_message *m, const char *field, cons
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int bus_try_append_condition(sd_bus_message *m, const char *field, const char *eq) {
|
||||
bool is_condition = false;
|
||||
int r;
|
||||
|
||||
ConditionType t = condition_type_from_string(field);
|
||||
if (t >= 0)
|
||||
is_condition = true;
|
||||
else
|
||||
t = assert_type_from_string(field);
|
||||
if (t >= 0) {
|
||||
if (isempty(eq))
|
||||
r = sd_bus_message_append(m, "(sv)", is_condition ? "Conditions" : "Asserts", "a(sbbs)", 0);
|
||||
else {
|
||||
const char *p = eq;
|
||||
|
||||
int trigger = *p == '|';
|
||||
if (trigger)
|
||||
p++;
|
||||
|
||||
int negate = *p == '!';
|
||||
if (negate)
|
||||
p++;
|
||||
|
||||
r = sd_bus_message_append(m, "(sv)", is_condition ? "Conditions" : "Asserts", "a(sbbs)", 1,
|
||||
field, trigger, negate, p);
|
||||
}
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bus_append_cgroup_property(sd_bus_message *m, const char *field, const char *eq) {
|
||||
if (STR_IN_SET(field, "DevicePolicy",
|
||||
"Slice",
|
||||
@@ -2888,10 +2923,6 @@ static int bus_append_timer_property(sd_bus_message *m, const char *field, const
|
||||
}
|
||||
|
||||
static int bus_append_unit_property(sd_bus_message *m, const char *field, const char *eq) {
|
||||
ConditionType t = _CONDITION_TYPE_INVALID;
|
||||
bool is_condition = false;
|
||||
int r;
|
||||
|
||||
if (STR_IN_SET(field, "Description",
|
||||
"SourcePath",
|
||||
"OnFailureJobMode",
|
||||
@@ -2932,36 +2963,7 @@ static int bus_append_unit_property(sd_bus_message *m, const char *field, const
|
||||
"Markers"))
|
||||
return bus_append_strv(m, field, eq);
|
||||
|
||||
t = condition_type_from_string(field);
|
||||
if (t >= 0)
|
||||
is_condition = true;
|
||||
else
|
||||
t = assert_type_from_string(field);
|
||||
if (t >= 0) {
|
||||
if (isempty(eq))
|
||||
r = sd_bus_message_append(m, "(sv)", is_condition ? "Conditions" : "Asserts", "a(sbbs)", 0);
|
||||
else {
|
||||
const char *p = eq;
|
||||
int trigger, negate;
|
||||
|
||||
trigger = *p == '|';
|
||||
if (trigger)
|
||||
p++;
|
||||
|
||||
negate = *p == '!';
|
||||
if (negate)
|
||||
p++;
|
||||
|
||||
r = sd_bus_message_append(m, "(sv)", is_condition ? "Conditions" : "Asserts", "a(sbbs)", 1,
|
||||
field, trigger, negate, p);
|
||||
}
|
||||
if (r < 0)
|
||||
return bus_log_create_error(r);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return bus_try_append_condition(m, field, eq);
|
||||
}
|
||||
|
||||
int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const char *assignment) {
|
||||
|
||||
Reference in New Issue
Block a user