summaryrefslogtreecommitdiff
path: root/src/tail.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-11-22 09:07:58 +0000
committerJim Meyering <jim@meyering.net>1999-11-22 09:07:58 +0000
commit7eba3be3400fde5668a8a69d7a0d1d6a352651c5 (patch)
treeba3dd99d56bcdbf9f30359d84e4a8e863ac49b52 /src/tail.c
parent971da27132cc5662fe8349c906b252e720f5c0bb (diff)
downloadcoreutils-7eba3be3400fde5668a8a69d7a0d1d6a352651c5.tar.xz
(recheck): Handle a race condition (including <dev,inode>
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.
Diffstat (limited to 'src/tail.c')
-rw-r--r--src/tail.c16
1 files 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 <dev,inode> 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)