From 94777894a95044c5253ec081503085ab9947cfec Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sat, 25 May 2019 19:48:33 -0500 Subject: Move notify.c into portability.c (collate the #ifdefs), move global variables into a structure passed as arguments, add x prefix to functions that can fail, add overflow test. --- toys/posix/tail.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'toys/posix/tail.c') diff --git a/toys/posix/tail.c b/toys/posix/tail.c index 49a7f69b..d49a70c2 100644 --- a/toys/posix/tail.c +++ b/toys/posix/tail.c @@ -36,6 +36,7 @@ GLOBALS( long n, c; int file_no, last_fd; + struct xnotify *not; ) struct line_list { @@ -139,7 +140,7 @@ static void do_tail(int fd, char *name) char *s = name; if (!fd) sprintf(s = toybuf, "/proc/self/fd/%d", fd); - if (notify_add(fd, s) == -1) perror_exit("-f on '%s' failed", s); + if (xnotify_add(TT.not, fd, s)) perror_exit("-f on '%s' failed", s); } if (TT.file_no++) xputc('\n'); @@ -233,13 +234,13 @@ void tail_main(void) } } - if (FLAG(f)) notify_init(toys.optc); + if (FLAG(f)) TT.not = xnotify_init(toys.optc); loopfiles_rw(args, O_RDONLY|WARN_ONLY|(O_CLOEXEC*!FLAG(f)), 0, do_tail); if (FLAG(f) && TT.file_no) { for (;;) { char *path; - int fd = notify_wait(&path), len; + int fd = xnotify_wait(TT.not, &path), len; // Read new data. while ((len = read(fd, toybuf, sizeof(toybuf)))>0) { -- cgit v1.2.3