From 7eba3be3400fde5668a8a69d7a0d1d6a352651c5 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 22 Nov 1999 09:07:58 +0000 Subject: (recheck): Handle a race condition (including reuse) that would lead to a failed assertion. Reported by Ken Pizzini. (tail_forever): Record errno before using it in call to `error' which might change it. (tail_file): Likewise. --- src/tail.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/tail.c b/src/tail.c index 8179f5c8b..7a2c32506 100644 --- a/src/tail.c +++ b/src/tail.c @@ -789,7 +789,17 @@ recheck (struct File_spec *f) } else { - close_fd (fd, pretty_name (f)); + if (f->fd == -1) + { + /* This happens when one iteration finds the file missing, + then the preceding pair is reused as the + file is recreated. */ + new_file = 1; + } + else + { + close_fd (fd, pretty_name (f)); + } } if (new_file) @@ -855,9 +865,9 @@ tail_forever (struct File_spec *f, int nfiles) if (fstat (f[i].fd, &stats) < 0) { - error (0, errno, "%s", pretty_name (&f[i])); f[i].fd = -1; f[i].errnum = errno; + error (0, errno, "%s", pretty_name (&f[i])); continue; } @@ -1119,9 +1129,9 @@ tail_file (struct File_spec *f, off_t n_units) /* FIXME: duplicate code */ if (fstat (fd, &stats) < 0) { - error (0, errno, "%s", pretty_name (f)); errors = 1; f->errnum = errno; + error (0, errno, "%s", pretty_name (f)); } if (errors) -- cgit v1.2.3-70-g09d2