diff options
| author | 2025-08-12 17:38:09 -0400 | |
|---|---|---|
| committer | 2025-08-12 17:38:09 -0400 | |
| commit | ab75884371a3545f7548498549e2faebbc465ed6 (patch) | |
| tree | 0a4b99a55b186eda26bf63343db91c931fb88279 /src/fs_event | |
| parent | eaf84a7850f2af70b16fb417cd002f5e39df5db2 (diff) | |
| download | libnaunet-ab75884371a3545f7548498549e2faebbc465ed6.tar.gz libnaunet-ab75884371a3545f7548498549e2faebbc465ed6.tar.bz2 libnaunet-ab75884371a3545f7548498549e2faebbc465ed6.zip | |
Improve inotify usage, copy path in file_stdio
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/fs_event')
| -rw-r--r-- | src/fs_event/fs_event.h | 5 | ||||
| -rw-r--r-- | src/fs_event/fs_event_inotify.c | 18 |
2 files changed, 13 insertions, 10 deletions
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 <sys/inotify.h> -#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, |