summaryrefslogtreecommitdiff
path: root/src/fs_event
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs_event')
-rw-r--r--src/fs_event/fs_event.h5
-rw-r--r--src/fs_event/fs_event_inotify.c18
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,