From 7d092913b37f6211375e0c16fff19e4f9a011b2b Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Sun, 7 Jan 2024 11:58:32 +0000 Subject: [PATCH] freebsd: fix F_KINFO file path handling (#4256) The new F_KINFO flag does not seem to work with directories nor with deleted entries. Fixes: https://github.com/libuv/libuv/issues/4255 --- src/unix/kqueue.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index 94ace586..d7aa60e7 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -488,11 +488,15 @@ static void uv__fs_event(uv_loop_t* loop, uv__io_t* w, unsigned int fflags) { * the struct's kf_structsize must be initialised beforehand * whether with the KINFO_FILE_SIZE constant or this way. */ + struct stat statbuf; struct kinfo_file kf; - kf.kf_structsize = sizeof(kf); - if (fcntl(handle->event_watcher.fd, F_KINFO, &kf) == 0) - path = uv__basename_r(kf.kf_path); + if (handle->event_watcher.fd != -1 && + (!uv__fstat(handle->event_watcher.fd, &statbuf) && !(statbuf.st_mode & S_IFDIR))) { + kf.kf_structsize = KINFO_FILE_SIZE; + if (fcntl(handle->event_watcher.fd, F_KINFO, &kf) == 0) + path = uv__basename_r(kf.kf_path); + } #endif handle->cb(handle, path, events, 0);