diff options
author | Christian Pointner <equinox@helsinki.at> | 2009-11-19 21:04:54 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2009-11-19 21:04:54 (GMT) |
commit | d171586226b79bd0977f6f9c6584621e6c6e46bb (patch) | |
tree | 8df1d3399716dccbe54ae865c2b33c333464e046 /utils.c | |
parent | a5b0a21c1a906ef871b32014c3f6357251141099 (diff) |
added basic inotify
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -22,9 +22,10 @@ #include "datatypes.h" #include <sys/un.h> -#include <termios.h> #include <unistd.h> #include <errno.h> +#include <fcntl.h> +#include <sys/inotify.h> #include "log.h" @@ -139,3 +140,34 @@ int nonblock_recvline(read_buffer_t* buffer, int fd, client_t* client_lst, optio return ret; } + +int create_inotify() +{ + int fd = inotify_init(); + if(fd < 0) { + log_printf(ERROR, "error at inotify_init: %s", strerror(errno)); + return -1; + } + + int fs_flags = fcntl(fd, F_GETFL); + if(fs_flags == -1) { + log_printf(ERROR, "inotify init failed (fcntl read flags error: %s)", strerror(errno)); + return -1; + } + if(fcntl(fd, F_SETFL, fs_flags | O_NONBLOCK) == -1) { + log_printf(ERROR, "inotify init failed (fcntl write flags error: %s)", strerror(errno)); + return -1; + } + + int fd_flags = fcntl(fd, F_GETFD); + if(fd_flags == -1) { + log_printf(ERROR, "inotify init failed (fcntl read flags error: %s)", strerror(errno)); + return -1; + } + if(fcntl(fd, F_SETFD, fd_flags | FD_CLOEXEC) == -1) { + log_printf(ERROR, "inotify init failed (fcntl write flags error: %s)", strerror(errno)); + return -1; + } + + return fd; +} |