wendy

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

commit 4ff6468aa26d8c9c7b85ca6cf6eac680e4d1ccc4
parent 5d5db1f773592dcba430662794f3cc33e8084559
Author: Willy Goiffon <dev@z3bra.org>
Date:   Wed,  4 Mar 2020 15:08:10 +0100

Read path from stdin when none provided

Diffstat:
Mwendy.1 | 6+++++-
Mwendy.c | 19+++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/wendy.1 b/wendy.1 @@ -35,7 +35,11 @@ default: IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MODIFY|IN_MOVE|IN_MOVE_SELF|IN_CL Specifies the file or directory to watch events in. You can specify multiple files by providing the .Fl w -flag multiple times. +flag multiple times. If no watcher is added with the -w flag, +.Nm +will read path names from +.Ar stdin , +one per line. .El .Sh MASKS The mask is a numeric value passed to inotify to specify the events that should diff --git a/wendy.c b/wendy.c @@ -87,6 +87,22 @@ watch(int fd, char *pathname, int mask) return w; } +int +watchstream(int fd, FILE *stream, int mask) +{ + ssize_t l, n = 0; + char *p = NULL; + + while (getline(&p, &n, stream) > 0) { + l = strlen(p); + p[l-1] = '\0'; + watch(fd, p, mask); + } + free(p); + + return 0; +} + char * wdpath(struct inotify_event *e, struct watcher *w) { @@ -143,6 +159,9 @@ main (int argc, char **argv) if (dflag) mask |= IN_ONLYDIR; + if (SLIST_EMPTY(&head)) + watchstream(fd, stdin, mask); + while (!SLIST_EMPTY(&head) && (off || (len=read(fd, buf, EVSZ))>0)) { /* cast buffer into the event structure */