From: Jim Meyering Date: Mon, 22 Nov 1999 09:07:58 +0000 (+0000) Subject: (recheck): Handle a race condition (including X-Git-Tag: FILEUTILS-4_0j~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7eba3be3400fde5668a8a69d7a0d1d6a352651c5;p=platform%2Fupstream%2Fcoreutils.git (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. --- diff --git a/src/tail.c b/src/tail.c index 8179f5c..7a2c325 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)