wendy

inotify based node watcher
git clone git://git.2f30.org/wendy
Log | Files | Refs | README | LICENSE

commit cff44da04995e9f4eda7483b47047295d345f1e6
parent 0176b6dc43a8dfb6682c3a76634e7b78e8354ed6
Author: Willy Goiffon <dev@z3bra.org>
Date:   Fri, 13 Mar 2020 11:04:36 +0100

Add -l flag to list numeric values of events

Diffstat:
Mwendy.1 | 4+++-
Mwendy.c | 22++++++++++++++++++++--
2 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/wendy.1 b/wendy.1 @@ -6,7 +6,7 @@ .Nd inotify based event watcher .Sh SYNOPSIS .Nm wendy -.Op Fl adrv +.Op Fl adlrv .Op Fl m Ar mask .Op Fl w Ar inode .Op command Op Ar args... @@ -24,6 +24,8 @@ Directory mode. Only directories will be watched, while regular files will be skipped (even if explicitely set with -w). See IN_ONLYDIR from .Xr inotify 7 . +.It Fl l +List events along with their numeric values. .It Fl r Recursive mode. Everytime an IN_CREATE event is triggered, a watch is added on the target file/directory. diff --git a/wendy.c b/wendy.c @@ -22,7 +22,7 @@ struct watcher { SLIST_HEAD(watchers, watcher) head; -char *evname[] = { +char *evname[IN_ALL_EVENTS] = { [IN_ACCESS] = "ACCESS", [IN_MODIFY] = "MODIFY", [IN_ATTRIB] = "ATTRIB", @@ -38,7 +38,7 @@ char *evname[] = { }; int verbose = 0; -int aflag = 0, dflag = 0, rflag = 0; +int aflag = 0, dflag = 0, lflag = 0, rflag = 0; void usage(char *name) @@ -54,6 +54,16 @@ basename(char *p) return *b ? b + 1 : p; } +int +listevents(char **ev) +{ + int i; + for (i=0; i<IN_ALL_EVENTS; i++) + if (ev[i]) + printf("%s\t%d\n", ev[i], i); + return 0; +} + struct watcher * getwatcher(struct watchers *h, int wd) { @@ -147,6 +157,9 @@ main (int argc, char **argv) case 'd': dflag = 1; break; + case 'l': + lflag = 1; + break; case 'r': rflag = 1; break; @@ -163,6 +176,11 @@ main (int argc, char **argv) usage(argv0); } ARGEND; + if (lflag) { + listevents(evname); + return 0; + } + /* remaining arguments is the command to run on event */ cmd = (argc > 0) ? argv : NULL;