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=PGEHFUmy; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 27F7F5A0625 for ; Tue, 21 Apr 2026 05:23:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1776741822; bh=V8wGUKn4B3NqixSMWgNWIzktlTlKDpxEeFgFMkWSRL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PGEHFUmynA+6KCAEnXNIozvPwuZ/FXbdwwNKzRteKixml5fTNFwZZMCj3l3OJnGq4 /D4SU84RcJGx5lGlAOGjBjKLxOMCF0Sv0A44gwVY3BWfU92P5nQQi8FgEOh6J1TWhW Fv42apniMSpYX0YthuaAODyT4AoEAjYIlMXQ+55VF6ErnoH/f+R4eEp6xkqgcuN2jL L2uiJGjbcTPzgGVQgM526kGyKR5qtyZTFtcv45QW5flgODxGQqIL/8bXuU+APyiB88 rPZQ4BCn+JiLxAUHnEbz6Gyty12wmrDdI2K3Q2cEItOC9+GkgLb4Ft6QMZ9N8l8MF8 A2repZtJQi6cA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4g073y5hKNz4wG7; Tue, 21 Apr 2026 13:23:42 +1000 (AEST) From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH v2 11/13] passt-repair: Simplify construction of Unix path from inotify Date: Tue, 21 Apr 2026 13:23:36 +1000 Message-ID: <20260421032338.1909084-12-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260421032338.1909084-1-david@gibson.dropbear.id.au> References: <20260421032338.1909084-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: Q4CIGLL6QIHSTFBCHRK6PJX3TUC2G7GV X-Message-ID-Hash: Q4CIGLL6QIHSTFBCHRK6PJX3TUC2G7GV 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