diff options
author | Krzesimir Nowak <knowak@microsoft.com> | 2024-04-11 13:49:54 +0200 |
---|---|---|
committer | Krzesimir Nowak <knowak@microsoft.com> | 2024-04-19 07:21:02 +0200 |
commit | 3e8f4d92b4786310f7c6ae5d4ae3ea1d28a33470 (patch) | |
tree | ac6d70fd540eae5b4781a4220e2269ede5ff4e91 /src/sysext | |
parent | test: Do not limit hierarchies (diff) | |
download | systemd-3e8f4d92b4786310f7c6ae5d4ae3ea1d28a33470.tar.xz systemd-3e8f4d92b4786310f7c6ae5d4ae3ea1d28a33470.zip |
sysext: Use string table for parsing mutable mode
Diffstat (limited to 'src/sysext')
-rw-r--r-- | src/sysext/sysext.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index b8753083bf..8c6a5a882f 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -44,6 +44,7 @@ #include "process-util.h" #include "rm-rf.h" #include "sort-util.h" +#include "string-table.h" #include "string-util.h" #include "terminal-util.h" #include "user-util.h" @@ -52,8 +53,8 @@ #include "verbs.h" typedef enum MutableMode { - MUTABLE_YES, MUTABLE_NO, + MUTABLE_YES, MUTABLE_AUTO, MUTABLE_IMPORT, MUTABLE_EPHEMERAL, @@ -62,6 +63,17 @@ typedef enum MutableMode { _MUTABLE_INVALID = -EINVAL, } MutableMode; +static const char* const mutable_mode_table[_MUTABLE_MAX] = { + [MUTABLE_NO] = "no", + [MUTABLE_YES] = "yes", + [MUTABLE_AUTO] = "auto", + [MUTABLE_IMPORT] = "import", + [MUTABLE_EPHEMERAL] = "ephemeral", + [MUTABLE_EPHEMERAL_IMPORT] = "ephemeral-import", +}; + +DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(mutable_mode, MutableMode, MUTABLE_YES); + static char **arg_hierarchies = NULL; /* "/usr" + "/opt" by default for sysext and /etc by default for confext */ static char *arg_root = NULL; static JsonFormatFlags arg_json_format_flags = JSON_FORMAT_OFF; @@ -127,27 +139,7 @@ static const struct { }; static int parse_mutable_mode(const char *p) { - int r; - - assert(p); - - if (streq(p, "auto")) - return MUTABLE_AUTO; - - if (streq(p, "import")) - return MUTABLE_IMPORT; - - if (streq(p, "ephemeral")) - return MUTABLE_EPHEMERAL; - - if (streq(p, "ephemeral-import")) - return MUTABLE_EPHEMERAL_IMPORT; - - r = parse_boolean(p); - if (r < 0) - return r; - - return r ? MUTABLE_YES : MUTABLE_NO; + return mutable_mode_from_string(p); } static int is_our_mount_point( |