[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] tail: avoid misleading diagnostic upon fstat failure

From: Jim Meyering
Subject: [PATCH] tail: avoid misleading diagnostic upon fstat failure
Date: Thu, 26 Jul 2012 12:38:19 +0200

FYI.  This bug seems hard enough to trigger and low enough
impact that the fix does not deserve an entry in NEWS.
Provoking the failure might be tricky, since in addition to
causing fstat failure, you'd have to make the intervening
close (via close_fd) clobber errno, probably via EINTR or EIO.
Not worth trying to write a test, IMHO.

>From a6e8e3a3e116f2cdaa452eb66032d912092d0026 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Wed, 25 Jul 2012 18:35:36 +0200
Subject: [PATCH] tail: avoid misleading diagnostic upon fstat failure

* 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 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tail.c b/src/tail.c
index 29ddabd..1935605 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1276,9 +1276,9 @@ check_fspec (struct File_spec *fspec, int wd, int 

   if (fstat (fspec->fd, &stats) != 0)
+      fspec->errnum = errno;
       close_fd (fspec->fd, name);
       fspec->fd = -1;
-      fspec->errnum = errno;


reply via email to

[Prev in Thread] Current Thread [Next in Thread]