diff options
author | June McEnroe <programble@gmail.com> | 2018-02-25 12:50:20 -0500 |
---|---|---|
committer | June McEnroe <programble@gmail.com> | 2018-02-25 12:50:20 -0500 |
commit | 622a1c15dd83b93b4c6cf0f133bd99b8151a7cae (patch) | |
tree | 6a6e9e1a8b12a2ebc210e451b9a42ace62cd0701 /bin | |
parent | Clean up klon (diff) | |
download | src-622a1c15dd83b93b4c6cf0f133bd99b8151a7cae.tar.gz src-622a1c15dd83b93b4c6cf0f133bd99b8151a7cae.zip |
Tweak watch exit codes
Diffstat (limited to '')
-rw-r--r-- | bin/watch.c | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/bin/watch.c b/bin/watch.c index 2787a45a..5b13b7e3 100644 --- a/bin/watch.c +++ b/bin/watch.c @@ -26,7 +26,7 @@ static void watch(int kq, char *path) { int fd = open(path, O_RDONLY); - if (fd < 0) err(EX_IOERR, "%s", path); + if (fd < 0) err(EX_NOINPUT, "%s", path); struct kevent event = { .ident = fd, @@ -36,7 +36,7 @@ static void watch(int kq, char *path) { .udata = path, }; int nevents = kevent(kq, &event, 1, NULL, 0, NULL); - if (nevents < 0) err(EX_IOERR, "kevent"); + if (nevents < 0) err(EX_OSERR, "kevent"); } static void exec(char *const argv[]) { @@ -44,8 +44,8 @@ static void exec(char *const argv[]) { if (pid < 0) err(EX_OSERR, "fork"); if (!pid) { - execvp(argv[0], argv); - err(EX_OSERR, "%s", argv[0]); + execvp(*argv, argv); + err(EX_NOINPUT, "%s", *argv); } int status; @@ -67,27 +67,27 @@ int main(int argc, char *argv[]) { int kq = kqueue(); if (kq < 0) err(EX_OSERR, "kqueue"); - int index; - for (index = 1; index < argc - 1; ++index) { - if (argv[index][0] == '-') { - index++; + int i; + for (i = 1; i < argc - 1; ++i) { + if (argv[i][0] == '-') { + i++; break; } - watch(kq, argv[index]); + watch(kq, argv[i]); } - exec(&argv[index]); + exec(&argv[i]); for (;;) { struct kevent event; int nevents = kevent(kq, NULL, 0, &event, 1, NULL); - if (nevents < 0) err(EX_IOERR, "kevent"); + if (nevents < 0) err(EX_OSERR, "kevent"); if (event.fflags & NOTE_DELETE) { close(event.ident); watch(kq, event.udata); } - exec(&argv[index]); + exec(&argv[i]); } } |