Align event buffer to what inotify(7) says

This commit is contained in:
kamkow1
2025-06-15 14:27:26 +02:00
parent ff44623710
commit 3d09d1dd67

View File

@ -1,3 +1,4 @@
#include <stdalign.h>
#include <dirent.h> #include <dirent.h>
#include <signal.h> #include <signal.h>
#include <errno.h> #include <errno.h>
@ -9,7 +10,8 @@
#define GEBS_IMPLEMENTATION #define GEBS_IMPLEMENTATION
#include "gebs/gebs.h" #include "gebs/gebs.h"
#define EVENT_BUFFER_SIZE (1 * (sizeof(struct inotify_event) + NAME_MAX + 1)) #define EVENT_BUFFER_SIZE (5 * (sizeof(struct inotify_event) + NAME_MAX + 1))
#define EVENT_BUFFER_ALIGNMENT __attribute__((aligned(alignof(struct inotify_event))))
typedef struct { typedef struct {
int key; // watch descriptor int key; // watch descriptor
@ -153,7 +155,7 @@ int main(int argc, char ** argv)
pid_t cmd_pid = cmd_run_async(&cmd); pid_t cmd_pid = cmd_run_async(&cmd);
char event_buffer[EVENT_BUFFER_SIZE] __attribute__((aligned(8))); char event_buffer[EVENT_BUFFER_SIZE] EVENT_BUFFER_ALIGNMENT;
while (running) { while (running) {
ssize_t nread; ssize_t nread;
if ((nread = read(watcher.fd, event_buffer, EVENT_BUFFER_SIZE)) < 0) { if ((nread = read(watcher.fd, event_buffer, EVENT_BUFFER_SIZE)) < 0) {