From ab75884371a3545f7548498549e2faebbc465ed6 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Tue, 12 Aug 2025 17:38:09 -0400 Subject: Improve inotify usage, copy path in file_stdio Signed-off-by: Andrew Opalach --- src/fs_event/fs_event.h | 5 +++-- src/fs_event/fs_event_inotify.c | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/fs_event') diff --git a/src/fs_event/fs_event.h b/src/fs_event/fs_event.h index 2cfef07..b25270e 100644 --- a/src/fs_event/fs_event.h +++ b/src/fs_event/fs_event.h @@ -4,10 +4,11 @@ #ifdef NAUNET_ON_WINDOWS struct inotify_event {}; -#define NNWT_CLOSE_WRITE 0 +#define NNWT_FS_CLOSE_WRITE 0 #else #include -#define NNWT_CLOSE_WRITE IN_CLOSE_WRITE +#define NNWT_FS_CLOSE_WRITE IN_CLOSE_WRITE +#define NNWT_FS_CREATE IN_CREATE #endif #include "../loop.h" diff --git a/src/fs_event/fs_event_inotify.c b/src/fs_event/fs_event_inotify.c index 7def7a3..757d393 100644 --- a/src/fs_event/fs_event_inotify.c +++ b/src/fs_event/fs_event_inotify.c @@ -6,21 +6,23 @@ #include "fs_event.h" +#define EVENT_MAX_SIZE (sizeof(struct inotify_event) + NAME_MAX + 1) + static void event_callback(struct ev_loop *loop, ev_io *w, s32 revents) { (void)loop; struct nn_fs_event *fs = (struct nn_fs_event *)w->data; (void)revents; - struct inotify_event event = { 0 }; - ssize_t ret = nn_read(fs->fd, &event, sizeof(struct inotify_event)); - if (!(event.mask & IN_CLOSE_WRITE)) { - // Expecting IN_IGNORED. + struct inotify_event *event = al_malloc(EVENT_MAX_SIZE); + ssize_t ret = nn_read(fs->fd, event, EVENT_MAX_SIZE); + al_assert(ret > 0); + if (!(event->mask & fs->mask)) { + al_assert(event->mask & IN_IGNORED); return; } - al_assert(ret == sizeof(struct inotify_event)); - al_assert(event.wd == fs->wd); - al_assert(event.len == 0); - fs->callback(fs->userdata, &event); + al_assert(event->wd == fs->wd); + fs->callback(fs->userdata, event); + al_free(event); } void nn_fs_event_init(struct nn_fs_event *fs, str *path, u32 mask, -- cgit v1.2.3-101-g0448