public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v2 3/6] isolation, conf: Set c->fd_tap from early parse of --fd
Date: Fri, 17 Jul 2026 15:46:31 +1000	[thread overview]
Message-ID: <20260717054634.1293553-4-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20260717054634.1293553-1-david@gibson.dropbear.id.au>

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 <david@gibson.dropbear.id.au>
---
 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 5b6cc2be..b3211e54 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 ea85fdba..c9dfefa8 100644
--- a/isolation.c
+++ b/isolation.c
@@ -257,8 +257,10 @@ void isolate_initial(void)
  *
  * Should:
  *  - close all open files except for standard streams and the one from --fd
+ *
+ * Return: fd number from --fd, or -1 if not specified
  */
-void isolate_fds(int argc, char **argv)
+int isolate_fds(int argc, char **argv)
 {
 	const struct option optfd[] = { { "fd", required_argument, NULL, 'F' },
 					{ 0 }, };
@@ -296,6 +298,8 @@ void isolate_fds(int argc, char **argv)
 			die_perror("Failed to close files leaked by parent");
 		}
 	}
+
+	return fd;
 }
 
 /**
diff --git a/isolation.h b/isolation.h
index e1b1bc5d..ec470388 100644
--- a/isolation.h
+++ b/isolation.h
@@ -11,7 +11,7 @@
 #include <unistd.h>
 
 void isolate_initial(void);
-void isolate_fds(int argc, char **argv);
+int isolate_fds(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 ce20cedb..e930df43 100644
--- a/passt.c
+++ b/passt.c
@@ -342,7 +342,7 @@ int main(int argc, char **argv)
 	arch_avx2_exec(argv);
 
 	isolate_initial();
-	isolate_fds(argc, argv);
+	c->fd_tap = isolate_fds(argc, argv);
 
 	sigemptyset(&sa.sa_mask);
 	sa.sa_flags = 0;
-- 
2.55.0


  parent reply	other threads:[~2026-07-17  5:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17  5:46 [PATCH v2 0/6] Fix bug 215 and some related issues with fd handling David Gibson
2026-07-17  5:46 ` [PATCH v2 1/6] passt: Always close pidfile_fd, not just when daemonizing David Gibson
2026-07-17  5:46 ` [PATCH v2 2/6] isolation: Move close_open_files() to isolate_fds() David Gibson
2026-07-17  5:46 ` David Gibson [this message]
2026-07-17  5:46 ` [PATCH v2 4/6] conf: Make conf_tap_fd() operate more like conf_mode() David Gibson
2026-07-17  5:46 ` [PATCH v2 5/6] isolation: Move --fd descriptor to a number of our choosing David Gibson
2026-07-17  5:46 ` [PATCH v2 6/6] main: Ensure fds 0-2 are populated David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260717054634.1293553-4-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).