From 0374500735b4f9b94fb2d9b5ce8b519c765cd259 Mon Sep 17 00:00:00 2001 From: "Lucas C. Villa Real" Date: Thu, 19 Jan 2017 15:07:55 -0200 Subject: [PATCH] Include support for watching symlinks. --- config/listener.conf | 5 +---- src/listener.c | 11 ++++++++--- src/listener.h | 5 +++-- src/rules.c | 2 ++ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/config/listener.conf b/config/listener.conf index b409a3d..8f39615 100644 --- a/config/listener.conf +++ b/config/listener.conf @@ -1,11 +1,10 @@ -# # Syntax: # { # TARGET = Directory to monitor # WATCHES = Events to monitor (ACCESS, MODIFY, ATTRIB, CLOSE_WRITE, CLOSE_NOWRITE, # OPEN, MOVED_FROM, MOVED_TO, CREATE, DELETE, DELETE_SELF and/or MOVE_SELF) # SPAWN = Program to spawn. $ENTRY holds the pathname being processed -# LOOKAT = What to monitor in the target directory (FILES, DIRS) +# LOOKAT = What to monitor in the target directory (FILES, DIRS, SYMLINKS) # ACCEPT_REGEX = Regex to limit the kind of FILES/DIRS that the rule cares about # RECURSIVE_DEPTH = Describes how many levels to descend in TARGET applying the same rule. # Minimum value is 0 and maximum is 127. @@ -13,7 +12,6 @@ # # NOTE: The parser expects the entries to be entered in the following sequence: # TARGET, WATCHES, SPAWN, LOOKAT, ACCEPT_REGEX and RECURSIVE_DEPTH. -# # Removes broken links when a version directory under /Programs is deleted. { @@ -44,4 +42,3 @@ # ACCEPT_REGEX = ^[-+_[:alnum:]]+--[-.+_[:alnum:]]+--(i386|i686|ppc|arm920t)\.tar\.bz2$ # RECURSIVE_DEPTH = 1 #} - diff --git a/src/listener.c b/src/listener.c index 0733207..5cbb093 100644 --- a/src/listener.c +++ b/src/listener.c @@ -246,12 +246,17 @@ handle_events(struct inotify_event *ev) } if (FILTER_DIRS(di->filter) && !FILTER_FILES(di->filter) && !S_ISDIR(status.st_mode)) { - debug_printf("watch descriptor %d listens for DIRS rules, but event happened in another kind of object\n", di->wd); + debug_printf("watch descriptor %d listens for DIRS, but event happened in another kind of object\n", di->wd); goto cleanup; } - + if (FILTER_FILES(di->filter) && !FILTER_DIRS(di->filter) && !S_ISREG(status.st_mode)) { - debug_printf("watch descriptor %d listens for FILES rules, but event happened in another kind of object\n", di->wd); + debug_printf("watch descriptor %d listens for FILES, but event happened in another kind of object\n", di->wd); + goto cleanup; + } + + if (FILTER_FILES(di->filter) && !FILTER_SYMLINKS(di->filter) && !S_ISLNK(status.st_mode)) { + debug_printf("watch descriptor %d listens for SYMLINKS, but event happened in another kind of object\n", di->wd); goto cleanup; } diff --git a/src/listener.h b/src/listener.h index 1f1776b..0b36314 100644 --- a/src/listener.h +++ b/src/listener.h @@ -54,8 +54,9 @@ #define LISTENER_RULES SYSCONFDIR"/listener.conf" #define EMPTY_MASK 0 -#define FILTER_DIRS(m) S_ISDIR(m) -#define FILTER_FILES(m) S_ISREG(m) +#define FILTER_DIRS(m) S_ISDIR(m) +#define FILTER_FILES(m) S_ISREG(m) +#define FILTER_SYMLINKS(m) S_ISLNK(m) #define MAX_RECUSIVE_DEPTH 127 diff --git a/src/rules.c b/src/rules.c index 23fc812..4bc7f87 100644 --- a/src/rules.c +++ b/src/rules.c @@ -332,6 +332,8 @@ assign_rules(char *config_file, int *retval) di->filter = S_IFDIR; else if (! strcasecmp(token, "FILES")) di->filter = S_IFREG; + else if (! strcasecmp(token, "SYMLINKS")) + di->filter = S_IFLNK; else { fprintf(stderr, "Error on rule #%d: invalid LOOKAT option %s\n", i+1, token); free(token);