From owner-freebsd-bugs@FreeBSD.ORG Sat Apr 14 22:20:04 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 605F7106566C for ; Sat, 14 Apr 2012 22:20:04 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 2DC658FC0C for ; Sat, 14 Apr 2012 22:20:04 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q3EMK4k5076387 for ; Sat, 14 Apr 2012 22:20:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q3EMK42b076386; Sat, 14 Apr 2012 22:20:04 GMT (envelope-from gnats) Date: Sat, 14 Apr 2012 22:20:04 GMT Message-Id: <201204142220.q3EMK42b076386@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: John Baldwin Cc: Subject: Re: bin/166660: [libc] [patch] New util/shlib to change per-fd default stdio buffering mode X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John Baldwin List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Apr 2012 22:20:04 -0000 The following reply was made to PR bin/166660; it has been noted by GNATS. From: John Baldwin To: Jeremie Le Hen Cc: bug-followup@freebsd.org Subject: Re: bin/166660: [libc] [patch] New util/shlib to change per-fd default stdio buffering mode Date: Sat, 14 Apr 2012 18:16:47 -0400 On 4/14/12 9:11 AM, Jeremie Le Hen wrote: > On Tue, Apr 10, 2012 at 09:43:16AM -0400, John Baldwin wrote: >> On Monday, April 09, 2012 5:21:03 pm Jeremie Le Hen wrote: >>> Hi John, >>> >>> On Mon, Apr 09, 2012 at 11:30:08AM -0400, John Baldwin wrote: >>>> I think it would be fine to do this in libc directly rather than via >>>> LD_PRELOAD. That would let it work for static binaries as well as >>>> dynamic libraries. My understanding is that this is how stdbuf works on >>>> Linux (glibc honors the relevant magic environment variables). To that >>>> end, I think it would be ok to move this into libc directly. >>> >>> I thought it would be too expensive to check for three (actually up to >>> six, see below) in such a critical path. Moreover, this would have >>> lowered a lot my chances to see this committed simply because very few >>> committers would have taken the responsibility for this and the time to >>> handle the debates that would have sprouted. >>> >>> Your point for static binaries is very valid but aren't you afraid of >>> the performance impact? I'll try to spare some time this week to move >>> libstdbuf code into libc and do some benchmarks. >> >> Hmm, I hadn't considered the performance impact, but to be honest, this >> is stdio. :) If it only happens once when stdio is first used then I think >> this is fine to do in libc. > > I looked in the stdio source to see how I could implement there > efficiently, but the problem is that there isn't a single entry point. > The best I can do I think is basically something like this: > > int stdbuf_done = 0; > > void > _stdbuf() > { > /* libstdbuf code */ > stdbuf_done = 1; > } > > #define STDBUF() if (!stdbuf_done) _stdbuf() > > And scatter STDBUF() all around. What do you think of it? > > (FWIW, I checked how Linux implemented this, they used an additional > shared library.) Oh, ok then. For some reason I thought it was done in the base libc rather than in a different shared library. -- John Baldwin