summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-08-12 17:38:09 -0400
committerAndrew Opalach <andrew@akon.city> 2025-08-12 17:38:09 -0400
commitab75884371a3545f7548498549e2faebbc465ed6 (patch)
tree0a4b99a55b186eda26bf63343db91c931fb88279
parenteaf84a7850f2af70b16fb417cd002f5e39df5db2 (diff)
downloadlibnaunet-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>
-rwxr-xr-xscripts/line_count.sh2
-rw-r--r--src/curl/websocket.c2
-rw-r--r--src/fs_event/fs_event.h5
-rw-r--r--src/fs_event/fs_event_inotify.c18
-rw-r--r--src/util/file/file_stdio.c3
-rw-r--r--subprojects/libalabaster.wrap2
-rw-r--r--tests/fs_event_local.c4
7 files changed, 22 insertions, 14 deletions
diff --git a/scripts/line_count.sh b/scripts/line_count.sh
index 6af0fe0..a6ac787 100755
--- a/scripts/line_count.sh
+++ b/scripts/line_count.sh
@@ -1,3 +1,3 @@
#! /usr/bin/env sh
export LC_ALL="C"
-find ./src ./include -type f -exec loccount {} +
+find ./src ./include -type f -exec sloccount {} +
diff --git a/src/curl/websocket.c b/src/curl/websocket.c
index d40dd0e..ebd8f79 100644
--- a/src/curl/websocket.c
+++ b/src/curl/websocket.c
@@ -59,7 +59,7 @@ bool nn_websocket_connect(struct nn_websocket *ws, struct nn_event_loop *loop,
struct nn_curl *curl = &ws->curl;
al_assert(curl->loop == NULL);
curl->loop = loop;
- curl_easy_setopt(curl->handle, CURLOPT_CONNECT_ONLY, 0);
+ curl_easy_setopt(curl->handle, CURLOPT_CONNECT_ONLY, 0L);
ws->callback = callback;
ws->userdata = userdata;
curl_easy_setopt(curl->handle, CURLOPT_WRITEFUNCTION, stream_write_callback);
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,
diff --git a/src/util/file/file_stdio.c b/src/util/file/file_stdio.c
index 97dd0f0..fa74be7 100644
--- a/src/util/file/file_stdio.c
+++ b/src/util/file/file_stdio.c
@@ -49,6 +49,8 @@ bool nn_file_open(struct nn_file *file, str *path, s32 flags)
return false;
}
+ al_str_clone(&file->path, path);
+
return true;
}
@@ -112,6 +114,7 @@ void *nn_file_mmap(struct nn_file *file)
void nn_file_close(struct nn_file *file)
{
fclose(file->file);
+ al_str_free(&file->path);
}
bool nn_dir_open(struct nn_dir *dir, str *path) { (void)dir; (void)path; return false; }
diff --git a/subprojects/libalabaster.wrap b/subprojects/libalabaster.wrap
index 425ed78..0dc9d62 100644
--- a/subprojects/libalabaster.wrap
+++ b/subprojects/libalabaster.wrap
@@ -1,4 +1,4 @@
[wrap-git]
url = https://git.akon.city/libalabaster
-revision = 1aa0177d1eb3767f1a7840115c3afeb93e8c858e
+revision = 492f4a38f7b7f32727ab678f333eff840d968d74
depth = 1
diff --git a/tests/fs_event_local.c b/tests/fs_event_local.c
index 89aa282..d5bb97c 100644
--- a/tests/fs_event_local.c
+++ b/tests/fs_event_local.c
@@ -26,11 +26,13 @@ s32 main(void)
nn_file_create(&TEST_FILE_PATH);
}
- nn_fs_event_init(&fs, &TEST_FILE_PATH, NNWT_CLOSE_WRITE, fs_event_callback, NULL);
+ nn_fs_event_init(&fs, &TEST_FILE_PATH, NNWT_FS_CLOSE_WRITE, fs_event_callback, NULL);
if (!nn_fs_event_start(&fs, &loop)) {
return EXIT_FAILURE;
}
+ al_printf("Do something like: \"echo 'yo' > test.txt\"\n");
+
nn_event_loop_run(&loop);
nn_common_close();