From 3c6e797f7551fd7258b18b3710349fc8db3d595a Mon Sep 17 00:00:00 2001 From: David Gibson Date: Tue, 12 May 2026 15:52:54 +1000 Subject: passt-repair: Simplify construction of Unix path from inotify 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 Signed-off-by: Stefano Brivio --- passt-repair.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/passt-repair.c b/passt-repair.c index 980b0b0..d4c8ce9 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; } /** -- cgit v1.2.3