[RFC] Force stdio output streams to line-buffered mode

From: Jeremie Le Hen <jeremie_at_le-hen.org>
Date: Sat, 19 Feb 2011 19:50:43 +0100
Hi,

I've been annoyed multiple time when running a command such like
    iostat -x 1 | grep -v ad10 | cat -n

The problem stems from two factors:
  - grep's stdio sees that its stdout is not a terminal, so stdout is
    full buffered and not line-buffered;
  - iostat produces output too slowly so the aforementioned buffer takes
    numerous seconds to be filled and flushed to the last command.

This problems is not specific to FreeBSD, it is actually a consequence
of POSIX specification.  I've checked this on Solaris and Linux.

I've attached a small patch for stdio, so if the environment variable
STDIO_IOLBF is set, the output streams will be line-oriented by default.
    iostat -x 1 | env STDIO_IOLBF=1 grep -v ad10 | cat -n

Before send it as a PR, I would like to hear your comments about this,
especially:
  - the variable name (no bikeshed please, I just ask this if there is a
    naming convention I'm not aware of);
  - the documentation: I've put a hint in stdio(3) manpage and put the
    full explanation in setvbuf(3).

Thanks.
Regards,
-- 
Jeremie Le Hen

Humans are born free and equal.  But some are more equal than others.
					    Coluche

Received on Sat Feb 19 2011 - 18:10:38 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:11 UTC