From 98613d454671ebc3e1a761788453542cd93e6ada Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 4 Jul 2021 12:24:32 -0500 Subject: Fix tail -F with no arguments. fstat() doesn't fail on stdin, so check for fd 0 explicitly so we don't try to access zero length array when optc was zero. (Plus can't reopen '-'.) --- toys/posix/tail.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/toys/posix/tail.c b/toys/posix/tail.c index 98309c0f..0d13ab01 100644 --- a/toys/posix/tail.c +++ b/toys/posix/tail.c @@ -188,7 +188,9 @@ static void do_tail(int fd, char *name) long bytes = TT.c, lines = TT.n; int linepop = 1; - if (fd == -1 && !FLAG(F)) return; + if (FLAG(F)) { + if (!fd) perror_exit("no -F with '-'"); + } else if (fd == -1) return; if (FLAG(f) || FLAG(F)) { char *s = name; struct stat sb; -- cgit v1.2.3