diff options
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; +} |