tFree the malloc(), and ignore expected ENOTDIR error - wendy - watch files/directories and run commands on any event
HTML git clone git://z3bra.org/wendy
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit 5cd21f9a20ee3dbd4d35d6957a5ebdb392ab8523
DIR parent c3e9487830fe62b4adcf4ad22053485a435a1fac
HTML Author: Willy Goiffon <dev@z3bra.org>
Date: Mon, 2 Mar 2020 14:58:19 +0100
Free the malloc(), and ignore expected ENOTDIR error
Diffstat:
M wendy.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
DIR diff --git a/wendy.c b/wendy.c
t@@ -75,7 +75,11 @@ watch(int fd, char *pathname, int mask)
w->wd = inotify_add_watch(fd, w->path, mask);
if (w->wd < 0) {
- perror(pathname);
+ /* triggered when dflag is set, so it is expected */
+ if (errno != ENOTDIR)
+ perror(pathname);
+
+ free(w);
return NULL;
}
t@@ -175,8 +179,10 @@ main (int argc, char **argv)
*/
if (e->mask & IN_IGNORED) {
inotify_rm_watch(fd, e->wd);
- if ((w->wd = inotify_add_watch(fd, w->path, mask)) < 0)
+ if ((w->wd = inotify_add_watch(fd, w->path, mask)) < 0) {
SLIST_REMOVE(&head, w, watcher, entries);
+ free(w);
+ }
}
skip: