From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id CA1F71F406 for ; Mon, 13 Nov 2023 05:02:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1699851765; bh=BRF80yqGy+1N5eztVvZwcxzwXHIG2CQBWY2mz63l7zY=; h=From:To:Subject:Date:From; b=Pp/atLwQWQX8txh/qfahwijoDiiBdt75icfhyfMuV9IqLmdzo40rMN/TPHlojy9vx s2HzV8M192ugPCNEsv8PDvToWuR6bosAZ8rCDdDoTffBXgB+QP+jv4LSBmne/9u/FU Sk3DwRHiZDJT4SXv8FnJnXpRIr3eexu9W0XhY5E4= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] xap_helper: reset getopt(3) properly in workers Date: Mon, 13 Nov 2023 05:00:39 +0000 Message-ID: <20231113050039.22817-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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) {