GNU bug report logs - #8961
stdbuf has no effect on some programs

Previous Next

Package: coreutils;

Reported by: Bruno Haible <bruno <at> clisp.org>

Date: Wed, 29 Jun 2011 21:00:03 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Eric Blake <eblake <at> redhat.com>
To: Pádraig Brady <P <at> draigBrady.com>
Cc: 8961 <at> debbugs.gnu.org, Paolo Bonzini <bonzini <at> gnu.org>, Bruno Haible <bruno <at> clisp.org>
Subject: bug#8961: stdbuf has no effect on some programs
Date: Tue, 05 Jul 2011 15:32:04 -0600
[Message part 1 (text/plain, inline)]
On 07/05/2011 01:13 PM, Pádraig Brady wrote:
> On 05/07/11 16:41, Eric Blake wrote:
>> On 07/04/2011 03:08 AM, Pádraig Brady wrote:
>>> But I notice that sed no longer supports `setbuf -i0`.
>>> This is because of 3a8e165a which discards the
>>> original stdin and instead fdopens() a new one
>>> to support reading in binary mode on windos.
>>> http://git.sv.gnu.org/gitweb/?p=sed.git;a=commit;h=3a8e165a
>>
>> This seems to point to the fact that using freopen() to force binary
>> mode on stdin is the wrong approach, and that we may be better served by
>> using lower-level idioms that change the binary mode of the underlying
>> file descriptor without also altering stdin with unintended side-effects.
> 
> Good point.
> 
> On the other hand all uses are protected by O_BINARY?...
> and so only apply on windos. Does stdbuf work there?
> Also od and head are the only commands that
> can consume part of stdin, but they handle this
> internally with setvbuf and read() respectively.
> So this would only be a performance issue,
> discarding the users buf size and reinitialization overhead.
> 
> If this was equivalent though, then it would be better:
> 
> ret = O_BINARY ? fcntl(fileno (stdin), F_SETFL, O_BINARY): 0;

For cygwin, I believe that this _is_ equivalent to changing just the
mode but nothing else in stdin - fcntl changes the fd mode, then calls
into an internal stdio hook function that walks all open FILE *, and if
any of those FILE * are visiting fd, then also updates that FILE * to
reflect the new operating mode.

But I don't know if it works for all other platforms with non-zero O_BINARY.

-- 
Eric Blake   eblake <at> redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

[signature.asc (application/pgp-signature, attachment)]

This bug report was last modified 13 years and 326 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.