(recheck): Handle a race condition (including <dev,inode>
authorJim Meyering <jim@meyering.net>
Mon, 22 Nov 1999 09:07:58 +0000 (09:07 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 22 Nov 1999 09:07:58 +0000 (09:07 +0000)
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

index 8179f5c..7a2c325 100644 (file)
@@ -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)