]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
namespace: introduce parse_protect_system()_or_bool
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 1 Jan 2018 15:10:22 +0000 (00:10 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 1 Jan 2018 17:23:13 +0000 (02:23 +0900)
src/core/load-fragment.c
src/core/namespace.c
src/core/namespace.h

index d292e4489fc50d15c714d791978cd0237c9f3095..b285264aebccf7f2aa8ebbdcab005018ea5e091b 100644 (file)
@@ -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;
 }
 
index ed02d40e512487e95d48301271e1bc5033f158ad..aed11c18ee67eb4f54e0f18ddcfe5a6bd61a6af1 100644 (file)
@@ -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",
index e497f2b65b888ff901f21fce51e24756f6b4cb74..42d841c4d291abe22d028782ae0e9ba8af905ba1 100644 (file)
@@ -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);