]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysctl: add --inline option
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 5 Oct 2025 17:29:39 +0000 (02:29 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 5 Oct 2025 18:17:23 +0000 (03:17 +0900)
This maybe useful to apply a simple configuration without creating conf
file.

man/systemd-sysctl.service.xml
src/sysctl/sysctl.c

index 0702fa87ce41ded449fb40a4ff8fb936da6d7422..61fe5238b7306ed0e99db7a6e45f2e9b2e0bd1ed 100644 (file)
         </listitem>
       </varlistentry>
 
+      <varlistentry>
+        <term><option>--inline</option></term>
+        <listitem><para>Treat each positional argument as a separate configuration line instead of a file
+        name.</para>
+
+        <xi:include href="version-info.xml" xpointer="v259"/></listitem>
+      </varlistentry>
+
       <xi:include href="standard-options.xml" xpointer="cat-config" />
       <xi:include href="standard-options.xml" xpointer="tldr" />
       <xi:include href="standard-options.xml" xpointer="no-pager" />
index 4e0c977c938869d2364c8ba8e9a26280cbd846a7..d761c7375a20f70898258e20f7ce33db0b6565a0 100644 (file)
@@ -26,6 +26,7 @@
 static char **arg_prefixes = NULL;
 static CatFlags arg_cat_flags = CAT_CONFIG_OFF;
 static bool arg_strict = false;
+static bool arg_inline = false;
 static PagerFlags arg_pager_flags = 0;
 
 STATIC_DESTRUCTOR_REGISTER(arg_prefixes, strv_freep);
@@ -332,6 +333,7 @@ static int help(void) {
                "     --prefix=PATH      Only apply rules with the specified prefix\n"
                "     --no-pager         Do not pipe output into a pager\n"
                "     --strict           Fail on any kind of failures\n"
+               "     --inline           Treat arguments as configuration lines\n"
                "\nSee the %5$s for details.\n",
                program_invocation_short_name,
                ansi_highlight(),
@@ -351,6 +353,7 @@ static int parse_argv(int argc, char *argv[]) {
                 ARG_PREFIX,
                 ARG_NO_PAGER,
                 ARG_STRICT,
+                ARG_INLINE,
         };
 
         static const struct option options[] = {
@@ -361,6 +364,7 @@ static int parse_argv(int argc, char *argv[]) {
                 { "prefix",     required_argument, NULL, ARG_PREFIX     },
                 { "no-pager",   no_argument,       NULL, ARG_NO_PAGER   },
                 { "strict",     no_argument,       NULL, ARG_STRICT     },
+                { "inline",     no_argument,       NULL, ARG_INLINE     },
                 {}
         };
 
@@ -416,6 +420,10 @@ static int parse_argv(int argc, char *argv[]) {
                         arg_strict = true;
                         break;
 
+                case ARG_INLINE:
+                        arg_inline = true;
+                        break;
+
                 case '?':
                         return -EINVAL;
 
@@ -443,11 +451,15 @@ static int run(int argc, char *argv[]) {
         umask(0022);
 
         if (argc > optind) {
-                r = 0;
-
-                for (int i = optind; i < argc; i++)
-                        RET_GATHER(r, parse_file(&sysctl_options, argv[i], false));
-
+                unsigned pos = 0;
+
+                STRV_FOREACH(arg, strv_skip(argv, optind)) {
+                        if (arg_inline)
+                                /* Use (argument):n, where n==1 for the first positional arg */
+                                RET_GATHER(r, parse_line("(argument)", ++pos, *arg, /* invalid_config = */ NULL, &sysctl_options));
+                        else
+                                RET_GATHER(r, parse_file(&sysctl_options, *arg, false));
+                }
         } else {
                 _cleanup_strv_free_ char **files = NULL;