From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8464 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: process doesn't terminate when closing streams from another thread Date: Sun, 6 Sep 2015 19:00:33 +0200 Message-ID: <20150906170033.GL28959@port70.net> References: 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 1441558849 9899 80.91.229.3 (6 Sep 2015 17:00:49 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 6 Sep 2015 17:00:49 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8476-gllmg-musl=m.gmane.org@lists.openwall.com Sun Sep 06 19:00:48 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 1ZYdJ9-0003aW-8W for gllmg-musl@m.gmane.org; Sun, 06 Sep 2015 19:00:47 +0200 Original-Received: (qmail 13693 invoked by uid 550); 6 Sep 2015 17:00:46 -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 13675 invoked from network); 6 Sep 2015 17:00:45 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Xref: news.gmane.org gmane.linux.lib.musl.general:8464 Archived-At: * 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.