From owner-freebsd-current@FreeBSD.ORG Tue Feb 22 16:20:01 2011 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B06B8106566C for ; Tue, 22 Feb 2011 16:20:01 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id 7B9588FC1B for ; Tue, 22 Feb 2011 16:20:01 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 272B746B32; Tue, 22 Feb 2011 11:20:01 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.10]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id E00678A02A; Tue, 22 Feb 2011 11:19:59 -0500 (EST) From: John Baldwin To: freebsd-current@freebsd.org Date: Tue, 22 Feb 2011 09:49:22 -0500 User-Agent: KMail/1.13.5 (FreeBSD/7.4-CBSD-20110107; KDE/4.4.5; amd64; ; ) References: <20110219185043.GA6573@felucia.tataz.chchile.org> In-Reply-To: <20110219185043.GA6573@felucia.tataz.chchile.org> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201102220949.22736.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Tue, 22 Feb 2011 11:20:00 -0500 (EST) X-Virus-Scanned: clamav-milter 0.96.3 at bigwig.baldwin.cx X-Virus-Status: Clean X-Spam-Status: No, score=0.5 required=4.2 tests=BAYES_00,MAY_BE_FORGED, RDNS_DYNAMIC autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on bigwig.baldwin.cx Cc: Jeremie Le Hen Subject: Re: [RFC] Force stdio output streams to line-buffered mode X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Feb 2011 16:20:01 -0000 On Saturday, February 19, 2011 1:50:43 pm Jeremie Le Hen wrote: > 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). Many people would find this useful I think. -- John Baldwin