mirror of
https://github.com/systemd/systemd.git
synced 2026-08-04 15:10:33 +00:00
parse-util: add parse_tristate() and use it everywhere
We parse tristates all the time, let's add an explicit parser for them.
This commit is contained in:
committed by
Yu Watanabe
parent
6a4d0efa00
commit
b71a721fbc
@@ -859,8 +859,7 @@ int config_parse_macsec_sa_activate(
|
||||
_cleanup_(macsec_transmit_association_free_or_set_invalidp) TransmitAssociation *a = NULL;
|
||||
_cleanup_(macsec_receive_association_free_or_set_invalidp) ReceiveAssociation *b = NULL;
|
||||
MACsec *s = userdata;
|
||||
int *dest;
|
||||
int r;
|
||||
int *dest, r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
@@ -877,21 +876,16 @@ int config_parse_macsec_sa_activate(
|
||||
|
||||
dest = a ? &a->sa.activate : &b->sa.activate;
|
||||
|
||||
if (isempty(rvalue))
|
||||
r = -1;
|
||||
else {
|
||||
r = parse_boolean(rvalue);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse activation mode of %s security association. "
|
||||
"Ignoring assignment: %s",
|
||||
streq(section, "MACsecTransmitAssociation") ? "transmit" : "receive",
|
||||
rvalue);
|
||||
return 0;
|
||||
}
|
||||
r = parse_tristate(rvalue, dest);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse activation mode of %s security association. "
|
||||
"Ignoring assignment: %s",
|
||||
streq(section, "MACsecTransmitAssociation") ? "transmit" : "receive",
|
||||
rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*dest = r;
|
||||
TAKE_PTR(a);
|
||||
TAKE_PTR(b);
|
||||
|
||||
@@ -930,7 +924,7 @@ int config_parse_macsec_use_for_encoding(
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, &a->sa.use_for_encoding);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse %s= setting. Ignoring assignment: %s",
|
||||
@@ -938,7 +932,6 @@ int config_parse_macsec_use_for_encoding(
|
||||
return 0;
|
||||
}
|
||||
|
||||
a->sa.use_for_encoding = r;
|
||||
if (a->sa.use_for_encoding > 0)
|
||||
a->sa.activate = true;
|
||||
|
||||
|
||||
@@ -1229,21 +1229,13 @@ int config_parse_nexthop_onlink(
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
n->onlink = -1;
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, &n->onlink);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n->onlink = r;
|
||||
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -354,13 +354,7 @@ int config_parse_cake_tristate(
|
||||
else
|
||||
assert_not_reached();
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*dest = -1;
|
||||
TAKE_PTR(qdisc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, dest);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse '%s=', ignoring assignment: %s",
|
||||
@@ -368,7 +362,6 @@ int config_parse_cake_tristate(
|
||||
return 0;
|
||||
}
|
||||
|
||||
*dest = r;
|
||||
TAKE_PTR(qdisc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -223,14 +223,7 @@ int config_parse_controlled_delay_bool(
|
||||
|
||||
cd = CODEL(qdisc);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
cd->ecn = -1;
|
||||
|
||||
qdisc = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, &cd->ecn);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse '%s=', ignoring assignment: %s",
|
||||
@@ -238,8 +231,7 @@ int config_parse_controlled_delay_bool(
|
||||
return 0;
|
||||
}
|
||||
|
||||
cd->ecn = r;
|
||||
qdisc = NULL;
|
||||
TAKE_PTR(qdisc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -251,14 +251,7 @@ int config_parse_fair_queueing_controlled_delay_bool(
|
||||
|
||||
fqcd = FQ_CODEL(qdisc);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
fqcd->ecn = -1;
|
||||
|
||||
TAKE_PTR(qdisc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, &fqcd->ecn);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse '%s=', ignoring assignment: %s",
|
||||
@@ -266,7 +259,6 @@ int config_parse_fair_queueing_controlled_delay_bool(
|
||||
return 0;
|
||||
}
|
||||
|
||||
fqcd->ecn = r;
|
||||
TAKE_PTR(qdisc);
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -267,14 +267,7 @@ int config_parse_fair_queueing_bool(
|
||||
|
||||
fq = FQ(qdisc);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
fq->pacing = -1;
|
||||
|
||||
qdisc = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, &fq->pacing);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse '%s=', ignoring assignment: %s",
|
||||
@@ -283,7 +276,7 @@ int config_parse_fair_queueing_bool(
|
||||
}
|
||||
|
||||
fq->pacing = r;
|
||||
qdisc = NULL;
|
||||
TAKE_PTR(qdisc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -163,14 +163,7 @@ int config_parse_generic_random_early_detection_bool(
|
||||
|
||||
gred = GRED(qdisc);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
gred->grio = -1;
|
||||
|
||||
TAKE_PTR(qdisc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
r = parse_tristate(rvalue, &gred->grio);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to parse '%s=', ignoring assignment: %s",
|
||||
@@ -178,7 +171,6 @@ int config_parse_generic_random_early_detection_bool(
|
||||
return 0;
|
||||
}
|
||||
|
||||
gred->grio = r;
|
||||
TAKE_PTR(qdisc);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user