X-Recipient: archive-cygwin@delorie.com
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 49B303858010
Authentication-Results: sourceware.org;
 dmarc=fail (p=none dis=none) header.from=nifty.ne.jp
Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp
DKIM-Filter: OpenDKIM Filter v2.10.3 conssluserg-06.nifty.com 24H3HEIX024271
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.ne.jp;
 s=dec2015msa; t=1652757434;
 bh=RamjmwGXPzHpMGSz1tuh+9AKtOSNgApSM/0XzRdcy1Y=;
 h=Date:From:To:Subject:In-Reply-To:References:From;
 b=nsF/JGzMu73/ghauJtYOt8WnGcoE17V3ih3b39jZiyRv/VAVy4LTJSjN2jlT9AGlP
 IgRJVoS6CLEYszS3QPoHYvVFERf2Ibl0PvPkViquiJfVBgvNqpkM0f78ZWvdGby1Dx
 Z+c1a/lHTC4jwIHITr+QvKQhjB0GI3nNu3idluJuf32ecOsjiU254vCzwMVSSIizgc
 bBi51/1AD+OTMs2HSEyYpiLT1nr5PbVA16IeZOmQiJKKVJ1yEpi8MKoOLMnIbMkw7p
 Jxip2TnYFH3LWlTSMcrJxsCI8L8bJZj6nAWGhq85nkISLkuloNQYqDldNMGsUCFSq5
 zYW0xQ3Sne9+g==
X-Nifty-SrcIP: [119.150.44.95]
Date: Tue, 17 May 2022 12:17:24 +0900
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: ps | cat broken in newlib-cygwin git head (master)
Message-Id: <20220517121724.d801487688110f34f2e5d764@nifty.ne.jp>
In-Reply-To: <20220517043712.c3208bf70ad0d338a562aaf6@nifty.ne.jp>
References: <20220517043712.c3208bf70ad0d338a562aaf6@nifty.ne.jp>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED,
 DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A,
 RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP,
 T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6
X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on
 server2.sourceware.org
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces+archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces+archive-cygwin=delorie.com@cygwin.com>

On Tue, 17 May 2022 04:37:12 +0900
Takashi Yano wrote:
> I found that "ps | cat" outputs nothing with the current git head (master)
> of newlib-cygwin. However, just "ps" and "ls | cat" works.
> 
> This happens after the commit:
> 
> commit 26747c47bc0a1137e02e0377306d721cc3478855
> Author: Matt Joyce <matthew.joyce@embedded-brains.de>
> Date:   Tue May 3 06:51:22 2022 +0200
> 
>     Add stdio_exit_handler()
> 
>     Add a dedicated stdio exit handler to avoid using _GLOBAL_REENT in exit().
> 
> 
> Is this the problem of cygwin side? Or newlib?
> 
> I also found "stdbuf -o 0 ps | cat" works. It seems that this problem is
> caused by buffering of stdout.

I am not sure this is the right thing, however, I found the following
patch solves the issue. It seems that initializing __stdio_exit_handler
is missing.

diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 19952d4e0..e759b5402 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -63,6 +63,8 @@ struct _glue __sglue = {NULL, 3, &_GLOBAL_REENT->__sf[0]};
 #endif
 #endif
 
+static void stdio_exit_handler (void);
+
 #if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED))
 _NOINLINE_STATIC void
 #else
@@ -109,6 +111,11 @@ std (FILE *ptr,
   if (__stextmode (ptr->_file))
     ptr->_flags |= __SCLE;
 #endif
+
+  if (__stdio_exit_handler == NULL) {
+    __sinit (_GLOBAL_REENT);
+    __stdio_exit_handler = stdio_exit_handler;
+  }
 }
 
 static inline void

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

-- 
Problem reports:      https://cygwin.com/problems.html
FAQ:                  https://cygwin.com/faq/
Documentation:        https://cygwin.com/docs.html
Unsubscribe info:     https://cygwin.com/ml/#unsubscribe-simple
