From 1c223728cf404d7d5c1802e0d5b149b966a80e0e Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 8 Aug 2026 19:45:18 +0900 Subject: [PATCH] sysctl: skip leading whitespaces and ignore arguments start with '#' when --inline --- src/sysctl/sysctl.c | 12 +++++++++--- test/units/TEST-87-AUX-UTILS-VM.sysctl.sh | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index b4d63635a5..f14f885773 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -425,10 +425,16 @@ static int run(int argc, char *argv[]) { unsigned pos = 0; STRV_FOREACH(arg, args) { - if (arg_inline) + if (arg_inline) { + pos++; + + const char *s = skip_leading_chars(*arg, /* bad= */ NULL); + if (IN_SET(*s, '\0', '#')) + continue; + /* 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_line("(argument)", pos, s, /* invalid_config= */ NULL, &sysctl_options)); + } else RET_GATHER(r, parse_file(&sysctl_options, *arg, false)); } } else { diff --git a/test/units/TEST-87-AUX-UTILS-VM.sysctl.sh b/test/units/TEST-87-AUX-UTILS-VM.sysctl.sh index 8333ce9787..fe1b5f1b33 100755 --- a/test/units/TEST-87-AUX-UTILS-VM.sysctl.sh +++ b/test/units/TEST-87-AUX-UTILS-VM.sysctl.sh @@ -17,7 +17,7 @@ assert_rc 0 /usr/lib/systemd/systemd-sysctl /tmp/foo.conf assert_rc 0 /usr/lib/systemd/systemd-sysctl --strict /tmp/foo.conf assert_rc 1 /usr/lib/systemd/systemd-sysctl --inline -assert_rc 0 /usr/lib/systemd/systemd-sysctl --inline "foo.bar=42" +assert_rc 0 /usr/lib/systemd/systemd-sysctl --inline " foo.bar=42" "#comment" " " assert_rc 1 /usr/lib/systemd/systemd-sysctl --inline --strict "foo.bar=42" assert_rc 0 /usr/lib/systemd/systemd-sysctl --inline -- "-foo.bar=42" assert_rc 0 /usr/lib/systemd/systemd-sysctl --inline --strict -- "-foo.bar=42"