On 01/02/2023 20:37, Pádraig Brady wrote:
diff --git a/src/tail.c b/src/tail.c
index 2244509dd..309d93072 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1243,7 +1243,8 @@ tail_forever (struct File_spec *f, size_t n_files, double 
sleep_interval)
                         recheck (&f[i], f[i].blocking);
                         f[i].n_unchanged_stats = 0;
                       }
-                  continue;
+                  if (S_ISREG (stats.st_mode) || 1 < n_files)
+                    continue;
                   }

The above diff wouldn't work as it would always bypass the recheck().
Attached is an (untested) update, which might work for your case.

cheers,
Pádraig
From 82863c9e432c796cc146811722f6b3d27f20e65d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Wed, 1 Feb 2023 20:41:31 +0000
Subject: [PATCH] tail: support --follow=name with single non regular files

* src/tail (tail_forever): Attempt to read() from non blocking
single non regular file, which shouldn't block, but also
read data even when the mtime doesn't change.
---
 src/tail.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/tail.c b/src/tail.c
index 2244509dd..21274dc99 100644
--- a/src/tail.c
+++ b/src/tail.c
@@ -1221,6 +1221,7 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval)
                 f[i].blocking = blocking;
             }
 
+          bool read_unchanged = false;
           if (!f[i].blocking)
             {
               if (fstat (fd, &stats) != 0)
@@ -1243,7 +1244,10 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval)
                       recheck (&f[i], f[i].blocking);
                       f[i].n_unchanged_stats = 0;
                     }
-                  continue;
+                  if (S_ISREG (stats.st_mode) || 1 < n_files)
+                    continue;
+                  else
+                    read_unchanged = true;
                 }
 
               /* This file has changed.  Print out what we can, and
@@ -1253,7 +1257,8 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval)
               f[i].mode = stats.st_mode;
 
               /* reset counter */
-              f[i].n_unchanged_stats = 0;
+              if (! read_unchanged)
+                f[i].n_unchanged_stats = 0;
 
               /* XXX: This is only a heuristic, as the file may have also
                  been truncated and written to if st_size >= size
@@ -1288,6 +1293,9 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval)
 
           bytes_read = dump_remainder (false, name, fd, bytes_to_read);
 
+          if (read_unchanged && bytes_read)
+            f[i].n_unchanged_stats = 0;
+
           any_input |= (bytes_read != 0);
           f[i].size += bytes_read;
         }
-- 
2.26.2

Reply via email to