From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id D3FA03858C74 for ; Tue, 17 May 2022 10:11:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D3FA03858C74 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy01.your-server.de ([78.46.139.224]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nquAx-000Myt-79 for newlib@sourceware.org; Tue, 17 May 2022 12:11:35 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy01.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nquAx-000W82-3Q for newlib@sourceware.org; Tue, 17 May 2022 12:11:35 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id C8DB4480075 for ; Tue, 17 May 2022 12:11:34 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 2mHhadLRF4Bj for ; Tue, 17 May 2022 12:11:34 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 8D11A4800ED for ; Tue, 17 May 2022 12:11:34 +0200 (CEST) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id hWX1i92WudFL for ; Tue, 17 May 2022 12:11:34 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.242]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 6FE91480075 for ; Tue, 17 May 2022 12:11:34 +0200 (CEST) From: Sebastian Huber To: newlib@sourceware.org Subject: [PATCH] Fix stdio exit handling Date: Tue, 17 May 2022 12:11:31 +0200 Message-Id: <20220517101131.1950-1-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26544/Tue May 17 10:09:52 2022) X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 May 2022 10:11:38 -0000 Make sure that the stdio exit handler is set in all stdio initialization = paths. The bug was introduced by commit 26747c47bc0a1137e02e0377306d721cc3478855= . --- newlib/libc/stdio/findfp.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c index 19952d4e0..118637a18 100644 --- a/newlib/libc/stdio/findfp.c +++ b/newlib/libc/stdio/findfp.c @@ -168,6 +168,19 @@ stdio_exit_handler (void) (void) _fwalk_sglue (_GLOBAL_REENT, CLEANUP_FILE, &__sglue); } =20 +static void +global_stdio_init (void) +{ + if (__stdio_exit_handler =3D=3D NULL) { + __stdio_exit_handler =3D stdio_exit_handler; +#ifdef _REENT_GLOBAL_STDIO_STREAMS + stdin_init (&__sf[0]); + stdout_init (&__sf[1]); + stderr_init (&__sf[2]); +#endif + } +} + /* * Find a free FILE for fopen et al. */ @@ -180,11 +193,7 @@ __sfp (struct _reent *d) struct _glue *g; =20 _newlib_sfp_lock_start (); - - if (__stdio_exit_handler =3D=3D NULL) { - __sinit (_GLOBAL_REENT); - __stdio_exit_handler =3D stdio_exit_handler; - } + global_stdio_init (); =20 for (g =3D &__sglue;; g =3D g->_next) { @@ -273,13 +282,9 @@ __sinit (struct _reent *s) # endif /* _REENT_GLOBAL_STDIO_STREAMS */ #endif =20 -#ifdef _REENT_GLOBAL_STDIO_STREAMS - if (__sf[0]._cookie =3D=3D NULL) { - stdin_init (&__sf[0]); - stdout_init (&__sf[1]); - stderr_init (&__sf[2]); - } -#else /* _REENT_GLOBAL_STDIO_STREAMS */ + global_stdio_init (); + +#ifndef _REENT_GLOBAL_STDIO_STREAMS stdin_init (s->_stdin); stdout_init (s->_stdout); stderr_init (s->_stderr); --=20 2.35.3