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
This commit is contained in:
David CARLIER 2024-01-07 11:58:32 +00:00 committed by GitHub
parent a9381cdb03
commit 7d092913b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);