From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=dTxkirK2; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 412CD5A0271 for ; Fri, 17 Jul 2026 07:46:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1784267197; bh=AIw9czXT3sRnnIVFaEyzebFiZ4kVAmua+CSDHbV4+20=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dTxkirK25Q3egL2jk1NrT2o978HonIrP9zbwsvidyyQ/hGQdTRPNq8q6y3UpiGcoO JdXFsLxy8SBR0Tuq9YZiCGn7ur0nipcIoaYmb2IurKIMxlFoTf/DvG5dwGkm8hZbHp suFL++FhU7ajcfGZNPUwl8VS0FFsyzLus0nBCJWb3SGz0P1o1SQ+nL83+ViLbDFt+e iEqGV6YNN7Z6wgmZrO+jG4i/7X5ZciXcUy0aqQDamB7mI7HV9nDoa96xo+QXDs/WmQ 7DMkkhw7NXbscsu/hiR7t6XYmZlp7+yfK0wl7SI5Ufa5xK/1WsZ/5olbestAIT5ZYA XE51IOdGpLNtg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4h1f6j0gBcz4wCC; Fri, 17 Jul 2026 15:46:37 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 4/6] conf: Make conf_tap_fd() operate more like conf_mode() Date: Fri, 17 Jul 2026 15:46:32 +1000 Message-ID: <20260717054634.1293553-5-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260717054634.1293553-1-david@gibson.dropbear.id.au> References: <20260717054634.1293553-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: IKLPGNRA4IZJAUQBNL2EB7X5J5V7RA4P X-Message-ID-Hash: IKLPGNRA4IZJAUQBNL2EB7X5J5V7RA4P X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: We have two cases where we need to parse specific options early: conf_tap_fd() and conf_mode(). conf_tap_fd() has a slightly odd interface, requiring the caller to use getopt_long() to find the right option, then pass it in. Alter it to work like conf_mode() instead, where all the command line parsing logic is contained within the conf.c function. This is slightly more lines, but has a clearer division of responsibility. Signed-off-by: David Gibson --- conf.c | 25 +++++++++++++++++++++---- conf.h | 2 +- isolation.c | 13 ++----------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/conf.c b/conf.c index b3211e54..df204d13 100644 --- a/conf.c +++ b/conf.c @@ -1153,17 +1153,34 @@ static void conf_sock_listen(const struct ctx *c) /** * conf_tap_fd() - Read tap fd as supplied by -F command line option - * @arg: Argument to -F command line option + * @argc: Argument count + * @argv: Command line options + * + * Return: fd number from --fd option, or -1 if not supplied */ -int conf_tap_fd(const char *arg) +int conf_tap_fd(int argc, char **argv) { - const char *p = arg; + const struct option optfd[] = { { "fd", required_argument, NULL, 'F' }, + { 0 }, }; + const char *fdarg = NULL, *p; unsigned long val; + int name; + + optind = 0; + do { + name = getopt_long(argc, argv, "-:F:", optfd, NULL); + if (name == 'F') + fdarg = optarg; + } while (name != -1); + + if (!fdarg) + return -1; + p = fdarg; if (!parse_unsigned(&p, 0, &val) || !parse_eoi(p) || val > INT_MAX || (val != STDIN_FILENO && val <= STDERR_FILENO)) - die("Invalid --fd: %s", arg); + die("Invalid --fd: %s", fdarg); return val; } diff --git a/conf.h b/conf.h index 1fa1280e..19bf9bc5 100644 --- a/conf.h +++ b/conf.h @@ -7,7 +7,7 @@ #define CONF_H enum passt_modes conf_mode(int argc, char *argv[]); -int conf_tap_fd(const char *arg); +int conf_tap_fd(int argc, char **argv); void conf(struct ctx *c, int argc, char **argv); void conf_listen_handler(struct ctx *c, uint32_t events); void conf_handler(struct ctx *c, uint32_t events); diff --git a/isolation.c b/isolation.c index c9dfefa8..725a72bb 100644 --- a/isolation.c +++ b/isolation.c @@ -63,7 +63,6 @@ #include #include -#include #include #include #include @@ -262,17 +261,9 @@ void isolate_initial(void) */ int isolate_fds(int argc, char **argv) { - const struct option optfd[] = { { "fd", required_argument, NULL, 'F' }, - { 0 }, }; - long fd = -1; - int name, rc; + int fd, rc; - do { - name = getopt_long(argc, argv, "-:F:", optfd, NULL); - - if (name == 'F') - fd = conf_tap_fd(optarg); - } while (name != -1); + fd = conf_tap_fd(argc, argv); if (fd == -1) { rc = close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_UNSHARE); -- 2.55.0