Archived
1
0
Fork 0

inotify-map: inotify_map_get_path: return a list of struct watch* instead of char **

This commit is contained in:
Henrik Hautakoski 2011-02-20 10:05:06 +01:00
parent 658bc8b9ad
commit ab91625700
4 changed files with 29 additions and 33 deletions

View file

@ -12,7 +12,6 @@
#include <string.h>
#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() {

View file

@ -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();

View file

@ -19,6 +19,7 @@
#include <sys/inotify.h>
#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() {