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=H3tMqYBp; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 60E315A026D 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=5qLsRjDFTQewemuN3Hu3kDNaszyUMhnKUyvJaDvkBwY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H3tMqYBp6lzQPdBYyKmNLLB9r/Px6jvRr6U29qJZcLqG87yXbdf6E1SKPom3wYY4I D6AVa5rS4lq++NNne7AS/thglB3zJr1udmvH6UM8iBuvQh+DnwpYBcqfRo4yC5sSYz T01P7OHg2eVTxmuu70J4kK4x6sa6M8t9HrkdSOgGJS1rT0jdPV8VPN9Mv54hD/S2yz H/RVUEzoiR/cfDUx0Fs5VDmdufV6R7orXB6ojYYT2omvEQcxGgYf0nPT55gCwa5IAz rYLKpABudrShP1f9ZRp7w36RpP62mh/nCVbtnQYl1Y9i+LEzhh1nyeQ2Hm7wq1QOk3 XTezwFqpHM+/A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gzvCF6VNcz4wCC; Tue, 14 Jul 2026 19:29:29 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 2/6] isolation, conf: Set c->fd_tap from eary parse of --fd Date: Tue, 14 Jul 2026 19:29:22 +1000 Message-ID: <20260714092926.2881848-3-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: ESVNL6T2TNQ5G5TO6FXBJQEB7ALPPNBH X-Message-ID-Hash: ESVNL6T2TNQ5G5TO6FXBJQEB7ALPPNBH 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 parse --fd twice: once in isolate_initial() just to avoid clobbering the passed in fd. Then we parse it "for real" in conf(), to set c->fd_tap and other configuration variables. Change this, so that we return the value parsed early from isolate_initial() and set c->fd_tap from that. This doesn't accomplish much immediately, but will make some further cleanups possible. Signed-off-by: David Gibson --- conf.c | 2 +- isolation.c | 6 +++++- isolation.h | 2 +- passt.c | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/conf.c b/conf.c index 6d83daef..41c9d557 100644 --- a/conf.c +++ b/conf.c @@ -1593,7 +1593,7 @@ void conf(struct ctx *c, int argc, char **argv) c->fd_control_listen = c->fd_control = -1; break; case 'F': - c->fd_tap = conf_tap_fd(optarg); + /* --fd was parsed early and c->fd_tap set in main() */ c->one_off = true; *c->sock_path = 0; break; diff --git a/isolation.c b/isolation.c index 07b281bb..4bb79e34 100644 --- a/isolation.c +++ b/isolation.c @@ -203,8 +203,10 @@ static int move_root(void) * - close all open files except for standard streams and the one from --fd * Mustn't: * - remove filesystem access (we need to access files during setup) + * + * Return: fd number from --fd, or -1 if not specified */ -void isolate_initial(int argc, char **argv) +int isolate_initial(int argc, char **argv) { const struct option optfd[] = { { "fd", required_argument, NULL, 'F' }, { 0 }, }; @@ -280,6 +282,8 @@ void isolate_initial(int argc, char **argv) die_perror("Failed to close files leaked by parent"); } } + + return fd_tap; } /** diff --git a/isolation.h b/isolation.h index 66b6968d..ef27c7d5 100644 --- a/isolation.h +++ b/isolation.h @@ -10,7 +10,7 @@ #include #include -void isolate_initial(int argc, char **argv); +int isolate_initial(int argc, char **argv); void isolate_user(const struct ctx *c, uid_t uid, gid_t gid, bool use_userns, const char *userns); int isolate_prefork(const struct ctx *c); diff --git a/passt.c b/passt.c index 65a07d72..b99e5998 100644 --- a/passt.c +++ b/passt.c @@ -341,7 +341,7 @@ int main(int argc, char **argv) arch_avx2_exec(argv); - isolate_initial(argc, argv); + c->fd_tap = isolate_initial(argc, argv); sigemptyset(&sa.sa_mask); sa.sa_flags = 0; -- 2.55.0