namespace: introduce parse_protect_system()_or_bool
This commit is contained in:
@@ -4399,7 +4399,7 @@ int config_parse_protect_system(
|
||||
void *userdata) {
|
||||
|
||||
ExecContext *c = data;
|
||||
int k;
|
||||
ProtectSystem s;
|
||||
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
@@ -4409,23 +4409,14 @@ int config_parse_protect_system(
|
||||
/* Our enum shall be a superset of booleans, hence first try
|
||||
* to parse as boolean, and then as enum */
|
||||
|
||||
k = parse_boolean(rvalue);
|
||||
if (k > 0)
|
||||
c->protect_system = PROTECT_SYSTEM_YES;
|
||||
else if (k == 0)
|
||||
c->protect_system = PROTECT_SYSTEM_NO;
|
||||
else {
|
||||
ProtectSystem s;
|
||||
|
||||
s = protect_system_from_string(rvalue);
|
||||
if (s < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse protect system value, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
c->protect_system = s;
|
||||
s = parse_protect_system_or_bool(rvalue);
|
||||
if (s < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse protect system value, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
c->protect_system = s;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1471,6 +1471,18 @@ static const char *const protect_system_table[_PROTECT_SYSTEM_MAX] = {
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(protect_system, ProtectSystem);
|
||||
|
||||
ProtectSystem parse_protect_system_or_bool(const char *s) {
|
||||
int r;
|
||||
|
||||
r = parse_boolean(s);
|
||||
if (r > 0)
|
||||
return PROTECT_SYSTEM_YES;
|
||||
if (r == 0)
|
||||
return PROTECT_SYSTEM_NO;
|
||||
|
||||
return protect_system_from_string(s);
|
||||
}
|
||||
|
||||
static const char* const namespace_type_table[] = {
|
||||
[NAMESPACE_MOUNT] = "mnt",
|
||||
[NAMESPACE_CGROUP] = "cgroup",
|
||||
|
||||
@@ -105,6 +105,7 @@ ProtectHome parse_protect_home_or_bool(const char *s);
|
||||
|
||||
const char* protect_system_to_string(ProtectSystem p) _const_;
|
||||
ProtectSystem protect_system_from_string(const char *s) _pure_;
|
||||
ProtectSystem parse_protect_system_or_bool(const char *s);
|
||||
|
||||
void bind_mount_free_many(BindMount *b, unsigned n);
|
||||
int bind_mount_add(BindMount **b, unsigned *n, const BindMount *item);
|
||||
|
||||
Reference in New Issue
Block a user