From unknown Fri Aug 15 17:55:15 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#23539 <23539@debbugs.gnu.org> To: bug#23539 <23539@debbugs.gnu.org> Subject: Status: tail -f file name headings displayed too many times after suspend Reply-To: bug#23539 <23539@debbugs.gnu.org> Date: Sat, 16 Aug 2025 00:55:15 +0000 retitle 23539 tail -f file name headings displayed too many times after sus= pend reassign 23539 coreutils submitter 23539 Janne Snabb severity 23539 normal tag 23539 fixed thanks From debbugs-submit-bounces@debbugs.gnu.org Sat May 14 18:15:49 2016 Received: (at submit) by debbugs.gnu.org; 14 May 2016 22:15:49 +0000 Received: from localhost ([127.0.0.1]:51794 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1hqd-00014j-NF for submit@debbugs.gnu.org; Sat, 14 May 2016 18:15:49 -0400 Received: from eggs.gnu.org ([208.118.235.92]:55755) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1gtD-00084x-PX for submit@debbugs.gnu.org; Sat, 14 May 2016 17:14:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1gt7-0006jp-Lz for submit@debbugs.gnu.org; Sat, 14 May 2016 17:14:18 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:53818) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1gt7-0006jd-Jd for submit@debbugs.gnu.org; Sat, 14 May 2016 17:14:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46704) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1gt5-00084O-Fh for bug-coreutils@gnu.org; Sat, 14 May 2016 17:14:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b1gt1-0006iw-QV for bug-coreutils@gnu.org; Sat, 14 May 2016 17:14:14 -0400 Received: from chmaa.epipe.com ([2a01:4f8:c17:2a9b::2]:56510) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b1gss-0006hi-Kg for bug-coreutils@gnu.org; Sat, 14 May 2016 17:14:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=epipe.com; s=default; h=Content-Transfer-Encoding:Content-Type:MIME-Version:Date: Message-ID:Subject:From:To; bh=2Wi98NtKji/zGn3P0g2mAYv0ggocWFoZK3YDVag9UI4=; b=XtAXGfd4mhcLjzSjTuXLv36o736zYeamPR/N1f6WZXtAspnuTqI6we1RbwUmoSIX4Iu2CshX0O FJxZLub+rJoHW1KTyZdHoA6YjJEkbz/5HZGd2Iih/DXy5becbe0DHgwTg3lboU0+qEAM8iYwuLIhK +gXmF6uSAWFSsHKRzauo=; Received: by chmaa.epipe.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1b1gIo-0006Qe-LG for bug-coreutils@gnu.org; Sat, 14 May 2016 20:36:46 +0000 To: bug-coreutils@gnu.org From: Janne Snabb Subject: tail -f file name headings displayed too many times after suspend Message-ID: <57378C33.5040605@epipe.com> Date: Sat, 14 May 2016 23:36:03 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -4.1 (----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sat, 14 May 2016 18:15:46 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -4.1 (----) Hi, I have a habit of running "tail -F /some/log/file /other/log/file" in my shell window. Whenever I need that shell window for something else, I hit ctrl-Z to suspend the tail. Then I do whatever I need to do. After I am done I do "fg" to get back to displaying the tail of the log files. I get the log output that I missed while tail was suspended. However that is followed by several extra file name headings with no log output following the headings. Like this: ==> /var/log/nginx/access.log <== ==> /var/log/nginx/error.log <== ==> /var/log/nginx/access.log <== ==> /var/log/nginx/error.log <== ==> /var/log/nginx/access.log <== This happens at least on Ubuntu 16.04 (4.4.0 kernel) and CentOS 7 (3.1.0 kernel) on x86_64 architecture. It happens with distro provided tail (coreutils 8.25 on Ubuntu and coreutils 8.22 on CentOS) as well as with coreutils 8.25 compiled from sources. I also tried this on FreeBSD 8.4 (which does not have inotify) with coreutils 8.25 but I was unable to reproduce it there. So it seems to be Linux and inotify dependent. I have been seeing this for long time, but I am unsure how long. I finally took the effort to report this. I wrote a shell script (#1) which demonstrates the problem: #!/bin/sh echo start > file1 echo start > file2 tail -f file1 file2 & pid=$! sleep 1 kill -STOP $pid sleep 1 echo line >> file1 sleep 1 echo line >> file2 sleep 1 echo line >> file1 sleep 1 echo line >> file2 sleep 1 kill -CONT $pid sleep 1 kill -TERM $pid # end The output of the above script ends with extra file name headings. However the following script (#2) does not exhibit this behaviour: #!/bin/sh echo start > file1 echo start > file2 tail -f file1 file2 & pid=$! sleep 1 kill -STOP $pid sleep 1 echo line >> file1 sleep 1 echo line >> file1 sleep 1 echo line >> file2 sleep 1 echo line >> file2 sleep 1 kill -CONT $pid sleep 1 kill -TERM $pid # end The only difference between these two scripts is the ordering of the writes to the files which are being tail'ed. If the writes are interleaved, tail displays extra file name headings. If I add the ---disable-inotify option to the tail commend line there is no extra file name headings. Thus this is clearly inotify related. I believe the extra file name headings are not displayed in case #2 because the following check in check_fspec() function suppresses them: if (fspec != *prev_fspec) This only suppresses the headings if the inotify events are not interleaved (case #2). I am unsure how to fix this. Best Regards, -- Janne Snabb snabb@epipe.com From debbugs-submit-bounces@debbugs.gnu.org Sun May 15 13:08:54 2016 Received: (at 23539) by debbugs.gnu.org; 15 May 2016 17:08:54 +0000 Received: from localhost ([127.0.0.1]:52956 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1zX9-0003UJ-0T for submit@debbugs.gnu.org; Sun, 15 May 2016 13:08:54 -0400 Received: from chmaa.epipe.com ([78.47.43.199]:37338) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b1s7q-0004uA-7j for 23539@debbugs.gnu.org; Sun, 15 May 2016 05:14:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=epipe.com; s=default; h=Content-Type:MIME-Version:Date:Message-ID:Subject:From:To; bh=FEBsBX3qkVftkbiZBi/fkfMq6NexAkCvoJpTblwo37I=; b=BCj0RQPsFAU/EJiMh95PG2VhsZ HfnAOk99A7uMKr7Fzsl9NDF1Lmyr4VWxWz/vAw8lb9HXzckkqjdoB4VGxcBnSeEyiWX2vRUkLoE9Q Gj+0clRWdspWgCikhLImc1VKkCBXkYuc785ofNbuYojccBGuvxFZg3nEfWHWJlGFoy8I=; Received: by chmaa.epipe.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1b1idw-0006nB-Na for 23539@debbugs.gnu.org; Sat, 14 May 2016 23:06:44 +0000 To: 23539@debbugs.gnu.org From: Janne Snabb Subject: bug#23539: tail -f file name headings displayed too many times after suspend Message-ID: <5737AF5A.3070308@epipe.com> Date: Sun, 15 May 2016 02:06:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------040008080606040506050600" X-Spam-Score: -1.4 (-) X-Debbugs-Envelope-To: 23539 X-Mailman-Approved-At: Sun, 15 May 2016 13:08:49 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.4 (-) This is a multi-part message in MIME format. --------------040008080606040506050600 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit The attached patch fixes this bug for me. The patch moves the write_header() call in the inotify case to dump_remainder() where write_header() is called only if some file content is going to be output. I am not sure if this is the best approach. Another approach would be to change the inotify event handling so that all queued events are read at once and duplicates are eliminated before acting on them. Now it reads and acts on them one. -- Janne Snabb snabb@epipe.com --------------040008080606040506050600 Content-Type: text/x-patch; name="tail-f-inotify-excess-header-output.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="tail-f-inotify-excess-header-output.patch" --- src/tail.c.dist 2016-01-19 18:09:56.000000000 +0200 +++ src/tail.c 2016-05-15 01:58:47.219808135 +0300 @@ -398,7 +398,7 @@ Return the number of bytes read from the file. */ =20 static uintmax_t -dump_remainder (const char *pretty_filename, int fd, uintmax_t n_bytes) +dump_remainder (bool want_header, const char *pretty_filename, int fd, u= intmax_t n_bytes) { uintmax_t n_written; uintmax_t n_remaining =3D n_bytes; @@ -418,6 +418,10 @@ } if (bytes_read =3D=3D 0) break; + if (want_header) { + write_header(pretty_filename); + want_header =3D false; + } xwrite_stdout (buffer, bytes_read); n_written +=3D bytes_read; if (n_bytes !=3D COPY_TO_EOF) @@ -527,7 +531,7 @@ output the part that is after it. */ if (n !=3D bytes_read - 1) xwrite_stdout (nl + 1, bytes_read - (n + 1)); - *read_pos +=3D dump_remainder (pretty_filename, fd, + *read_pos +=3D dump_remainder (false, pretty_filename, fd,= end_pos - (pos + bytes_read))= ; return true; } @@ -539,7 +543,7 @@ /* Not enough lines in the file; print everything from start_pos to the end. */ xlseek (fd, start_pos, SEEK_SET, pretty_filename); - *read_pos =3D start_pos + dump_remainder (pretty_filename, fd,= + *read_pos =3D start_pos + dump_remainder (false, pretty_filena= me, fd, end_pos); return true; } @@ -1216,7 +1220,7 @@ } } =20 - bytes_read =3D dump_remainder (name, fd, + bytes_read =3D dump_remainder (false, name, fd, (f[i].blocking ? COPY_A_BUFFER : COPY_TO_EOF));= any_input |=3D (bytes_read !=3D 0); @@ -1365,14 +1369,15 @@ && timespec_cmp (fspec->mtime, get_stat_mtime (&stats)) =3D=3D= 0) return; =20 + bool want_header =3D false; if (fspec !=3D *prev_fspec) { if (print_headers) - write_header (name); + want_header =3D true; *prev_fspec =3D fspec; } =20 - uintmax_t bytes_read =3D dump_remainder (name, fspec->fd, COPY_TO_EOF)= ; + uintmax_t bytes_read =3D dump_remainder (want_header, name, fspec->fd,= COPY_TO_EOF); fspec->size +=3D bytes_read; =20 if (fflush (stdout) !=3D 0) @@ -1786,7 +1791,7 @@ *read_pos =3D current_pos; } =20 - *read_pos +=3D dump_remainder (pretty_filename, fd, n_bytes); + *read_pos +=3D dump_remainder (false, pretty_filename, fd, n_bytes); return true; } =20 @@ -1810,7 +1815,7 @@ int t =3D start_lines (pretty_filename, fd, n_lines, read_pos); if (t) return t < 0; - *read_pos +=3D dump_remainder (pretty_filename, fd, COPY_TO_EOF); + *read_pos +=3D dump_remainder (false, pretty_filename, fd, COPY_TO= _EOF); } else { --------------040008080606040506050600-- From debbugs-submit-bounces@debbugs.gnu.org Fri May 20 08:08:29 2016 Received: (at 23539) by debbugs.gnu.org; 20 May 2016 12:08:29 +0000 Received: from localhost ([127.0.0.1]:58648 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3jED-0003dM-8X for submit@debbugs.gnu.org; Fri, 20 May 2016 08:08:29 -0400 Received: from mail.magicbluesmoke.com ([82.195.144.49]:34736) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b3jEC-0003dF-D3 for 23539@debbugs.gnu.org; Fri, 20 May 2016 08:08:28 -0400 Received: from [192.168.1.80] (unknown [109.76.181.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 544F823C; Fri, 20 May 2016 13:08:23 +0100 (IST) Subject: Re: bug#23539: tail -f file name headings displayed too many times after suspend To: Janne Snabb , 23539@debbugs.gnu.org References: <57378C33.5040605@epipe.com> <5737AF5A.3070308@epipe.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <573EFE2C.9010606@draigBrady.com> Date: Fri, 20 May 2016 13:08:12 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <5737AF5A.3070308@epipe.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 23539 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 15/05/16 00:06, Janne Snabb wrote: > The attached patch fixes this bug for me. > > The patch moves the write_header() call in the inotify case to > dump_remainder() where write_header() is called only if some file > content is going to be output. > > I am not sure if this is the best approach. Another approach would be to > change the inotify event handling so that all queued events are read at > once and duplicates are eliminated before acting on them. Now it reads > and acts on them one. I'd prefer to handle this much like you've done in the patch. I.E. avoid more complications with inotify. However consider the case where a file is truncated, with your patch subsequent writes will not get a header. I.E. echo file1 > file1 echo file2 > file2 tail -f file1 file2 Then in parallel: > file1 echo file1 > file1 You'll get output like: ==> file1 <== file1 ==> file2 <== file2 tail: file1: file truncated file1 I suppose you could track the header_outputted state in each File_spec? thanks! Pádraig From debbugs-submit-bounces@debbugs.gnu.org Tue Feb 07 02:42:46 2017 Received: (at 23539) by debbugs.gnu.org; 7 Feb 2017 07:42:46 +0000 Received: from localhost ([127.0.0.1]:58279 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cb0Q8-0005z0-Jf for submit@debbugs.gnu.org; Tue, 07 Feb 2017 02:42:46 -0500 Received: from midir.magicbluesmoke.com ([82.195.144.46]:33908 helo=mail.magicbluesmoke.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cb0Q3-0005yo-Ej for 23539@debbugs.gnu.org; Tue, 07 Feb 2017 02:42:35 -0500 Received: from [10.0.0.126] (c-73-170-254-78.hsd1.ca.comcast.net [73.170.254.78]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 9948E4B07; Tue, 7 Feb 2017 07:42:29 +0000 (GMT) Subject: Re: bug#23539: tail -f file name headings displayed too many times after suspend To: Janne Snabb , 23539@debbugs.gnu.org References: <57378C33.5040605@epipe.com> <5737AF5A.3070308@epipe.com> <573EFE2C.9010606@draigBrady.com> From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: Date: Mon, 6 Feb 2017 23:42:27 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 MIME-Version: 1.0 In-Reply-To: <573EFE2C.9010606@draigBrady.com> Content-Type: multipart/mixed; boundary="------------5EB8B9D1496A8D01167FFCDE" X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: 23539 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) This is a multi-part message in MIME format. --------------5EB8B9D1496A8D01167FFCDE Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit unarchive 23539 close 23539 stop On 20/05/16 05:08, Pádraig Brady wrote: > On 15/05/16 00:06, Janne Snabb wrote: >> The attached patch fixes this bug for me. >> >> The patch moves the write_header() call in the inotify case to >> dump_remainder() where write_header() is called only if some file >> content is going to be output. >> >> I am not sure if this is the best approach. Another approach would be to >> change the inotify event handling so that all queued events are read at >> once and duplicates are eliminated before acting on them. Now it reads >> and acts on them one. > > I'd prefer to handle this much like you've done in the patch. > I.E. avoid more complications with inotify. > However consider the case where a file is truncated, > with your patch subsequent writes will not get a header. I.E. > > echo file1 > file1 > echo file2 > file2 > tail -f file1 file2 > > Then in parallel: > > > file1 > echo file1 > file1 > > You'll get output like: > > ==> file1 <== > file1 > > ==> file2 <== > file2 > tail: file1: file truncated > file1 The attached variant also handles the case above, and includes a test. I'll push in your name tomorrow. sorry for the delay on this. Pádraig --------------5EB8B9D1496A8D01167FFCDE Content-Type: text/x-patch; name="tail-suspend.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="tail-suspend.patch" >From 1504dc0bb85422b8a8aa3d3a74a7db8c4b1f0578 Mon Sep 17 00:00:00 2001 From: Janne Snabb Date: Mon, 6 Feb 2017 23:15:42 -0800 Subject: [PATCH] tail: fix output of redundant headers when resuming * src/tail.c (check_fspec): Only enable printing of the file header if we've actually read some data and this is a new file. Also move printing of the file header to... (dump_remainder): ...here, to allow printing only when data read. * tests/tail-2/overlay-headers.sh: A new test for suspension and resumption of tail. * tests/local.mk: Reference the new test. * NEWS: Mention the fix. Fixes http://bugs.gnu.org/23539 --- NEWS | 4 ++ src/tail.c | 39 ++++++++++++-------- tests/local.mk | 1 + tests/tail-2/overlay-headers.sh | 81 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 109 insertions(+), 16 deletions(-) create mode 100755 tests/tail-2/overlay-headers.sh diff --git a/NEWS b/NEWS index 24082f5..9528f89 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,10 @@ GNU coreutils NEWS -*- outline -*- 158909489063877810457 and 222087527029934481871. [bug introduced in coreutils-8.20] + tail no longer prints redundant file headers with interleaved inotify events, + which could be triggered especially when tail was suspended and resumed. + [bug introduced with inotify support added in coreutils-7.5] + wc --bytes --files0-from now correctly reports byte counts. Previously it may have returned values that were too large, depending on the size of the first file processed. diff --git a/src/tail.c b/src/tail.c index 3023dd4..e060e99 100644 --- a/src/tail.c +++ b/src/tail.c @@ -399,7 +399,8 @@ xwrite_stdout (char const *buffer, size_t n_bytes) Return the number of bytes read from the file. */ static uintmax_t -dump_remainder (const char *pretty_filename, int fd, uintmax_t n_bytes) +dump_remainder (bool want_header, const char *pretty_filename, int fd, + uintmax_t n_bytes) { uintmax_t n_written; uintmax_t n_remaining = n_bytes; @@ -419,6 +420,11 @@ dump_remainder (const char *pretty_filename, int fd, uintmax_t n_bytes) } if (bytes_read == 0) break; + if (want_header) + { + write_header (pretty_filename); + want_header = false; + } xwrite_stdout (buffer, bytes_read); n_written += bytes_read; if (n_bytes != COPY_TO_EOF) @@ -528,7 +534,7 @@ file_lines (const char *pretty_filename, int fd, uintmax_t n_lines, output the part that is after it. */ if (n != bytes_read - 1) xwrite_stdout (nl + 1, bytes_read - (n + 1)); - *read_pos += dump_remainder (pretty_filename, fd, + *read_pos += dump_remainder (false, pretty_filename, fd, end_pos - (pos + bytes_read)); return true; } @@ -540,7 +546,7 @@ file_lines (const char *pretty_filename, int fd, uintmax_t n_lines, /* Not enough lines in the file; print everything from start_pos to the end. */ xlseek (fd, start_pos, SEEK_SET, pretty_filename); - *read_pos = start_pos + dump_remainder (pretty_filename, fd, + *read_pos = start_pos + dump_remainder (false, pretty_filename, fd, end_pos); return true; } @@ -1224,7 +1230,7 @@ tail_forever (struct File_spec *f, size_t n_files, double sleep_interval) else bytes_to_read = COPY_TO_EOF; - bytes_read = dump_remainder (name, fd, bytes_to_read); + bytes_read = dump_remainder (false, name, fd, bytes_to_read); any_input |= (bytes_read != 0); f[i].size += bytes_read; @@ -1337,7 +1343,8 @@ wd_comparator (const void *e1, const void *e2) return spec1->wd == spec2->wd; } -/* Output (new) data for FSPEC->fd. */ +/* Output (new) data for FSPEC->fd. + PREV_FSPEC records the last File_spec for which we output. */ static void check_fspec (struct File_spec *fspec, struct File_spec **prev_fspec) { @@ -1372,18 +1379,18 @@ check_fspec (struct File_spec *fspec, struct File_spec **prev_fspec) && timespec_cmp (fspec->mtime, get_stat_mtime (&stats)) == 0) return; - if (fspec != *prev_fspec) - { - if (print_headers) - write_header (name); - *prev_fspec = fspec; - } + bool want_header = print_headers && (fspec != *prev_fspec); - uintmax_t bytes_read = dump_remainder (name, fspec->fd, COPY_TO_EOF); + uintmax_t bytes_read = dump_remainder (want_header, name, fspec->fd, + COPY_TO_EOF); fspec->size += bytes_read; - if (fflush (stdout) != 0) - die (EXIT_FAILURE, errno, _("write error")); + if (bytes_read) + { + *prev_fspec = fspec; + if (fflush (stdout) != 0) + die (EXIT_FAILURE, errno, _("write error")); + } } /* Attempt to tail N_FILES files forever, or until killed. @@ -1793,7 +1800,7 @@ tail_bytes (const char *pretty_filename, int fd, uintmax_t n_bytes, *read_pos = current_pos; } - *read_pos += dump_remainder (pretty_filename, fd, n_bytes); + *read_pos += dump_remainder (false, pretty_filename, fd, n_bytes); return true; } @@ -1817,7 +1824,7 @@ tail_lines (const char *pretty_filename, int fd, uintmax_t n_lines, int t = start_lines (pretty_filename, fd, n_lines, read_pos); if (t) return t < 0; - *read_pos += dump_remainder (pretty_filename, fd, COPY_TO_EOF); + *read_pos += dump_remainder (false, pretty_filename, fd, COPY_TO_EOF); } else { diff --git a/tests/local.mk b/tests/local.mk index 30d6d7c..2717024 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -248,6 +248,7 @@ all_tests = \ tests/misc/date-next-dow.pl \ tests/misc/ptx-overrun.sh \ tests/misc/xstrtol.pl \ + tests/tail-2/overlay-headers.sh \ tests/tail-2/pid.sh \ tests/misc/od.pl \ tests/misc/od-endian.sh \ diff --git a/tests/tail-2/overlay-headers.sh b/tests/tail-2/overlay-headers.sh new file mode 100755 index 0000000..cc4f789 --- /dev/null +++ b/tests/tail-2/overlay-headers.sh @@ -0,0 +1,81 @@ +#!/bin/sh +# inotify-based tail would output redundant headers for +# overlapping inotify events while it was suspended + +# Copyright (C) 2017 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ tail sleep + +# Function to count number of lines from tail +# while ignoring transient errors due to resource limits +countlines_ () +{ + grep -Ev 'inotify (resources exhausted|cannot be used)' out | wc -l +} + +# Function to check the expected line count in 'out'. +# Called via retry_delay_(). Sleep some time - see retry_delay_() - if the +# line count is still smaller than expected. +wait4lines_ () +{ + local delay=$1 + local elc=$2 # Expected line count. + [ "$(countlines_)" -ge "$elc" ] || { sleep $delay; return 1; } +} + +# Speedup the non inotify case +fastpoll='---dis -s.1 --max-unchanged-stats=1' + +# Terminate any background tail process +cleanup_() { + kill $pid 2>/dev/null && wait $pid; + kill $sleep 2>/dev/null && wait $sleep +} + +echo start > file1 || framework_failure_ +echo start > file2 || framework_failure_ + +# Use this as a way to gracefully terminate tail +env sleep 20 & sleep=$! + +tail $fastpoll --pid=$sleep -f file1 file2 > out & pid=$! + +kill -0 $pid || fail=1 + +# Wait for 5 initial lines +retry_delay_ wait4lines_ .1 6 5 || fail=1 + +# Suspend tail so single read() caters for multiple inotify events +kill -STOP $pid || fail=1 + +# Interleave writes to files to generate overlapping inotify events +echo line >> file1 || framework_failure_ +echo line >> file2 || framework_failure_ +echo line >> file1 || framework_failure_ +echo line >> file2 || framework_failure_ + +# Resume tail processing +kill -CONT $pid || fail=1 + +# Wait for 8 more lines +retry_delay_ wait4lines_ .1 6 13 || fail=1 + +kill $sleep && wait || framework_failure_ + +test "$(countlines_)" = 13 || fail=1 + +Exit $fail -- 2.5.5 --------------5EB8B9D1496A8D01167FFCDE-- From debbugs-submit-bounces@debbugs.gnu.org Wed Feb 08 02:54:01 2017 Received: (at 23539) by debbugs.gnu.org; 8 Feb 2017 07:54:01 +0000 Received: from localhost ([127.0.0.1]:59604 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbN4i-0008Sj-W1 for submit@debbugs.gnu.org; Wed, 08 Feb 2017 02:54:01 -0500 Received: from mout.kundenserver.de ([212.227.17.24]:55242) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cbN4h-0008SV-6o for 23539@debbugs.gnu.org; Wed, 08 Feb 2017 02:54:00 -0500 Received: from [192.168.101.10] ([217.87.209.50]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.183]) with ESMTPSA (Nemesis) id 0MZOEH-1cs44e0kIv-00LBpg; Wed, 08 Feb 2017 08:53:49 +0100 Subject: Re: bug#23539: tail -f file name headings displayed too many times after suspend To: =?UTF-8?Q?P=c3=a1draig_Brady?= , Janne Snabb , 23539@debbugs.gnu.org References: <57378C33.5040605@epipe.com> <5737AF5A.3070308@epipe.com> <573EFE2C.9010606@draigBrady.com> From: Bernhard Voelker Message-ID: Date: Wed, 8 Feb 2017 08:53:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K0:PCbpJT9n283jWxVWh9Y6+1WMFqnLIHejkvjo2CKqqFWb0wv+fwt YEtpRBuZUE7PHZMoA6NdA2I3i/miz5phtRDaae4fLc37VoEt6hlUade26ezAY555MDFeeYG WwkfLqkNtJIkc8q/uVIqFKYq00Tn9II8BK6A+S0APOfW29ftdPD6Ili3SPz26I/mtyvWKP2 7FB+A4ts20wIL9LTWpJ4Q== X-UI-Out-Filterresults: notjunk:1;V01:K0:0MG5GoOboxY=:Z/IpzIvC3jDUacIKsrTo86 q+CqnqP7B/kyFH/geeHnlcbwG3BjKfIPaGxzRhQjMQ3XSvfXUClt0MoSQOPGHP5ge576AJkkc iz+UtWYb8yTSB0LqdiS1P7Ne+clVTe+ZRX5fXzpNjwa5U3RFnAlPXKzbOhp10rjE72XE/WLbw SJACCe4YOko6FQJ9UbQKoiJmLnMASI4bgVTqmrU1sWTKd0uCs8cYJhyxR9PAdVLBMObyJW2E7 vw9e3/tLa4zh+HUbnoNrYhmWU7yswoR1lii5b6RjyHfKCcf6fcs0ZNXt6jkbGiudzFAQgr9X9 SpMnGtuCVNhxrg5I3ohzW2oiA3/GJBIC6YGVX4pWjOt1sz8lblxRYpQCT/lnoF7kbYExa670J 8EKERJkMdGLDUQ3HgZaGgBd9GX+v4S5WFQq8SmwXFXGnBxSzTMuKgyzfvLhF3u7wJ9Yc+OcYZ bUZSq8DS/Ciyt26yzW/ADiD00tO99fY1300oqP7IEJrOFUkLFLjLwRAyjfqlSetqlrAa5EsxH qaZXp3qkxb/xb0omG6XAKDMDMeflyUDaBo6XUewSGOrPk0z2elxeGFRgvLP1oCBGs8Hbn9/Qe 3F23ATNP8zyinhph4g5b4MY2ZbgzWh6wmzmnciJfHhFJtuUX0lgeuEF3INKCDDUbPIOS6Jt3J 16cnYlJKbRDpMyrahjc18GZN8gxEy2OtYj/CsmAK5X515JyaN2VfHBKnLr50q8xg78pBZopd8 AgTa+oUVfl6Nuyha X-Spam-Score: 0.5 (/) X-Debbugs-Envelope-To: 23539 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.5 (/) On 02/07/2017 08:42 AM, Pádraig Brady wrote: > I'll push in your name tomorrow. +1 Thanks & have a nice day, Berny From debbugs-submit-bounces@debbugs.gnu.org Sat Oct 27 18:38:13 2018 Received: (at control) by debbugs.gnu.org; 27 Oct 2018 22:38:13 +0000 Received: from localhost ([127.0.0.1]:46027 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGXDh-0003Ig-0g for submit@debbugs.gnu.org; Sat, 27 Oct 2018 18:38:13 -0400 Received: from mail-pl1-f173.google.com ([209.85.214.173]:35710) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gGXDf-0003IT-8y for control@debbugs.gnu.org; Sat, 27 Oct 2018 18:38:11 -0400 Received: by mail-pl1-f173.google.com with SMTP id n4-v6so1496961plp.2 for ; Sat, 27 Oct 2018 15:38:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:message-id:date:user-agent:mime-version:content-language :content-transfer-encoding; bh=6o+RDGy8h/hdiE2uhiCNGbP0W19fRvQMwKEiu2w+Mqs=; b=uzjuR5s8nihkJrS0DQH2lXkTvSDzqEva/ky75+aB8KqoMBOSlBz0m062RTenQSnbY/ KVC7yP6fiW7caP+H4WtU/i5WnvYQnv+ObPZreT2sYR3k5ULDOs0t1rKJT9F7yKDAbd8W pu3iUYkxWwLqCrshIS3sCOHBSrOl+i9n3NMXaXOPKDfXvFGS5pOJylti1o6igewDq/VZ i8dp4tb1tBJ1WZGuGNhqdvy6W3dgu2DOsZtM4Nd+mDnNYCqr0sBqSIL5MYovj8+tR8Wl QAG0PwRlzK4apwPSlCJwL/OYtJvK876gMZviiS3zRlX6nZm1c2TuCG/Heuz4RDdNqE1F SfBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:from:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=6o+RDGy8h/hdiE2uhiCNGbP0W19fRvQMwKEiu2w+Mqs=; b=iE9qQpxpPP6U5r/3FtmI7wNmCUNpgXeAcdfKuDq8Qy2aA/ae0hNFAHk2fvSp+Z4Xbh HVQpUcd7Aisetp0fZUzcwRPaC6GrDjGXD4CrvSZdzHk+gjXg9a9Prf0lLMBubpgQcChj L2qZSedZSYoxfX+y6Nu4lQLFO+UChEntqAauUhfGGW2c0uxCEIFyt9mznq1c9L67l7zY NkJByvkizdO0DUGc55SiAXhrj5HLWtr1FWaZyUlUy+PxaqGfGhmxGnSzxr9cgETR6rVk E8qjdSKtC9xOLs8LXsHICZoEYK2A6bdjs7b865nKGLuTpPAUELQZtZxn3RKjmpQIgM1E hSKQ== X-Gm-Message-State: AGRZ1gJ4cQH8RFX8uXrIaip9f+YVDUP67mT2zgsJXmkHY3nb1vNp6MKg R3W5qvn0rwGolBqwl2TmFgotwSXe X-Google-Smtp-Source: AJdET5eNfvULzPhJt3XO1S5q/d0uMGmZvBGZlbgpMgycLwehb6sfu9AB+7OBT6wGXQ6hW77C7B+1zA== X-Received: by 2002:a17:902:148:: with SMTP id 66-v6mr8655458plb.140.1540679884693; Sat, 27 Oct 2018 15:38:04 -0700 (PDT) Received: from tomato.housegordon.com (moose.housegordon.com. [184.68.105.38]) by smtp.googlemail.com with ESMTPSA id 7-v6sm17295858pgk.31.2018.10.27.15.38.03 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Oct 2018 15:38:03 -0700 (PDT) To: control@debbugs.gnu.org From: Assaf Gordon Message-ID: Date: Sat, 27 Oct 2018 16:38:02 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Score: 2.0 (++) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: tags 23539 fixed close 23539 [...] Content analysis details: (2.0 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (assafgordon[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.214.173 listed in list.dnswl.org] 1.8 MISSING_SUBJECT Missing Subject: header 0.2 NO_SUBJECT Extra score for no subject X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 1.0 (+) tags 23539 fixed close 23539 From unknown Fri Aug 15 17:55:15 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sun, 25 Nov 2018 12:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator