summaryrefslogtreecommitdiffstats
path: root/src/run
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-21 02:05:33 +0100
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-29 03:34:41 +0200
commitef9c12b157a50d63e8a8eb710c013d16c2cea319 (patch)
tree62406cd13da67e6aadd80b2fad3bf2b5d31aa313 /src/run
parentcondition: use proc_cmdline_strv() (diff)
downloadsystemd-ef9c12b157a50d63e8a8eb710c013d16c2cea319.tar.xz
systemd-ef9c12b157a50d63e8a8eb710c013d16c2cea319.zip
tree-wide: reset optind to 0 when GNU extensions in optstring are used
Otherwise, if getopt() and friends are used before parse_argv(), then the GNU extensions may be ignored. This should not change any behavior at least now, as we usually use getopt_long() only once per invocation. But in the next commit, getopt_long() will be used for other arrays, hence this change will become necessary.
Diffstat (limited to 'src/run')
-rw-r--r--src/run/run.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/run/run.c b/src/run/run.c
index 8377c2e8cd..ee4a151a4a 100644
--- a/src/run/run.c
+++ b/src/run/run.c
@@ -242,6 +242,9 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
+ /* Resetting to 0 forces the invocation of an internal initialization routine of getopt_long()
+ * that checks for GNU extensions in optstring ('-' or '+' at the beginning). */
+ optind = 0;
while ((c = getopt_long(argc, argv, "+hrH:M:E:p:tPqGdSu:", options, NULL)) >= 0)
switch (c) {