]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
runtime-scope: add helper that turns RuntimeScope enum into --system/--user string 26737/head
authorLennart Poettering <lennart@poettering.net>
Thu, 9 Mar 2023 16:41:25 +0000 (17:41 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 10 Mar 2023 08:47:58 +0000 (09:47 +0100)
src/basic/runtime-scope.c
src/basic/runtime-scope.h
src/core/main.c
src/systemctl/systemctl-start-special.c

index 88afb53d0bf7439742d92eff9231880d254f1960..3d653d6cefc572f2cb0c3b2f8614505d5d34ff50 100644 (file)
@@ -10,3 +10,11 @@ static const char* const runtime_scope_table[_RUNTIME_SCOPE_MAX] = {
 };
 
 DEFINE_STRING_TABLE_LOOKUP(runtime_scope, RuntimeScope);
+
+static const char* const runtime_scope_cmdline_option_table[_RUNTIME_SCOPE_MAX] = {
+        [RUNTIME_SCOPE_SYSTEM] = "--system",
+        [RUNTIME_SCOPE_USER]   = "--user",
+        [RUNTIME_SCOPE_GLOBAL] = "--global",
+};
+
+DEFINE_STRING_TABLE_LOOKUP_TO_STRING(runtime_scope_cmdline_option, RuntimeScope);
index 6a7f9e65d49d1774d046f4694d7cf2edc14e2bf4..6553e4c19993a026b189fade3a917cd9b9d19f9e 100644 (file)
@@ -15,3 +15,5 @@ typedef enum RuntimeScope {
 
 const char *runtime_scope_to_string(RuntimeScope scope) _const_;
 RuntimeScope runtime_scope_from_string(const char *s) _const_;
+
+const char *runtime_scope_cmdline_option_to_string(RuntimeScope scope) _const_;
index 29302a6de9a6c256798acfd91fc90cf528a2515b..3f63150f31351303a84eef0dd4cd8d7b58379352 100644 (file)
@@ -1867,7 +1867,7 @@ static int do_reexecute(
 
                 if (switch_root_dir)
                         args[i++] = "--switched-root";
-                args[i++] = arg_runtime_scope == RUNTIME_SCOPE_SYSTEM ? "--system" : "--user";
+                args[i++] = runtime_scope_cmdline_option_to_string(arg_runtime_scope);
                 args[i++] = "--deserialize";
                 args[i++] = sfd;
                 args[i++] = NULL;
index 90b1e2ae0dfdf4719f5cbac5e0d3b1940d94469c..1c50adff6ed803bebcaf718092a9654a301d7594 100644 (file)
@@ -238,7 +238,7 @@ int verb_start_system_special(int argc, char *argv[], void *userdata) {
         if (arg_runtime_scope != RUNTIME_SCOPE_SYSTEM)
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "Bad action for %s mode.",
-                                       arg_runtime_scope == RUNTIME_SCOPE_GLOBAL ? "--global" : "--user");
+                                       runtime_scope_cmdline_option_to_string(arg_runtime_scope));
 
         return verb_start_special(argc, argv, userdata);
 }