aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2026-05-12 15:52:54 +1000
committerStefano Brivio <sbrivio@redhat.com>2026-05-16 15:47:07 +0200
commit3c6e797f7551fd7258b18b3710349fc8db3d595a (patch)
tree4be35bcf62b201e048d8d59d7bd5d5d3efbb2d21
parent1254a1f9f9867a9d9022e709549388d9cdf4f7b4 (diff)
downloadpasst-3c6e797f7551fd7258b18b3710349fc8db3d595a.tar
passt-3c6e797f7551fd7258b18b3710349fc8db3d595a.tar.gz
passt-3c6e797f7551fd7258b18b3710349fc8db3d595a.tar.bz2
passt-3c6e797f7551fd7258b18b3710349fc8db3d595a.tar.lz
passt-3c6e797f7551fd7258b18b3710349fc8db3d595a.tar.xz
passt-3c6e797f7551fd7258b18b3710349fc8db3d595a.tar.zst
passt-3c6e797f7551fd7258b18b3710349fc8db3d595a.zip
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 <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
-rw-r--r--passt-repair.c13
1 files 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;
}
/**