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=Jg5oJBif; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 89FD15A061A for ; Tue, 21 Apr 2026 04:43:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1776739427; bh=V8wGUKn4B3NqixSMWgNWIzktlTlKDpxEeFgFMkWSRL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jg5oJBif3O5iCP6tm6NO1rca2SE6z0Jl0wBgBVm46XYZLmiTHs4V+hjiKxPV+OUIO /Ysu20bAHc2Nw+kpwz/2vc6z9MaWtBGOABugn4NRxQ9lobz4LH9BJKy7UJR+j66OvC n6rr34gvQCwfaUA/YbV8IO9pMX+xqJwgbLjFscqNxOKt9wztdDsSRmNgGaBaxgf2XH 5c1pjzRfPjtNbgirkeptxGzyppJwxOUl+cPQyn6jp7nASp5c0PTfqXxr95donUtKUp DBvGgA2o+ScX/HXMULne4TG7qPfX5j9vaFyA+VzwXh9rVkOmMCbxaMSQWQqk3CBj3P NSsf1r0Wf6KpA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4g069v3RLVz4wGx; Tue, 21 Apr 2026 12:43:47 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 11/13] passt-repair: Simplify construction of Unix path from inotify Date: Tue, 21 Apr 2026 12:43:42 +1000 Message-ID: <20260421024344.1379633-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260421024344.1379633-1-david@gibson.dropbear.id.au> References: <20260421024344.1379633-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: YBS3DV6J3F3WXUQ4ATBDNDGNIYARRDBZ X-Message-ID-Hash: YBS3DV6J3F3WXUQ4ATBDNDGNIYARRDBZ 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.53.0