# HG changeset patch # User John "Elwin" Edwards # Date 1420654925 18000 # Node ID 66fef65c34e7286f0b6d8378de3b3291d84dc273 # Parent 59e62710cbb5cb5dddab1950e86e68d2d2bee1a4 watcher: exit if errors occur. diff -r 59e62710cbb5 -r 66fef65c34e7 watcher.c --- a/watcher.c Wed Jan 07 13:18:35 2015 -0500 +++ b/watcher.c Wed Jan 07 13:22:05 2015 -0500 @@ -43,7 +43,7 @@ } int main(int argc, char *argv[]) { - int ifd, rsize, off, done, nwatchers, i; + int ifd, rsize, off, done, nwatchers, i, result; char typecode; struct inotify_event *iev; fd_set rfds; @@ -69,7 +69,11 @@ FD_ZERO(&rfds); FD_SET(0, &rfds); FD_SET(ifd, &rfds); - select(ifd + 1, &rfds, NULL, NULL, NULL); + result = select(ifd + 1, &rfds, NULL, NULL, NULL); + if (result < 0) { + /* Something went wrong. */ + break; + } if (FD_ISSET(ifd, &rfds)) { off = 0; rsize = read(ifd, ibuf, sizeof(struct inotify_event) + NAME_MAX + 1); @@ -90,7 +94,11 @@ fflush(stdout); } if (FD_ISSET(0, &rfds)) { - read(0, &typecode, 1); + result = read(0, &typecode, 1); + if (result <= 0) { + /* EOF on stdin: controlling process probably died. */ + done = 1; + } if (typecode == '\n') done = 1; }