Skip to content

Commit

Permalink
Include support for watching symlinks.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvr committed Jan 19, 2017
1 parent adf1291 commit 0374500
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
5 changes: 1 addition & 4 deletions config/listener.conf
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#
# 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.
# }
#
# 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.
{
Expand Down Expand Up @@ -44,4 +42,3 @@
# ACCEPT_REGEX = ^[-+_[:alnum:]]+--[-.+_[:alnum:]]+--(i386|i686|ppc|arm920t)\.tar\.bz2$
# RECURSIVE_DEPTH = 1
#}

11 changes: 8 additions & 3 deletions src/listener.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
5 changes: 3 additions & 2 deletions src/listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/rules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0374500

Please sign in to comment.