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=HN7qTtfE; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 5918A5A0269 for ; Tue, 14 Jul 2026 11:29:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1784021369; bh=V1PrPbEjlt7XCuNdPShNklCxdXwK4907o+9NxDUO6Ik=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HN7qTtfEEpiQKY7ochKj9hR1FnNh1IOjmYauZ3W3Z1LWGSl7rmyd/4EwjJtLxG442 VLH8NOef+BmynDmjmE8i8HpcL8SwhQPqbmSi3k4qn4nETPFgAmTq/bVD6Gk/rwQupx WEkIOrhJpOxGrrKD3aBXAAuNwjwYgK0DAuwdMxFs3sPTgdj9Hyp7oGISTyE5tLWzCh IlqmJidw23FjVveWHETYwg1WXqHQt2gMYF4BwuLtPoQ/KNV9SGKSvOhCyxKXsZT3fm Zd13NcVqhevonzeCiDEcdZowzx9T8s7Jlv2jHZWLe5/7Ncg6nZ80/6qMo4d0wDqWyk /pLjnR0jTeSEg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gzvCF6k4zz4wB7; Tue, 14 Jul 2026 19:29:29 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 3/6] conf: Make conf_tap_fd() operate more like conf_mode() Date: Tue, 14 Jul 2026 19:29:23 +1000 Message-ID: <20260714092926.2881848-4-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260714092926.2881848-1-david@gibson.dropbear.id.au> References: <20260714092926.2881848-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: TQNKNXYHW2YZFFWSD4HPXO4KH6YLE5HS X-Message-ID-Hash: TQNKNXYHW2YZFFWSD4HPXO4KH6YLE5HS 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 | 12 ++---------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/conf.c b/conf.c index 41c9d557..f0bce41b 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 4bb79e34..c4d476d6 100644 --- a/isolation.c +++ b/isolation.c @@ -58,7 +58,6 @@ #include #include -#include #include #include #include @@ -208,9 +207,7 @@ static int move_root(void) */ int isolate_initial(int argc, char **argv) { - const struct option optfd[] = { { "fd", required_argument, NULL, 'F' }, - { 0 }, }; - int name, rc, fd_tap = -1; + int rc, fd_tap = -1; uint64_t keep; /* We want to keep CAP_NET_BIND_SERVICE in the initial @@ -251,12 +248,7 @@ int isolate_initial(int argc, char **argv) drop_caps_ep_except(keep); - do { - name = getopt_long(argc, argv, "-:F:", optfd, NULL); - - if (name == 'F') - fd_tap = conf_tap_fd(optarg); - } while (name != -1); + fd_tap = conf_tap_fd(argc, argv); if (fd_tap == -1) { rc = close_range(STDERR_FILENO + 1, ~0U, CLOSE_RANGE_UNSHARE); -- 2.55.0