sysctl: skip leading whitespaces and ignore arguments start with '#' when --inline

This commit is contained in:
Yu Watanabe
2026-08-21 00:40:53 +09:00
parent 5c76cb0e27
commit 1c223728cf
2 changed files with 10 additions and 4 deletions
+9 -3
View File
@@ -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 {
+1 -1
View File
@@ -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"