diff --git a/src/inotify-backend.c b/src/inotify-backend.c index 2f5d2f7..a706c8e 100644 --- a/src/inotify-backend.c +++ b/src/inotify-backend.c @@ -9,9 +9,12 @@ */ #include +#include #include #include +#include #include +#include #include "inotify-backend.h" #include "inotify-syscalls.h" @@ -19,16 +22,41 @@ #define WATCH_MASK (IN_MOVE | IN_CREATE | IN_DELETE | IN_ONLYDIR) +#define PROCFS_QSIZE "/proc/sys/fs/inotify/max_queued_events" + static int fd = -1; static unsigned inotify_qsize = 256; +void read_unsigned_int(const char *filename, unsigned *val) { + + int fd; + char buf[16]; + + fd = open(filename, O_RDONLY); + if (fd < 0) + return; + if (read(fd, buf, 15) > 0 && *buf) { + unsigned long tmp; + errno = 0; + tmp = strtoul(buf, NULL, 10); + if (!errno && tmp <= (unsigned)-1) + *val = tmp; + } + close(fd); +} + int inotify_backend_init(void) { if (fd >= 0) close(fd); fd = inotify_init(); + if (fd < 0) + return -errno; + + read_unsigned_int(PROCFS_QSIZE, &inotify_qsize); + return fd; }