From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8465 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: process doesn't terminate when closing streams from another thread Date: Mon, 7 Sep 2015 00:50:44 -0400 Message-ID: <20150907045044.GY17773@brightrain.aerifal.cx> References: <20150906170033.GL28959@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1441601468 3901 80.91.229.3 (7 Sep 2015 04:51:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 7 Sep 2015 04:51:08 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8477-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 07 06:51:03 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ZYoOR-0000FJ-RV for gllmg-musl@m.gmane.org; Mon, 07 Sep 2015 06:50:59 +0200 Original-Received: (qmail 24363 invoked by uid 550); 7 Sep 2015 04:50:58 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24345 invoked from network); 7 Sep 2015 04:50:57 -0000 Content-Disposition: inline In-Reply-To: <20150906170033.GL28959@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:8465 Archived-At: On Sun, Sep 06, 2015 at 07:00:33PM +0200, Szabolcs Nagy wrote: > * Nuno Gon?alves [2015-09-06 15:44:45 +0100]: > > I'm having problems when closing streams from another thread. > > > > The following code: > > > > static void *func(void *arg) > > { > > fclose(stdout); > > fprintf(stderr,"Thread about to exit\n"); > > return 0; > > } > > > > int main(int argc, char **argv) > > { > > int thread_id; > > s/int/pthread_t/ > > > pthread_create(&thread_id,NULL,&func,NULL); > > pthread_join(thread_id,NULL); > > fprintf(stderr,"Process about to terminate\n"); > > return 0; > > } > > > > Prints: > > > > root@OpenWrt:/tmp# ./myapp_withmusl > > Thread about to exit > > Process about to terminate > > > > But never returns! I have to send it a SIGINT. > > > > yes, musl fflushes stdout on fflush(0) even if > it is closed. (fflush(0) is called at exit, > fflushing a closed stream is undefined behaviour). > > this might be a musl bug. Yes, this is indeed a musl bug. Getting the right fix is non-trivial but I think it will involve having fclose unlock the FILE but ensure that its contents are setup such that the exit-time code behaves as a no-op. Rich