From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on starla X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id C5B6B1F44D for ; Sat, 20 Apr 2024 21:44:17 +0000 (UTC) Authentication-Results: dcvr.yhbt.net; dkim=pass (2048-bit key; secure) header.d=cs.wisc.edu header.i=@cs.wisc.edu header.a=rsa-sha256 header.s=csl-2018021300 header.b=b9bjdife; dkim-atps=neutral Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2AD693858C53 for ; Sat, 20 Apr 2024 21:44:16 +0000 (GMT) Received: from smtpout2.cs.wisc.edu (smtpout2.cs.wisc.edu [128.105.6.54]) by sourceware.org (Postfix) with ESMTPS id E29483858D34 for ; Sat, 20 Apr 2024 21:43:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E29483858D34 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=cs.wisc.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.wisc.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E29483858D34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=128.105.6.54 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713649438; cv=none; b=FsTAsalPBCqfMBxrZXckPUFWeW8981SLGEJl054nI/XMKPyw7Sun8K4ej5lyEdTNXQklesPswHyTWgb+AsevnWugilbjJQ5q47uNpI2nLvKq3WM4eOgdLEr3kz/RIPHzK4S151kWI/Tq8tlE1kcUXuAbLDPPnx24mWedh8wH+ms= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713649438; c=relaxed/simple; bh=Uq6H4iFHasWFRLYzL3Z+5kbugaVKrY8pE814WtBTVF8=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=e+wi/MxWzatBTGMKQ26OpkrJnbSxc3bPB8/T4NhNGX8Rju21MC2VVQGNXoNepgPAvM/8TiWhiOzyqaLRIjMLnVCDXORt6GqRy4uTIJ4Dpvg7HINa176FitOYn1WrzJD8vIb44RB0asNjWlhiA9KlkTBupMLDLjjP2r6esWXiUrU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from alumni.cs.wisc.edu (alumni.cs.wisc.edu [128.105.2.11]) by flint.cs.wisc.edu (8.14.7/8.14.4) with ESMTP id 43KLhlMx010862; Sat, 20 Apr 2024 16:43:47 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 flint.cs.wisc.edu 43KLhlMx010862 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.wisc.edu; s=csl-2018021300; t=1713649428; bh=hAD+JJbyxmKSgZ/cQo/E094nIjdmUEp3hTl9oR78Mg0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=b9bjdifeGfQ4IqFooXP/y3quawNEqtADQglqueFlaR/kCr+ZK/wcHKrNIbE48cxTY 3dwSkcuUrZOAbv5QqnMjTxIRnpreaNyzyMhvUJanEFfJiDq8THyZ+6XMLEpj2wiSkM 1g6/miRkao2OyPGDsKQo/svMoFndktFPUr4pohGalj61iFC9+knPiN4ueGyD+6cZMj XCQtGrsKJjbRDpJ+pDN7DX0BZhZJedEVhQRiC50rV4hVWoAxkYlZsBicoYEuTWMc/U KTSnJvIu4nJUhA/fTEZpDDkcwro3OreTHEbN0amLC4YpDaunn9tfSxWJGZMxm4uin8 3W91ZBd9vNspg== Received: from localhost (localhost.localdomain [127.0.0.1]) by alumni.cs.wisc.edu (Postfix) with ESMTP id 0F7331E083B; Sat, 20 Apr 2024 16:43:46 -0500 (CDT) Date: Sat, 20 Apr 2024 16:45:34 -0500 (CDT) From: Carl Edquist To: Zachary Santer cc: libc-alpha@sourceware.org, coreutils@gnu.org, =?utf-8?Q?P=C3=A1draig_Brady?= Subject: Re: Modify buffering of standard streams via environment variables (not LD_PRELOAD)? In-Reply-To: Message-ID: <6b1c46a9-95a6-9422-85aa-fa8035d6c429@cs.wisc.edu> References: <9831afe6-958a-fbd3-9434-05dd0c9b602a@draigBrady.com> <317fe0e2-8cf9-d4ac-ed56-e6ebcc2baa55@cs.wisc.edu> <8c490a55-598a-adf6-67c2-eb2a6099620a@cs.wisc.edu> <8d26e5046cc8bf49490e4aa3f6c00b09@kylheku.com> <12e70177-d115-3c0d-0603-635a14d032f1@cs.wisc.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+e=80x24.org@sourceware.org On Sat, 20 Apr 2024, Zachary Santer wrote: > This was actually in RHEL 7. Oh. In that case it might be worth looking into ... > I don't know how buffering works when stdout and stderr get redirected > to the same pipe. You'd think, whatever it is, it would have to be smart > enough to keep them interleaved in the same order they were printed to > in. That in mind, I would assume they both get placed into the same > block buffer by default. My take is always to try it and find out. Though in this case I think the default (without using stdbuf) is that the program's stderr is output to the pipe immediately (ie, unbuffered) on each library call (fprintf(3), fputs(3), putc(3), fwrite(3)), while stdout is written to the pipe at block boundaries - even though fd 1 and 2 refer to the same pipe. If you force line buffering for stdout and stderr, that is likely what you want, and it will interleave _lines_ in the order that they were printed. However, stdout and stderr are still separate streams even if they refer to the same output file/pipe/device, so partial lines are not interleaved in the order that they were printed. For example: #include int main() { putc('a', stderr); putc('1', stdout); putc('b', stderr); putc('2', stdout); putc('c', stderr); putc('3', stdout); putc('\n', stderr); putc('\n', stdout); return 0; } will output "abc\n123\n" instead of "a1b2c3\n\n", even if you run it as $ ./abc123 2>&1 | cat or $ stdbuf -oL -eL ./abc123 2>&1 | cat ... Not that that's relevant for what you're doing :) Carl