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=202602 header.b=QP+Pthhw; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 74CE05A0262 for ; Tue, 12 May 2026 07:53:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1778565179; bh=8YIlUKuXUMWvQfppA1M8IKNFVsHD1bjNUvckv8Z3ql8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QP+Pthhw6NfbHg9apeCv66haWnoWJx66Ey/mUH1oEq3poT1op6pEPjlBssemGXc7j RPLoq6IXD19CCnUmBFW67nJSWX/mrwT5tbGd4LI2DqPQFidFePph2AMMkdi3X95Muy UkqDjD73zkWmnka5lzhC4u+TUeFN03cFInVJmcdGE2ZyjMVEu7/okg92ILemkXotsf V9cNmgLNBqnJGfPNM5jexMGOVMtMdHVlNvo+5tkar7eN/TuMCoadEKbc5le7r1pW7F ETJ9Tlu0cOUJa197s1FCeWNj+BwI+V+H1uX2HTd5k9kntRQoTJwXkfZIuBDW7LqREL ZhLVetrKwf0Kw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gF5NW23JDz4wTY; Tue, 12 May 2026 15:52:59 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v3 10/12] passt-repair: Simplify construction of Unix path from inotify Date: Tue, 12 May 2026 15:52:54 +1000 Message-ID: <20260512055256.1800449-11-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260512055256.1800449-1-david@gibson.dropbear.id.au> References: <20260512055256.1800449-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: VL7MNQV7EFD2UCGSTY6G7NQQ4HLJDA7R X-Message-ID-Hash: VL7MNQV7EFD2UCGSTY6G7NQQ4HLJDA7R 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: When passt-repair is invoked with a directory name, it waits for a Unix socket to appear in that directory. We need to build the Unix path name from the given directory, plus the stem file name from the inotify event. Currently, we build that path into a temporary buffer of size PATH_MAX, then move it into the smaller buffer inside the Unix sockaddr. There's no particular reason for this two step process, we can build the address directly within the sockaddr_un. This will give a slightly different error if the constructed path exceeds the maximum length of a Unix address, but it will fail either way so it doesn't really matter. Signed-off-by: David Gibson --- passt-repair.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/passt-repair.c b/passt-repair.c index 980b0b09..d4c8ce9a 100644 --- a/passt-repair.c +++ b/passt-repair.c @@ -64,10 +64,9 @@ static int wait_for_socket(struct sockaddr_un *a, const char *dir, char buf[sizeof(struct inotify_event) + NAME_MAX + 1] __attribute__ ((aligned(__alignof__(struct inotify_event)))); const struct inotify_event *ev = NULL; - char path[PATH_MAX + 1]; bool found = false; + int fd, ret; ssize_t n; - int fd; if ((fd = inotify_init1(IN_CLOEXEC)) < 0) { fprintf(stderr, "inotify_init1: %i\n", errno); @@ -113,13 +112,15 @@ static int wait_for_socket(struct sockaddr_un *a, const char *dir, _exit(1); } - snprintf(path, sizeof(path), "%s/%s", dir, ev->name); - if ((stat(path, sb))) { - fprintf(stderr, "Can't stat() %s: %i\n", path, errno); + ret = snprintf(a->sun_path, sizeof(a->sun_path), "%s/%s", + dir, ev->name); + + if ((stat(a->sun_path, sb))) { + fprintf(stderr, "Can't stat() %s: %i\n", a->sun_path, errno); _exit(1); } - return snprintf(a->sun_path, sizeof(a->sun_path), "%s", path); + return ret; } /** -- 2.54.0