From: Krzesimir Nowak Date: Thu, 11 Apr 2024 11:49:54 +0000 (+0200) Subject: sysext: Use string table for parsing mutable mode X-Git-Tag: v256-rc1~86^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e8f4d92b4786310f7c6ae5d4ae3ea1d28a33470;p=thirdparty%2Fsystemd.git sysext: Use string table for parsing mutable mode --- diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index b8753083bff..8c6a5a882f6 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(