watcher: exit if errors occur.

This commit is contained in:
John "Elwin" Edwards 2015-01-07 13:22:05 -05:00
parent 3c88c233b4
commit 537c227f87

View file

@ -43,7 +43,7 @@ int startwatch(int ifd, char *dir, struct watchdir *w) {
}
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 @@ int main(int argc, char *argv[]) {
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 @@ int main(int argc, char *argv[]) {
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;
}