inotify-map: inotify_map_get_path: return a list of struct watch* instead of char **
This commit is contained in:
parent
658bc8b9ad
commit
ab91625700
4 changed files with 29 additions and 33 deletions
|
|
@ -12,7 +12,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "xalloc.h"
|
#include "xalloc.h"
|
||||||
#include "rbtree.h"
|
#include "rbtree.h"
|
||||||
#include "list.h"
|
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
#include "inotify-watch.h"
|
#include "inotify-watch.h"
|
||||||
#include "inotify-map.h"
|
#include "inotify-map.h"
|
||||||
|
|
@ -192,23 +191,12 @@ int inotify_map_get_wd(const char *path) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** inotify_map_get_path(int wd) {
|
struct list* inotify_map_get_path(int wd) {
|
||||||
|
|
||||||
char **out = NULL;
|
struct list *list = wd_lookup(wd);
|
||||||
struct list *list;
|
if (list)
|
||||||
|
return list_copy(list);
|
||||||
list = wd_lookup(wd);
|
return NULL;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int inotify_map_isempty() {
|
int inotify_map_isempty() {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,9 @@
|
||||||
#ifndef __INOTIFY_MAP_H
|
#ifndef __INOTIFY_MAP_H
|
||||||
#define __INOTIFY_MAP_H
|
#define __INOTIFY_MAP_H
|
||||||
|
|
||||||
|
#include "list.h"
|
||||||
|
#include "inotify-watch.h"
|
||||||
|
|
||||||
void inotify_map(int wd, const char *path);
|
void inotify_map(int wd, const char *path);
|
||||||
|
|
||||||
int inotify_unmap_wd(int wd);
|
int inotify_unmap_wd(int wd);
|
||||||
|
|
@ -21,7 +24,7 @@ void inotify_unmap_all();
|
||||||
|
|
||||||
int inotify_map_get_wd(const char *path);
|
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();
|
int inotify_map_isempty();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include <sys/inotify.h>
|
#include <sys/inotify.h>
|
||||||
|
|
||||||
#include "inotify-map.h"
|
#include "inotify-map.h"
|
||||||
|
#include "inotify-watch.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "path.h"
|
#include "path.h"
|
||||||
|
|
@ -132,7 +133,8 @@ static int rmwatch(const char *path, const char *name) {
|
||||||
|
|
||||||
static void proc_event(inoev *iev) {
|
static void proc_event(inoev *iev) {
|
||||||
|
|
||||||
char **paths, **path;
|
int i;
|
||||||
|
struct list *watch_list;
|
||||||
int isdir;
|
int isdir;
|
||||||
|
|
||||||
logmsg(LOG_DEBUG, "RAW EVENT: %i, %x, %s", iev->wd, iev->mask, iev->name);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* lookup the watch descriptor in rbtree */
|
/* lookup watch descriptors */
|
||||||
paths = inotify_map_get_path(iev->wd);
|
watch_list = inotify_map_get_path(iev->wd);
|
||||||
|
|
||||||
if (!paths) {
|
if (!watch_list) {
|
||||||
logmsg(LOG_WARN, "-- IGNORING EVENT -- invalid watchdescriptor %i", iev->wd);
|
logmsg(LOG_WARN, "-- IGNORING EVENT -- invalid watchdescriptor %i", iev->wd);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -154,12 +156,13 @@ static void proc_event(inoev *iev) {
|
||||||
isdir = (iev->mask & IN_ISDIR) != 0;
|
isdir = (iev->mask & IN_ISDIR) != 0;
|
||||||
iev->mask &= ~IN_ISDIR;
|
iev->mask &= ~IN_ISDIR;
|
||||||
|
|
||||||
for(path = paths; *path; path++) {
|
for(i=0; i < watch_list->nr; i++) {
|
||||||
|
|
||||||
uint8_t type = NOTIFY_UNKNOWN;
|
uint8_t type = NOTIFY_UNKNOWN;
|
||||||
|
struct watch *watch = watch_list->items[i];
|
||||||
notify_event *event = notify_event_new();
|
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);
|
notify_event_set_filename(event, iev->name);
|
||||||
event->dir = isdir;
|
event->dir = isdir;
|
||||||
|
|
||||||
|
|
@ -193,7 +196,7 @@ static void proc_event(inoev *iev) {
|
||||||
event->type = type;
|
event->type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(paths);
|
list_destroy(watch_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
int notify_init() {
|
int notify_init() {
|
||||||
|
|
|
||||||
|
|
@ -23,23 +23,25 @@ static void teardown() {
|
||||||
assert(inotify_map_isempty());
|
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;
|
int i;
|
||||||
|
|
||||||
assert(list);
|
assert(list);
|
||||||
|
|
||||||
for(i=0; i < 4; i++) {
|
for(i=0; i < 4; i++) {
|
||||||
char **path, found = 0;
|
|
||||||
|
|
||||||
if (i != wdref[index])
|
if (i != wdref[index])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for(path=list; !found && *path; path++) {
|
assert(list_has(list, pathref[index], cmp));
|
||||||
if (!strcmp(*path, pathref[index]))
|
|
||||||
found = 1;
|
|
||||||
}
|
|
||||||
assert(found);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue