]> git.ipfire.org Git - thirdparty/systemd.git/commit
core: tweak handling of unknown options
authorZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Thu, 14 May 2026 16:44:29 +0000 (18:44 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@amutable.com>
Fri, 15 May 2026 07:26:48 +0000 (09:26 +0200)
commit63fc9f1696a7d2032280f0bfd8729ecf2fe425e1
treede235a3514af3445b3bf5a8df5d9aec76146e480
parentf51393716f2c4aa59b7741bfb5d7d8b1fc5fd601
core: tweak handling of unknown options

099663ff8c117303af369a4d412dafed0c5614c2 added "support" for
-b/-s/-z ARG with a comment of
> /* Just to eat away the sysvinit kernel cmdline args without getopt()
>  * error messages that we'll parse in parse_proc_cmdline_word() or
>  * ignore. */
And for PID1 those was valid. But when not running as PID1, those
options would be parsed as valid but then help() would immediately
return -EINVAL:
  $ build-old/systemd -b; echo $?
  1

At the same time, when running as PID1, if we encounter an error,
we shouldn't opine about the rest of the command line. So continuing
with the loop and the checks after the loop were iffy.

Later, cd57038a30aa9447bde3af7111ac8dc517b38bbf made a big refactoring,
and the 'break' (i.e. continuation of the loop) was changed to 'return 0',
making things even more confusing, since now we'd just silently stop in
the middle of the command line if -b/-s/-z were encountered.

So be more careful: when running as PID1, stop parsing on error
and return from the function. We didn't parse the full command line,
so the later checks are not useful. Silently ignore -b/-s/-z.
When not running as PID1, explicitly say that -b/-s/-z are not
supported, and propogate the error if parsing fails, e.g. with
an unknown option.
src/core/main.c