--- libaitio/src/aitio.c 2016/08/10 14:19:50 1.17.8.3 +++ libaitio/src/aitio.c 2016/08/10 14:33:23 1.17.8.4 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.c,v 1.17.8.3 2016/08/10 14:19:50 misho Exp $ +* $Id: aitio.c,v 1.17.8.4 2016/08/10 14:33:23 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -316,6 +316,9 @@ ioWatchDirLoop(const char *csDir, int (*callback)(cons #ifndef __linux__ int kq; struct kevent req, chg; +#else + int in; + struct inotify_event evt; #endif char wrk[MAXPATHLEN * 2], str[MAXPATHLEN] = { 0 }; @@ -325,13 +328,13 @@ ioWatchDirLoop(const char *csDir, int (*callback)(cons strlcpy(str, csDir, MAXPATHLEN); strlcat(str, "/*", MAXPATHLEN); +#ifndef __linux__ d = open(csDir, O_RDONLY); if (d == -1) { LOGERR; return -1; } -#ifndef __linux__ kq = kqueue(); if (kq == -1) { LOGERR; @@ -340,13 +343,24 @@ ioWatchDirLoop(const char *csDir, int (*callback)(cons } EV_SET(&req, d, EVFILT_VNODE, EV_ADD | EV_CLEAR, NOTE_WRITE, 0, 0); +#else + in = inotify_init(); + if (in == -1) { + LOGERR; + return -1; + } + + d = inotify_add_watch(in, csDir, IN_CREATE | IN_DELETE); #endif if ((n = glob(str, GLOB_NOCHECK, NULL, &g[0]))) { LOGERR; - close(d); #ifndef __linux__ close(kq); + close(d); +#else + inotify_rm_watch(in, d); + close(in); #endif return -1; } /*else @@ -419,8 +433,11 @@ ioWatchDirLoop(const char *csDir, int (*callback)(cons globfree(&g[0]); #ifndef __linux__ close(kq); -#endif close(d); +#else + inotify_rm_watch(in, d); + close(in); +#endif return n; }