summaryrefslogtreecommitdiff
path: root/src/userdb
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-03-21 10:05:33 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-03-29 10:34:41 +0900
commitef9c12b157a50d63e8a8eb710c013d16c2cea319 (patch)
tree62406cd13da67e6aadd80b2fad3bf2b5d31aa313 /src/userdb
parentdd2d3e975e80f5ae3b64bd9c2b63d866415c764e (diff)
downloadsystemd-ef9c12b157a50d63e8a8eb710c013d16c2cea319.tar.gz
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/userdb')
-rw-r--r--src/userdb/userdbctl.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c
index eab0c3af15..67675b4b7f 100644
--- a/src/userdb/userdbctl.c
+++ b/src/userdb/userdbctl.c
@@ -1150,6 +1150,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_services = l;
}
+ /* 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;
+
for (;;) {
int c;