diff --git a/src/inotify-map.c b/src/inotify-map.c index 5f3e339..c51dca9 100644 --- a/src/inotify-map.c +++ b/src/inotify-map.c @@ -12,7 +12,6 @@ #include #include "xalloc.h" #include "rbtree.h" -#include "list.h" #include "path.h" #include "inotify-watch.h" #include "inotify-map.h" @@ -192,23 +191,12 @@ int inotify_map_get_wd(const char *path) { return 0; } -char** inotify_map_get_path(int wd) { +struct list* inotify_map_get_path(int wd) { - char **out = NULL; - struct list *list; - - list = wd_lookup(wd); - if (list && list->nr) { - int i; - - out = xmalloc(list->nr + 1); - for(i=0; i < list->nr; i++) { - struct watch *w = list->items[i]; - out[i] = (char *)w->path; - } - out[list->nr] = NULL; - } - return out; + struct list *list = wd_lookup(wd); + if (list) + return list_copy(list); + return NULL; } int inotify_map_isempty() { diff --git a/src/inotify-map.h b/src/inotify-map.h index 6efe5fa..75cd3ec 100644 --- a/src/inotify-map.h +++ b/src/inotify-map.h @@ -11,6 +11,9 @@ #ifndef __INOTIFY_MAP_H #define __INOTIFY_MAP_H +#include "list.h" +#include "inotify-watch.h" + void inotify_map(int wd, const char *path); int inotify_unmap_wd(int wd); @@ -21,7 +24,7 @@ void inotify_unmap_all(); int inotify_map_get_wd(const char *path); -char** inotify_map_get_path(int wd); +struct list* inotify_map_get_path(int wd); int inotify_map_isempty(); diff --git a/src/inotify.c b/src/inotify.c index f23bd2c..91515ab 100644 --- a/src/inotify.c +++ b/src/inotify.c @@ -19,6 +19,7 @@ #include #include "inotify-map.h" +#include "inotify-watch.h" #include "util.h" #include "log.h" #include "path.h" @@ -132,7 +133,8 @@ static int rmwatch(const char *path, const char *name) { static void proc_event(inoev *iev) { - char **paths, **path; + int i; + struct list *watch_list; int isdir; logmsg(LOG_DEBUG, "RAW EVENT: %i, %x, %s", iev->wd, iev->mask, iev->name); @@ -142,10 +144,10 @@ static void proc_event(inoev *iev) { return; } - /* lookup the watch descriptor in rbtree */ - paths = inotify_map_get_path(iev->wd); + /* lookup watch descriptors */ + watch_list = inotify_map_get_path(iev->wd); - if (!paths) { + if (!watch_list) { logmsg(LOG_WARN, "-- IGNORING EVENT -- invalid watchdescriptor %i", iev->wd); return; } @@ -154,12 +156,13 @@ static void proc_event(inoev *iev) { isdir = (iev->mask & IN_ISDIR) != 0; iev->mask &= ~IN_ISDIR; - for(path = paths; *path; path++) { + for(i=0; i < watch_list->nr; i++) { uint8_t type = NOTIFY_UNKNOWN; + struct watch *watch = watch_list->items[i]; notify_event *event = notify_event_new(); - notify_event_set_path(event, *path); + notify_event_set_path(event, watch->path); notify_event_set_filename(event, iev->name); event->dir = isdir; @@ -193,7 +196,7 @@ static void proc_event(inoev *iev) { event->type = type; } - free(paths); + list_destroy(watch_list); } int notify_init() { diff --git a/test/t_inotify-map.c b/test/t_inotify-map.c index 5a94e8b..f9f0524 100644 --- a/test/t_inotify-map.c +++ b/test/t_inotify-map.c @@ -23,23 +23,25 @@ static void teardown() { assert(inotify_map_isempty()); } -static void validate_list(int index, char **list) { +static int cmp(const void *a, const void *b) { + + struct watch *w = (struct watch *)a; + + return strcmp(w->path, b); +} + +static void validate_list(int index, struct list *list) { int i; assert(list); for(i=0; i < 4; i++) { - char **path, found = 0; if (i != wdref[index]) continue; - - for(path=list; !found && *path; path++) { - if (!strcmp(*path, pathref[index])) - found = 1; - } - assert(found); + + assert(list_has(list, pathref[index], cmp)); } }