]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: avoid misleading diagnostic upon fstat failure
authorJim Meyering <meyering@redhat.com>
Wed, 25 Jul 2012 16:35:36 +0000 (18:35 +0200)
committerJim Meyering <meyering@redhat.com>
Wed, 25 Jul 2012 17:00:22 +0000 (19:00 +0200)
* src/tail.c (check_fspec): Save fstat-induced errno *before*
calling close_fd, not after.  Otherwise, the close could well
clobber the global errno, making tail print an invalid diagnostic.
This could happen only with tail -f, and even then, only when
a valid file descriptor were to provoke fstat failure.

src/tail.c

index 29ddabd62c650c4b0c9ed9b52bb3270e25f1bb90..1935605efb6c2aa56ffd9f247ec9ec14098118de 100644 (file)
@@ -1276,9 +1276,9 @@ check_fspec (struct File_spec *fspec, int wd, int *prev_wd)
 
   if (fstat (fspec->fd, &stats) != 0)
     {
+      fspec->errnum = errno;
       close_fd (fspec->fd, name);
       fspec->fd = -1;
-      fspec->errnum = errno;
       return;
     }