about summary refs log tree commit homepage
path: root/lib/PublicInbox
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2023-11-13 05:00:39 +0000
committerEric Wong <e@80x24.org>2023-11-13 08:36:16 +0000
commit82f45b6fa99380b02502046086fb7640065d44a1 (patch)
treed823c4ca4e46015cf653b665196a32bb3878f2c9 /lib/PublicInbox
parent47c7ef452c0984cb4f2c3662d352ae95d672b56d (diff)
downloadpublic-inbox-82f45b6fa99380b02502046086fb7640065d44a1.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r--lib/PublicInbox/xap_helper.h10
1 files 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) {