From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] xap_helper: reset getopt(3) properly in workers
Date: Mon, 13 Nov 2023 05:00:39 +0000 [thread overview]
Message-ID: <20231113050039.22817-1-e@80x24.org> (raw)
I only noticed this while doing a full -cindex --associate with
--associate-date-range=30.years.ago and --associate-max=-1 (no
limit for Xapian) between local mirrors of lore and
git.kernel.org my glibc-based system.
Apparently, glibc requires `optind = 0' to reset getopt(3) in
our workers. Oddly, glibc appeared to work fine prior to this
change for the defaults (--associate-date-range=1.year.ago..
and --associate-max=50000).
BSDs and musl have an `optreset' variable which appear to do
the same thing, but I don't have space on BSD VMs to test full
associations.
While we're at it, we'll also keep `opterr' enabled to improve
error reporting.
---
lib/PublicInbox/xap_helper.h | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/xap_helper.h b/lib/PublicInbox/xap_helper.h
index fafb392d..8602170f 100644
--- a/lib/PublicInbox/xap_helper.h
+++ b/lib/PublicInbox/xap_helper.h
@@ -58,6 +58,12 @@
# define SET_MAX_EXPANSION set_max_wildcard_expansion
#endif
+#if defined(__GLIBC__)
+# define MY_DO_OPTRESET() do { optind = 0; } while (0)
+#else /* FreeBSD, musl, dfly, NetBSD, OpenBSD */
+# define MY_DO_OPTRESET() do { optind = optreset = 1; } while (0)
+#endif
+
#if defined(__FreeBSD__) || defined(__GLIBC__)
# define STDERR_ASSIGNABLE (1)
#else
@@ -807,9 +813,9 @@ static void dispatch(struct req *req)
fwrite(&req->argv[0], offsetof(struct srch, paths), 1, kfp);
// global getopt variables:
- optind = 1;
- opterr = optopt = 0;
+ optopt = 0;
optarg = NULL;
+ MY_DO_OPTRESET();
// keep sync with @PublicInbox::XapHelper::SPEC
while ((c = getopt(req->argc, req->argv, "acd:k:m:o:rtA:O:T:")) != -1) {
reply other threads:[~2023-11-13 5:02 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231113050039.22817-1-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).