Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20150907045044.GY17773@brightrain.aerifal.cx>
Date: Mon, 7 Sep 2015 00:50:44 -0400
From: Rich Felker <dalias@...c.org>
To: musl@...ts.openwall.com
Subject: Re: process doesn't terminate when closing streams from
 another thread

On Sun, Sep 06, 2015 at 07:00:33PM +0200, Szabolcs Nagy wrote:
> * Nuno Gon?alves <nunojpg@...il.com> [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@...nWrt:/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

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.