]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
tail: use consistent diagnostics with and without inotify
authorPádraig Brady <P@draigBrady.com>
Mon, 9 Dec 2013 01:58:25 +0000 (01:58 +0000)
committerPádraig Brady <P@draigBrady.com>
Mon, 9 Dec 2013 09:26:17 +0000 (09:26 +0000)
* src/tail.c: With inotify, when a file is initially absent,
we fstat(-1) for that file spec, thus recording an errnum of EBADF,
which caused the "has become accessible" diagnostic to be issued,
when the file first appears.  Instead we avoid the fstat(-1) and
thus emit the more natural and consistent "has appeared" diagnostic.
* tests/tail-2/retry.sh: Use the new diagnostic which also causes
this test to pass on systems without inotify.

src/tail.c
tests/tail-2/retry.sh

index c781dc2fac62dcb07141145969028450bff12bee..dc4e10df0072b6031728f356c8689abb357e9ed5 100644 (file)
@@ -1315,7 +1315,12 @@ static void
 check_fspec (struct File_spec *fspec, int wd, int *prev_wd)
 {
   struct stat stats;
-  char const *name = pretty_name (fspec);
+  char const *name;
+
+  if (fspec->fd == -1)
+    return;
+
+  name = pretty_name (fspec);
 
   if (fstat (fspec->fd, &stats) != 0)
     {
index 7ba773475786398b6204c6d5c48fca09ab485596..ce67a459421dec342c5aa837ec2f4ba732ead1e0 100755 (executable)
@@ -53,11 +53,11 @@ retry_delay_ wait4lines_ .1 6 3 || fail=1  # Wait for the expected output.
 kill $pid
 wait $pid
 # Expect 3 lines in the output file.
-[ $( wc -l < out ) = 3 ]            || { fail=1; cat out; }
-grep -F 'cannot open' out           || { fail=1; cat out; }
-grep -F 'has become accessible' out || { fail=1; cat out; }
-grep '^X$' out                      || { fail=1; cat out; }
-rm -f missing out                   || framework_failure_
+[ $( wc -l < out ) = 3 ]   || { fail=1; cat out; }
+grep -F 'cannot open' out  || { fail=1; cat out; }
+grep -F 'has appeared' out || { fail=1; cat out; }
+grep '^X$' out             || { fail=1; cat out; }
+rm -f missing out          || framework_failure_
 
 # === Test:
 # Ensure that "tail --retry --follow=descriptor" waits for the file to appear.