Check for fatal errors, and exit immediately if we don't actually have anything to -f --- something like "tail -f /does/not/exist" should exit: it's -f's big brother -F that retries by name rather than by fd. --- toys/posix/tail.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-)
-- Elliott Hughes - http://who/enh - http://jessies.org/~enh/ Android native code/tools questions? Mail me/drop by/add me as a reviewer.
From dfc7555a86a9f2c394721edda018725cbb6617eb Mon Sep 17 00:00:00 2001 From: Elliott Hughes <[email protected]> Date: Mon, 21 Dec 2015 13:15:21 -0800 Subject: [PATCH] Better tail -f error checking. Check for fatal errors, and exit immediately if we don't actually have anything to -f --- something like "tail -f /does/not/exist" should exit: it's -f's big brother -F that retries by name rather than by fd. --- toys/posix/tail.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/toys/posix/tail.c b/toys/posix/tail.c index c2f71cb..b91aab3 100644 --- a/toys/posix/tail.c +++ b/toys/posix/tail.c @@ -149,8 +149,8 @@ static void do_tail(int fd, char *name) } // -f support: cache name/descriptor - TT.files[TT.file_no].fd = dup(fd); - TT.files[TT.file_no].path = strdup(name); + TT.files[TT.file_no].fd = xdup(fd); + TT.files[TT.file_no].path = xstrdup(name); ++TT.file_no; // Are we measuring from the end of the file? @@ -244,7 +244,7 @@ void tail_main(void) loopfiles(args, do_tail); // do -f stuff - if (toys.optflags & FLAG_f) { + if ((toys.optflags&FLAG_f) && TT.file_no>0) { int infd, last_wd, i; infd = inotify_init(); @@ -253,12 +253,8 @@ void tail_main(void) } for (i = 0; i < TT.file_no; ++i) { - #define STR(x) #x - char path[sizeof("/proc/self/fd/" STR(INT_MIN))]; - - snprintf(path, sizeof(path), "/proc/self/fd/%d", TT.files[i].fd); - - TT.files[i].wd = inotify_add_watch(infd, path, IN_MODIFY); + snprintf(toybuf, sizeof(toybuf), "/proc/self/fd/%d", TT.files[i].fd); + TT.files[i].wd = inotify_add_watch(infd, toybuf, IN_MODIFY); if (TT.files[i].wd < 0) { perror_msg("failed to add inotify watch for %s", TT.files[i].path); continue; -- 2.6.0.rc2.230.g3dd15c0
_______________________________________________ Toybox mailing list [email protected] http://lists.landley.net/listinfo.cgi/toybox-landley.net
