From: Yu Watanabe Date: Mon, 1 Jan 2018 15:10:22 +0000 (+0900) Subject: namespace: introduce parse_protect_system()_or_bool X-Git-Tag: v237~157^2~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=03c791aa24f9319d0fe85a9223174cf60bb26f9a;p=thirdparty%2Fsystemd.git namespace: introduce parse_protect_system()_or_bool --- diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index d292e4489fc..b285264aebc 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -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; } diff --git a/src/core/namespace.c b/src/core/namespace.c index ed02d40e512..aed11c18ee6 100644 --- a/src/core/namespace.c +++ b/src/core/namespace.c @@ -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", diff --git a/src/core/namespace.h b/src/core/namespace.h index e497f2b65b8..42d841c4d29 100644 --- a/src/core/namespace.h +++ b/src/core/namespace.h @@ -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);