From unknown Sat Jun 21 10:27:25 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#17145 <17145@debbugs.gnu.org> To: bug#17145 <17145@debbugs.gnu.org> Subject: Status: head fails with implicit stdin on darwin Reply-To: bug#17145 <17145@debbugs.gnu.org> Date: Sat, 21 Jun 2025 17:27:25 +0000 retitle 17145 head fails with implicit stdin on darwin reassign 17145 coreutils submitter 17145 Denis Excoffier severity 17145 normal tag 17145 patch thanks From debbugs-submit-bounces@debbugs.gnu.org Sun Mar 30 17:43:24 2014 Received: (at submit) by debbugs.gnu.org; 30 Mar 2014 21:43:24 +0000 Received: from localhost ([127.0.0.1]:57350 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUNVj-000243-Dl for submit@debbugs.gnu.org; Sun, 30 Mar 2014 17:43:24 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37928) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUMXJ-0000VC-5q for submit@debbugs.gnu.org; Sun, 30 Mar 2014 16:40:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUMX9-0007Ie-V3 for submit@debbugs.gnu.org; Sun, 30 Mar 2014 16:40:56 -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.5 required=5.0 tests=BAYES_05 autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:37958) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUMX9-0007Ia-RL for submit@debbugs.gnu.org; Sun, 30 Mar 2014 16:40:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUMX0-0005ZV-Dl for bug-coreutils@gnu.org; Sun, 30 Mar 2014 16:40:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WUMWr-0007Fe-At for bug-coreutils@gnu.org; Sun, 30 Mar 2014 16:40:38 -0400 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]:55718) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WUMWq-0007FK-Pk for bug-coreutils@gnu.org; Sun, 30 Mar 2014 16:40:29 -0400 Received: from [192.168.0.11] (unknown [78.224.52.79]) by smtp4-g21.free.fr (Postfix) with ESMTP id A9C584C803D; Sun, 30 Mar 2014 22:40:19 +0200 (CEST) From: Denis Excoffier Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Date: Sun, 30 Mar 2014 22:40:18 +0200 Subject: head fails with implicit stdin on darwin To: bug-coreutils@gnu.org Message-Id: Mime-Version: 1.0 (Mac OS X Mail 7.2 \(1874\)) X-Mailer: Apple Mail (2.1874) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Sun, 30 Mar 2014 17:43:21 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -5.0 (-----) Hello, head -n -1 -- - or equivalently head -n -1 returns immediately (ie does not wait for further stdin) and prints = nothing. I use coreutils 8.22 compiled (with gcc-4.8.2) on top of darwin 13.1.0 = (Mavericks). However the following seem to work perfectly: head -n 1 head -c -1 cat | head -n -1 head -n -1 ---presume-input-pipe on cygwin: head -n -1 What is weird on my system is lseek() at the beginning of = elide_tail_lines_file(): lseek(fd, 0, SEEK_CUR) returns a (random?) number, something like 6735, = 539 etc. lseek(fd, 0, SEEK_END) returns 0 Hope this helps, Regards, Denis Excoffier.= From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 03:41:26 2014 Received: (at 17145) by debbugs.gnu.org; 31 Mar 2014 07:41:27 +0000 Received: from localhost ([127.0.0.1]:57558 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUWqU-0001Vf-1c for submit@debbugs.gnu.org; Mon, 31 Mar 2014 03:41:26 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:57567) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUWqP-0001VV-TK for 17145@debbugs.gnu.org; Mon, 31 Mar 2014 03:41:23 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 88672A6000A; Mon, 31 Mar 2014 00:41:20 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zrDxGvCAIPXr; Mon, 31 Mar 2014 00:41:20 -0700 (PDT) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 361C9A60006; Mon, 31 Mar 2014 00:41:20 -0700 (PDT) Message-ID: <53391C1F.9020801@cs.ucla.edu> Date: Mon, 31 Mar 2014 00:41:19 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: Denis Excoffier , 17145@debbugs.gnu.org Subject: Re: bug#17145: head fails with implicit stdin on darwin References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 17145 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -2.9 (--) Denis Excoffier wrote: > I use coreutils 8.22 compiled (with gcc-4.8.2) on top of darwin 13.1.0 (Mavericks). Presumably it's a darwin-specific problem, since it doesn't occur on GNU/Linux or on Cygwin. I'm afraid that meas you'll have to investigate it more. What happens when you use the darwin equivalent of 'strace', whatever that is these days? From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 08:32:57 2014 Received: (at 17145) by debbugs.gnu.org; 31 Mar 2014 12:32:58 +0000 Received: from localhost ([127.0.0.1]:57653 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUbOa-0001g8-Ep for submit@debbugs.gnu.org; Mon, 31 Mar 2014 08:32:57 -0400 Received: from mail5.vodafone.ie ([213.233.128.176]:53356) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUbOW-0001fy-9l for 17145@debbugs.gnu.org; Mon, 31 Mar 2014 08:32:53 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AkUCAM1fOVNtTmjw/2dsb2JhbAANTINBUYhtujCBMYMZAQEBBHkQCw0BAwMBAgEJFg8JAwIBAgE9CAYNAQUCAQEWh2QDBa0iowwXjm4RB4Q4BJBVgTSHeIVChXmIeA Received: from unknown (HELO [192.168.1.79]) ([109.78.104.240]) by mail3.vodafone.ie with ESMTP; 31 Mar 2014 13:32:50 +0100 Message-ID: <53396072.8010106@draigBrady.com> Date: Mon, 31 Mar 2014 13:32:50 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Denis Excoffier Subject: Re: bug#17145: head fails with implicit stdin on darwin References: In-Reply-To: X-Enigmail-Version: 1.6 Content-Type: multipart/mixed; boundary="------------060908050808020600020103" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 17145 Cc: 17145@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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. --------------060908050808020600020103 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 03/30/2014 09:40 PM, Denis Excoffier wrote: > Hello, > > head -n -1 -- - > or equivalently > head -n -1 > returns immediately (ie does not wait for further stdin) and prints nothing. > > I use coreutils 8.22 compiled (with gcc-4.8.2) on top of darwin 13.1.0 (Mavericks). > > However the following seem to work perfectly: > head -n 1 > head -c -1 > cat | head -n -1 > head -n -1 ---presume-input-pipe > on cygwin: head -n -1 > > What is weird on my system is lseek() at the beginning of elide_tail_lines_file(): > lseek(fd, 0, SEEK_CUR) returns a (random?) number, something like 6735, 539 etc. > lseek(fd, 0, SEEK_END) returns 0 So: head -n -1 # returns immediately while: cat | head -n -1 # waits as expected It seems we might be using non portable code here. POSIX says: "The behavior of lseek() on devices which are incapable of seeking is implementation-defined. The value of the file offset associated with such a device is undefined." and also: "The lseek() function shall fail [with ESPIPE if] the fildes argument is associated with a pipe, FIFO, or socket" So tty devices would come outside of this POSIX scope. Furthermore the FreeBSD lseek man pages states: "Some devices are incapable of seeking and POSIX does not specify which devices must support it. Linux specific restrictions: using lseek on a tty device returns ESPIPE. Other systems return the number of written characters, using SEEK_SET to set the counter. Some devices, e.g. /dev/null do not cause the error ESPIPE, but return a pointer which value is undefined." Now head(1) isn't the only place we use this logic. In dd we have: offset = lseek (STDIN_FILENO, 0, SEEK_CUR); input_seekable = (0 <= offset); I wonder should be be using something like: bool seekable (int fd) { return ! isatty (fd) && lseek (fd, 0, SEEK_CUR) >= 0; } Though this only handles the tty case, and there could be other devices for which this could be an issue. So the general question is, is there a way we can robustly determine if we have a seekable device or not? Perhaps by using SEEK_SET in combination with SEEK_CUR, but notice the BSD lseek man page above says that tty devices support SEEK_SET also :/ Anyway... Note the original head(1) code to detect seekable input was introduced with: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=61ba51a6 and that was changed recently due to a coverity identified logic issue, to: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=5fdb5082 However that now logically consistent code will return immediately in your case. I also notice the related `head -c -1` check is more conservative in that it only uses the more efficient lseek() code for regular files, which would mean we don't operate as efficiently as we could on a disk device for example. But that's much better than undefined operation of course. If we were to do the same for lines then we would also introduce a change in behavior with devices like /dev/zero. Currently on Linux, this will return immediately: head -n -1 /dev/zero I.E. we currently treat such devices as empty, and return immediately with success status, whereas treating as a stream of NULs, would result in memory exhaustion while buffering waiting for a complete line. That is probably the more consistent operation at least. So the attached uses this more conservative test for the --lines=-N case. thanks, Pádraig. --------------060908050808020600020103 Content-Type: text/x-patch; name="head-tty-bsd.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="head-tty-bsd.patch" >From 386bdbd2e9b9af1813bc4ac205755c0ce17f5cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Mon, 31 Mar 2014 13:16:56 +0100 Subject: [PATCH] head: with --lines=-N process devices more consistently * src/head.c (elide_tail_lines_file): Restrict lseek() logic to regular files, as it's not possible to determine if a device is really seekable or not. On BSD for example, lseek() returns >= 0 for tty devices, while on Linux 0 will be returned for /dev/zero which would therefore be ignored without this change. Fixes http://bugs.gnu.org/17145 Redported by Denis Excoffier --- NEWS | 4 ++++ src/head.c | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 582f060..b37a21a 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,10 @@ GNU coreutils NEWS -*- outline -*- now copies all input to stdout. Previously nothing was output in this case. [bug introduced with the --lines=-N feature in coreutils-5.0.1] + head --lines=-N now handles devices more consistently, not ignoring data + from virtual devices like /dev/zero, or on BSD systems data from tty devices. + [bug introduced with the --lines=-N feature in coreutils-5.0.1] + ln -sf now replaces symbolic links whose targets can't exist. Previously it would display an error, requiring --no-dereference to avoid the issue. [bug introduced in coreutils-5.3.0] diff --git a/src/head.c b/src/head.c index b833af6..d3d8eca 100644 --- a/src/head.c +++ b/src/head.c @@ -414,9 +414,9 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0) static bool elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide) { - struct stat stats; + struct stat st; - if (presume_input_pipe || fstat (fd, &stats) || ! S_ISREG (stats.st_mode)) + if (presume_input_pipe || fstat (fd, &st) || ! S_ISREG (st.st_mode)) { return elide_tail_bytes_pipe (filename, fd, n_elide); } @@ -735,7 +735,9 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, static bool elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide) { - if (!presume_input_pipe) + struct stat st; + + if (! presume_input_pipe && fstat (fd, &st) == 0 && S_ISREG (st.st_mode)) { /* Find the offset, OFF, of the Nth newline from the end, but not counting the last byte of the file. -- 1.7.7.6 --------------060908050808020600020103-- From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 13:58:04 2014 Received: (at 17145) by debbugs.gnu.org; 31 Mar 2014 17:58:04 +0000 Received: from localhost ([127.0.0.1]:58149 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUgTD-0001Yz-Py for submit@debbugs.gnu.org; Mon, 31 Mar 2014 13:58:04 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:56713) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUgTA-0001YW-St for 17145@debbugs.gnu.org; Mon, 31 Mar 2014 13:58:01 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 2416139E8013; Mon, 31 Mar 2014 10:58:00 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id jO7AdxtcxA3J; Mon, 31 Mar 2014 10:57:59 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id C90F739E8012; Mon, 31 Mar 2014 10:57:59 -0700 (PDT) Message-ID: <5339ACA7.7010209@cs.ucla.edu> Date: Mon, 31 Mar 2014 10:57:59 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: =?ISO-8859-1?Q?P=E1draig_Brady?= , Denis Excoffier Subject: Re: bug#17145: head fails with implicit stdin on darwin References: <53396072.8010106@draigBrady.com> In-Reply-To: <53396072.8010106@draigBrady.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 17145 Cc: 17145@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -2.9 (--) On 03/31/2014 05:32 AM, Pádraig Brady wrote: > I also notice the related `head -c -1` check is more conservative I just now noticed that head -c -1 is obviously buggy in some cases, andfixed that in commit d08381bc261d95502a205f7214686f80383c9692. From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 14:19:58 2014 Received: (at 17145) by debbugs.gnu.org; 31 Mar 2014 18:19:58 +0000 Received: from localhost ([127.0.0.1]:58169 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUgoQ-00027L-7x for submit@debbugs.gnu.org; Mon, 31 Mar 2014 14:19:58 -0400 Received: from mail6.vodafone.ie ([213.233.128.184]:62588) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUgoO-00027C-HJ for 17145@debbugs.gnu.org; Mon, 31 Mar 2014 14:19:57 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApQBANywOVNtTmjw/2dsb2JhbAANTA6DM8NqCYE3gxkBAQEEMgFGEAsNCwkWDwkDAgECAUUGDQEHAQGHegitU6JmF45/B4Q4AQOfQ44wQQ Received: from unknown (HELO [192.168.1.79]) ([109.78.104.240]) by mail3.vodafone.ie with ESMTP; 31 Mar 2014 19:19:54 +0100 Message-ID: <5339B1CA.9080308@draigBrady.com> Date: Mon, 31 Mar 2014 19:19:54 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#17145: head fails with implicit stdin on darwin References: <53396072.8010106@draigBrady.com> <5339ACA7.7010209@cs.ucla.edu> In-Reply-To: <5339ACA7.7010209@cs.ucla.edu> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 17145 Cc: 17145@debbugs.gnu.org, Denis Excoffier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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 03/31/2014 06:57 PM, Paul Eggert wrote: > On 03/31/2014 05:32 AM, Pádraig Brady wrote: >> I also notice the related `head -c -1` check is more conservative > I just now noticed that head -c -1 is obviously buggy in some cases, andfixed that in commit d08381bc261d95502a205f7214686f80383c9692. http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=d08381bc +1 thanks, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 15:44:00 2014 Received: (at 17145) by debbugs.gnu.org; 31 Mar 2014 19:44:00 +0000 Received: from localhost ([127.0.0.1]:58229 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUi7e-0004HR-9Z for submit@debbugs.gnu.org; Mon, 31 Mar 2014 15:43:59 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:34663) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUi7b-0004HH-6U for 17145@debbugs.gnu.org; Mon, 31 Mar 2014 15:43:52 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id A74CC39E8014; Mon, 31 Mar 2014 12:43:49 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zr-jjxH1OwYn; Mon, 31 Mar 2014 12:43:48 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id B24AC39E8011; Mon, 31 Mar 2014 12:43:48 -0700 (PDT) Message-ID: <5339C574.3050501@cs.ucla.edu> Date: Mon, 31 Mar 2014 12:43:48 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: =?ISO-8859-1?Q?P=E1draig_Brady?= , Denis Excoffier Subject: Re: bug#17145: head fails with implicit stdin on darwin References: <53396072.8010106@draigBrady.com> In-Reply-To: <53396072.8010106@draigBrady.com> Content-Type: multipart/mixed; boundary="------------020706050006080203060607" X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 17145 Cc: 17145@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -2.9 (--) This is a multi-part message in MIME format. --------------020706050006080203060607 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit On 03/31/2014 05:32 AM, Pádraig Brady wrote: > It seems we might be using non portable code here. Yes. > In dd we have: I haven't looked at dd carefully, but I assume it's OK. It's a low-level program intended for people who want to exercise system calls pretty much directly. If someone wants to lseek on a device, dd should probably do just that. > is there a way we can robustly determine if we have a seekable device > or not? Not as far as I know. In fact, I expect much of the coreutils code uses the word "seekable" to mean "lseek returns a nonnegative value", which isn't the same thing that POSIX means. Quite possibly we should clean up coreutils' terminology here. > head -n -1 /dev/zero I.E. we currently treat such devices as empty, > and return immediately with success status, whereas treating as a > stream of NULs, would result in memory exhaustion while buffering > waiting for a complete line. That is probably the more consistent > operation at least. Yes, that sounds right. > So the attached uses this more conservative test for the --lines=-N case. Inoticed other instances of the problem, and in general the whole lseek business needs a cleanup; the code's too complicated. Attached is a proposed cleanup+fix patch. --------------020706050006080203060607 Content-Type: text/x-patch; name="0001-head-port-to-Darwin-and-use-simpler-seeks.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-head-port-to-Darwin-and-use-simpler-seeks.patch" >From e36f80cf9d6eb97d0827129d972a4a96cf7be680 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 31 Mar 2014 12:16:44 -0700 Subject: [PATCH] head: port to Darwin and use simpler seeks This removes an unportable assumption that if lseek succeeds, the file is capable of seeking. See Bug#17145. * src/head.c (elseek): New function, for consistency in reporting lseek failures. (elide_tail_bytes_file, elide_tail_lines_seekable) (elide_tail_lines_file, head_lines, head): Use it. (elide_tail_bytes_file, elide_tail_lines_file): New args CURRENT_POS and SIZE. All uses changed. Don't bother invoking lseek, since we know the file's pos and size now. (elide_tail_bytes_file): Change a local from uintmax_t to off_t, since it fits. (head): Use lseek only on regular files, since its behavior on unseekable devices is implementation-defined. * NEWS: Document this. --- NEWS | 3 ++ src/head.c | 163 +++++++++++++++++++++++++++---------------------------------- 2 files changed, 74 insertions(+), 92 deletions(-) diff --git a/NEWS b/NEWS index 4402a02..be9b7ee 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,9 @@ GNU coreutils NEWS -*- outline -*- date could crash or go into an infinite loop when parsing a malformed TZ="". [bug introduced with the --date='TZ="" ..' parsing feature in coreutils-5.3.0] + head no longer assumes that lseek fails on unseekable devices. + [bug introduced with the --bytes=-N feature in coreutils-5.0.1] + head --bytes=-N - no longer fails with a bogus diagnostic when stdin's seek pointer is not at the beginning. [bug introduced with the --bytes=-N feature in coreutils-5.0.1] diff --git a/src/head.c b/src/head.c index e27ce46..56dc36a 100644 --- a/src/head.c +++ b/src/head.c @@ -34,6 +34,7 @@ #include "error.h" #include "full-read.h" #include "quote.h" +#include "quotearg.h" #include "safe-read.h" #include "xfreopen.h" #include "xstrtol.h" @@ -404,53 +405,53 @@ elide_tail_bytes_pipe (const char *filename, int fd, uintmax_t n_elide_0) } } -/* Print all but the last N_ELIDE lines from the input available - via file descriptor FD. Return true upon success. +/* Call lseek (FD, OFFSET, WHENCE), where file descriptor FD + corresponds to the file FILENAME. WHENCE must be SEEK_SET or + SEEK_CUR. Return the resulting offset. Give a diagnostic and + return -1 if lseek fails. */ + +static off_t +elseek (int fd, off_t offset, int whence, char const *filename) +{ + off_t new_offset = lseek (fd, offset, whence); + char buf[INT_BUFSIZE_BOUND (offset)]; + + if (new_offset < 0) + error (0, errno, + _(whence == SEEK_SET + ? N_("%s: cannot seek to offset %s") + : N_("%s: cannot seek to relative offset %s")), + quotearg_colon (filename), + offtostr (offset, buf)); + + return new_offset; +} + +/* For the file FILENAME with descriptor FD, output all but the last N_ELIDE + bytes. If SIZE is nonnegative, this is a regular file positioned + at START_POS with SIZE bytes. Return true on success. Give a diagnostic and return false upon error. */ /* NOTE: if the input file shrinks by more than N_ELIDE bytes between the length determination and the actual reading, then head fails. */ static bool -elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide) +elide_tail_bytes_file (const char *filename, int fd, uintmax_t n_elide, + off_t current_pos, off_t size) { - struct stat stats; - - if (presume_input_pipe || fstat (fd, &stats) || ! S_ISREG (stats.st_mode)) - { - return elide_tail_bytes_pipe (filename, fd, n_elide); - } + if (size < 0) + return elide_tail_bytes_pipe (filename, fd, n_elide); else { - off_t current_pos, end_pos; - uintmax_t bytes_remaining; - off_t diff; - enum Copy_fd_status err; - - if ((current_pos = lseek (fd, 0, SEEK_CUR)) == -1 - || (end_pos = lseek (fd, 0, SEEK_END)) == -1) - { - error (0, errno, _("cannot lseek %s"), quote (filename)); - return false; - } - /* Be careful here. The current position may actually be beyond the end of the file. */ - bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 : diff; + off_t diff = size - current_pos; + off_t bytes_remaining = diff < 0 ? 0 : diff; if (bytes_remaining <= n_elide) return true; - /* Seek back to 'current' position, then copy the required - number of bytes from fd. */ - if (lseek (fd, current_pos, SEEK_SET) < 0) - { - error (0, errno, _("%s: cannot lseek back to original position"), - quote (filename)); - return false; - } - - err = copy_fd (fd, bytes_remaining - n_elide); + enum Copy_fd_status err = copy_fd (fd, bytes_remaining - n_elide); if (err == COPY_FD_OK) return true; @@ -594,10 +595,10 @@ free_lbuffers: } /* Output all but the last N_LINES lines of the input stream defined by - FD, START_POS, and END_POS. + FD, START_POS, and SIZE. START_POS is the starting position of the read pointer for the file associated with FD (may be nonzero). - END_POS is the file offset of EOF (one larger than offset of last byte). + SIZE is the file size in bytes. Return true upon success. Give a diagnostic and return false upon error. @@ -607,11 +608,11 @@ free_lbuffers: static bool elide_tail_lines_seekable (const char *pretty_filename, int fd, uintmax_t n_lines, - off_t start_pos, off_t end_pos) + off_t start_pos, off_t size) { char buffer[BUFSIZ]; size_t bytes_read; - off_t pos = end_pos; + off_t pos = size; /* Set 'bytes_read' to the size of the last, probably partial, buffer; 0 < 'bytes_read' <= 'BUFSIZ'. */ @@ -621,13 +622,8 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, /* Make 'pos' a multiple of 'BUFSIZ' (0 if the file is short), so that all reads will be on block boundaries, which might increase efficiency. */ pos -= bytes_read; - if (lseek (fd, pos, SEEK_SET) < 0) - { - char offset_buf[INT_BUFSIZE_BOUND (pos)]; - error (0, errno, _("%s: cannot seek to offset %s"), - pretty_filename, offtostr (pos, offset_buf)); - return false; - } + if (elseek (fd, pos, SEEK_SET, pretty_filename) < 0) + return false; bytes_read = safe_read (fd, buffer, bytes_read); if (bytes_read == SAFE_READ_ERROR) { @@ -667,14 +663,8 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, if (start_pos < pos) { enum Copy_fd_status err; - if (lseek (fd, start_pos, SEEK_SET) < 0) - { - /* Failed to reposition file pointer. */ - error (0, errno, - "%s: unable to restore file pointer to initial offset", - quote (pretty_filename)); - return false; - } + if (elseek (fd, start_pos, SEEK_SET, pretty_filename) < 0) + return false; err = copy_fd (fd, pos - start_pos); if (err != COPY_FD_OK) @@ -689,13 +679,7 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, xwrite_stdout (buffer, n + 1); /* Set file pointer to the byte after what we've output. */ - if (lseek (fd, pos + n + 1, SEEK_SET) < 0) - { - error (0, errno, _("%s: failed to reset file pointer"), - quote (pretty_filename)); - return false; - } - return true; + return 0 <= elseek (fd, pos + n + 1, SEEK_SET, pretty_filename); } } @@ -706,13 +690,8 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, return true; } pos -= BUFSIZ; - if (lseek (fd, pos, SEEK_SET) < 0) - { - char offset_buf[INT_BUFSIZE_BOUND (pos)]; - error (0, errno, _("%s: cannot seek to offset %s"), - pretty_filename, offtostr (pos, offset_buf)); - return false; - } + if (elseek (fd, pos, SEEK_SET, pretty_filename) < 0) + return false; bytes_read = safe_read (fd, buffer, BUFSIZ); if (bytes_read == SAFE_READ_ERROR) @@ -728,36 +707,28 @@ elide_tail_lines_seekable (const char *pretty_filename, int fd, } } -/* Print all but the last N_ELIDE lines from the input available - via file descriptor FD. Return true upon success. +/* For the file FILENAME with descriptor FD, output all but the last N_ELIDE + lines. If SIZE is nonnegative, this is a regular file positioned + at START_POS with SIZE bytes. Return true on success. Give a diagnostic and return nonzero upon error. */ static bool -elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide) +elide_tail_lines_file (const char *filename, int fd, uintmax_t n_elide, + off_t current_pos, off_t size) { - if (!presume_input_pipe) + if (size < 0) + return elide_tail_lines_pipe (filename, fd, n_elide); + else { /* Find the offset, OFF, of the Nth newline from the end, but not counting the last byte of the file. If found, write from current position to OFF, inclusive. Otherwise, just return true. */ - off_t start_pos = lseek (fd, 0, SEEK_CUR); - off_t end_pos = lseek (fd, 0, SEEK_END); - if (0 <= start_pos && 0 <= end_pos) - { - /* If no data to read we're done. */ - if (start_pos >= end_pos) - return true; - - return elide_tail_lines_seekable (filename, fd, n_elide, - start_pos, end_pos); - } - - /* lseek failed, Fall through... */ + return (size <= current_pos + || elide_tail_lines_seekable (filename, fd, n_elide, + current_pos, size)); } - - return elide_tail_lines_pipe (filename, fd, n_elide); } static bool @@ -811,11 +782,9 @@ head_lines (const char *filename, int fd, uintmax_t lines_to_write) gotten to had we been reading one byte at a time. */ if (lseek (fd, -n_bytes_past_EOL, SEEK_CUR) < 0) { - int e = errno; struct stat st; if (fstat (fd, &st) != 0 || S_ISREG (st.st_mode)) - error (0, e, _("cannot reposition file pointer for %s"), - quote (filename)); + elseek (fd, -n_bytes_past_EOL, SEEK_CUR, filename); } break; } @@ -833,14 +802,24 @@ head (const char *filename, int fd, uintmax_t n_units, bool count_lines, if (elide_from_end) { - if (count_lines) + off_t current_pos = -1, size = -1; + if (! presume_input_pipe) { - return elide_tail_lines_file (filename, fd, n_units); + struct stat st; + if (fstat (fd, &st) != 0) + error (0, errno, _("cannot fstat %s"), quotearg_colon (filename)); + if (S_ISREG (st.st_mode)) + { + size = st.st_size; + current_pos = elseek (fd, 0, SEEK_CUR, filename); + if (current_pos < 0) + return false; + } } + if (count_lines) + return elide_tail_lines_file (filename, fd, n_units, current_pos, size); else - { - return elide_tail_bytes_file (filename, fd, n_units); - } + return elide_tail_bytes_file (filename, fd, n_units, current_pos, size); } if (count_lines) return head_lines (filename, fd, n_units); -- 1.9.0 --------------020706050006080203060607-- From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 15:44:36 2014 Received: (at control) by debbugs.gnu.org; 31 Mar 2014 19:44:36 +0000 Received: from localhost ([127.0.0.1]:58233 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUi8K-0004Iy-3S for submit@debbugs.gnu.org; Mon, 31 Mar 2014 15:44:36 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:34721) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUi8H-0004Ip-8g for control@debbugs.gnu.org; Mon, 31 Mar 2014 15:44:34 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id A4584A60006 for ; Mon, 31 Mar 2014 12:44:32 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fTKs3edutp0u for ; Mon, 31 Mar 2014 12:44:32 -0700 (PDT) Received: from penguin.cs.ucla.edu (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 6DD3539E8016 for ; Mon, 31 Mar 2014 12:44:32 -0700 (PDT) Message-ID: <5339C5A0.3080102@cs.ucla.edu> Date: Mon, 31 Mar 2014 12:44:32 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: control@debbugs.gnu.org Subject: 17145 has a patch Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: control X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -2.9 (--) tags 17145 + patch From debbugs-submit-bounces@debbugs.gnu.org Mon Mar 31 19:14:10 2014 Received: (at 17145) by debbugs.gnu.org; 31 Mar 2014 23:14:10 +0000 Received: from localhost ([127.0.0.1]:58456 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUlP8-0003Pf-0M for submit@debbugs.gnu.org; Mon, 31 Mar 2014 19:14:10 -0400 Received: from mail3.vodafone.ie ([213.233.128.45]:18967) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUlP5-0003PV-SH for 17145@debbugs.gnu.org; Mon, 31 Mar 2014 19:14:08 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBAD/2OVNtTmjw/2dsb2JhbAANTA6DM8QLgTWDGQEBAQQyAUYQCw0LCRYPCQMCAQIBRQYNAQcBARaHZK4Io1kXjh0RAVAHhDgBA5oBhUKOMEGBcQ Received: from unknown (HELO [192.168.1.79]) ([109.78.104.240]) by mail3.vodafone.ie with ESMTP; 01 Apr 2014 00:14:05 +0100 Message-ID: <5339F6BC.7030909@draigBrady.com> Date: Tue, 01 Apr 2014 00:14:04 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 MIME-Version: 1.0 To: Paul Eggert Subject: Re: bug#17145: head fails with implicit stdin on darwin References: <53396072.8010106@draigBrady.com> <5339C574.3050501@cs.ucla.edu> In-Reply-To: <5339C574.3050501@cs.ucla.edu> X-Enigmail-Version: 1.6 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 17145 Cc: 17145@debbugs.gnu.org, Denis Excoffier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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 (/) Very nice cleanup. Comments below... On 03/31/2014 08:43 PM, Paul Eggert wrote: > diff --git a/NEWS b/NEWS > + head no longer assumes that lseek fails on unseekable devices. > + [bug introduced with the --bytes=-N feature in coreutils-5.0.1] I slightly prefer my NEWS entry since it details the consequences rather than the mechanism, and so could be more meaningful to end users. > @@ -833,14 +802,24 @@ head (const char *filename, int fd, uintmax_t n_units, bool count_lines, > > if (elide_from_end) > { > - if (count_lines) > + off_t current_pos = -1, size = -1; > + if (! presume_input_pipe) > { > - return elide_tail_lines_file (filename, fd, n_units); > + struct stat st; > + if (fstat (fd, &st) != 0) > + error (0, errno, _("cannot fstat %s"), quotearg_colon (filename)); > + if (S_ISREG (st.st_mode)) s/if/else if/ Could you also update Denis' current email address in THANKS.in Otherwise it all looks good. thanks! Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Tue Apr 01 03:23:41 2014 Received: (at 17145) by debbugs.gnu.org; 1 Apr 2014 07:23:41 +0000 Received: from localhost ([127.0.0.1]:58635 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUt2p-0000wk-Nv for submit@debbugs.gnu.org; Tue, 01 Apr 2014 03:23:40 -0400 Received: from moutng.kundenserver.de ([212.227.17.10]:65323) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WUt2m-0000wX-6g for 17145@debbugs.gnu.org; Tue, 01 Apr 2014 03:23:37 -0400 Received: from susi.site (gw.camline.com [62.153.148.194]) by mrelayeu.kundenserver.de (node=mreue105) with ESMTP (Nemesis) id 0Md4Fu-1WlrvW1Fnm-00IEdF; Tue, 01 Apr 2014 09:23:20 +0200 Message-ID: <533A6967.2000808@bernhard-voelker.de> Date: Tue, 01 Apr 2014 09:23:19 +0200 From: Bernhard Voelker User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Paul Eggert , =?ISO-8859-1?Q?P=E1draig_Brady?= , Denis Excoffier Subject: Re: bug#17145: head fails with implicit stdin on darwin References: <53396072.8010106@draigBrady.com> <5339C574.3050501@cs.ucla.edu> In-Reply-To: <5339C574.3050501@cs.ucla.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:reYZvvOmS2TNc2yVNH+/K2BWcam3cTFG2SFNzwzlK7g WrHor603ruBI1GGQigTIxdjWH9cJJgJ6JEsXPSjBDNaSo7tNcD pqCjcZg5tUHcdjbncfDrZ75MqT9Re1vvAEQdp+dVWM5U0s+xQx kvq4mp4UGsa6LtNpMURo0kIQ1D/tZ+3Y1x/oAesCwTcyogx+0F E+3aTj5Vh7K5+EOljqqnuYiUiZRFYhnSSpDhFgLvWOxhg0Z9Tp q+l3kyK0n77qsW5uBBYF4BbxqJOpw5kEhHFd+ZljWTf0VqxH2i 4Aq5YMY263awNTIiKQmkJJMjIHkcm3hiBy+OHNQB6dVPSAHpZm BplHqkuAnUPfd3fG/d5kLlEWPeayfbolajrX23HPe X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 17145 Cc: 17145@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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 03/31/2014 09:43 PM, Paul Eggert wrote: > Subject: [PATCH] head: port to Darwin and use simpler seeks > > This removes an unportable assumption that if lseek succeeds, the > file is capable of seeking. See Bug#17145. Minor note: please s,Bug#17145,http://bugs.gnu.org/17145, Thanks & have a nice day, Berny From debbugs-submit-bounces@debbugs.gnu.org Wed Apr 02 10:47:28 2014 Received: (at 17145-done) by debbugs.gnu.org; 2 Apr 2014 14:47:28 +0000 Received: from localhost ([127.0.0.1]:33048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVMRr-0002Rt-Tq for submit@debbugs.gnu.org; Wed, 02 Apr 2014 10:47:28 -0400 Received: from smtp.cs.ucla.edu ([131.179.128.62]:33907) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WVMRp-0002Rk-Bc for 17145-done@debbugs.gnu.org; Wed, 02 Apr 2014 10:47:26 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 00F4F39E8018; Wed, 2 Apr 2014 07:47:24 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id yo8zfl5iEW8U; Wed, 2 Apr 2014 07:47:15 -0700 (PDT) Received: from [192.168.1.9] (pool-108-0-233-62.lsanca.fios.verizon.net [108.0.233.62]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 636EB39E8015; Wed, 2 Apr 2014 07:47:15 -0700 (PDT) Message-ID: <533C22EF.1080201@cs.ucla.edu> Date: Wed, 02 Apr 2014 07:47:11 -0700 From: Paul Eggert Organization: UCLA Computer Science Department User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 MIME-Version: 1.0 To: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= Subject: Re: bug#17145: head fails with implicit stdin on darwin References: <53396072.8010106@draigBrady.com> <5339C574.3050501@cs.ucla.edu> <5339F6BC.7030909@draigBrady.com> In-Reply-To: <5339F6BC.7030909@draigBrady.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -2.9 (--) X-Debbugs-Envelope-To: 17145-done Cc: 17145-done@debbugs.gnu.org, Denis Excoffier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 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: -2.9 (--) Pádraig Brady wrote: > s/if/else if/ Thanks. Or better yet, return false if fstat fails. I did that, plus the other changes you and Bernhard suggested, and installed the patch. From unknown Sat Jun 21 10:27:25 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Thu, 01 May 2014 11:24:04 +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