From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id iDktLzwBlmJHDwEAbAwnHQ (envelope-from ) for ; Tue, 31 May 2022 13:51:24 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id WLg0LjwBlmKFEwEAG6o9tA (envelope-from ) for ; Tue, 31 May 2022 13:51:24 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 8A96CC6BF for ; Tue, 31 May 2022 13:51:24 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0AB835F782; Tue, 31 May 2022 11:51:12 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id B0A4E5F769 for ; Tue, 31 May 2022 11:51:09 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id F07265FBD7; Tue, 31 May 2022 07:51:08 -0400 (EDT) Received: (nullmailer pid 2446071 invoked by uid 1000); Tue, 31 May 2022 11:51:04 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 2/3] CLI: pass --config to external commands via NOTMUCH_CONFIG. Date: Tue, 31 May 2022 08:50:59 -0300 Message-Id: <20220531115100.2446050-2-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220531115100.2446050-1-david@tethera.net> References: <20220531115100.2446050-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: WVBT5RJ3WN265HUE6NB6RV4WEWSSLURU X-Message-ID-Hash: WVBT5RJ3WN265HUE6NB6RV4WEWSSLURU X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1653997884; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post; bh=/DEzyzN53h9kLt1poNfibQ12fSvZrxftUIO7eETEEJ4=; b=Ko0Nnswyu/P9GHtRf9ouE6abyHWYW2UV3RWG/27Br4Rwyend3GpmK752kt88kTDp4lRPs0 +tehKbfr+/Ue2ZTHTEuw2CBT4xzkp3COfF9Sg4Vrz7YvT9LbLSnzxTwjdyAj61qMZsU52a UwFbEo1us4LCsyOux+Qs4jZ/720pZv8DTD7ssKmEG1Bb0QccUDOTv0t1qRN+HircW6TVSF uS5PPDOpvnbw2L0CWk5KQCJ/m7DUmAatL3iv/bSxgaKTu9Gvv2E/GsmSXzBwwhpho3IJGp uU7eLfVxsSpapoWzEiQE9qrgiNb3wmFnYJiMQ2PRh04gym+LnFDhoFJCkWdGyQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1653997884; a=rsa-sha256; cv=none; b=ECfmJdkE1dYi4AwUQ9+ckyO3pbITmoVpFzgBY2iGmcJuolEaJpLDjo4otYhSaSA19/SMuB m4yG4ylS3KA4XW9EdKqx/pdt173KZMjJJwUelrxff7y1tUQMS7hY1wblFXc2sutwXbfUq1 aXUZNQOfGtp2kgdv5HnCsh4DFChYKbxC8W5kR4AaU/Uys0q35tOUhSpdKc1kO9dMo2PS4O bcK6M8+Wm7YfcQhQcpGUdqWCVoESveZ3U51E3jrlIaTFZ1K4hnlVN2Uw1EtI7FMAVitg/H 0muM8CDelx7lASLOloxuG7lWVc2GuG/ZMJRgqcbhkvlcwM6caDcvrGADGlbPhg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.53 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 8A96CC6BF X-Spam-Score: -1.53 X-Migadu-Scanner: scn0.migadu.com X-TUID: Cum6cTrYteDE This makes `notmuch --config foo external-subcommand` work consistently with the built in subcommands. --- notmuch.c | 11 +++++++++-- test/T405-external.sh | 1 - 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/notmuch.c b/notmuch.c index ac25ae18..8398501f 100644 --- a/notmuch.c +++ b/notmuch.c @@ -443,11 +443,18 @@ notmuch_command (notmuch_database_t *notmuch, * false on errors. */ static bool -try_external_command (char *argv[]) +try_external_command (const char *config_file_name, char *argv[]) { char *old_argv0 = argv[0]; bool ret = true; + if (config_file_name) { + if (setenv ("NOTMUCH_CONFIG", config_file_name, 1)) { + perror ("setenv"); + exit (1); + } + } + argv[0] = talloc_asprintf (NULL, "notmuch-%s", old_argv0); /* @@ -507,7 +514,7 @@ main (int argc, char *argv[]) /* if command->function is NULL, try external command */ if (! command || ! command->function) { /* This won't return if the external command is found. */ - if (try_external_command (argv + opt_index)) + if (try_external_command (config_file_name, argv + opt_index)) fprintf (stderr, "Error: Unknown command '%s' (see \"notmuch help\")\n", command_name); ret = EXIT_FAILURE; diff --git a/test/T405-external.sh b/test/T405-external.sh index b121fc72..0e1d9646 100755 --- a/test/T405-external.sh +++ b/test/T405-external.sh @@ -44,7 +44,6 @@ EOF test_expect_equal_file_nonempty EXPECTED OUTPUT test_begin_subtest "NOTMUCH_CONFIG is set by --config" -test_subtest_known_broken cp "${NOTMUCH_CONFIG}" "${NOTMUCH_CONFIG}.alternate" cat < EXPECTED ${NOTMUCH_CONFIG}.alternate -- 2.35.2