sysctl: skip leading whitespaces and ignore arguments start with '#' when --inline
This commit is contained in:
+9
-3
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user