develooper Front page | perl.perl5.porters | Postings from September 2010

[perl #75154] Spawning threads with open directory handles causes a crash

Thread Next
From:
Father Chrysostomos via RT
Date:
September 19, 2010 13:10
Subject:
[perl #75154] Spawning threads with open directory handles causes a crash
Message ID:
rt-3.6.HEAD-5116-1284927039-1192.75154-15-0@perl.org
On Tue May 25 01:42:10 2010, sprout wrote:
> This is the result of this function in sv.c:
> 
> DIR *
> Perl_dirp_dup(pTHX_ DIR *const dp)
> {
>      PERL_UNUSED_CONTEXT;
>      if (!dp)
> 	return (DIR*)NULL;
>      /* XXX TODO */
>      return dp;
> }
> 
> Unfortunately, I don’t know how to duplicate a directory handle  
> properly.
> 
> The attached patch (not to be applied; just an example) makes a copy  
> using dup2, but the resulting dir handles share the same iterator  
> (i.e., the current behaviour, but without the crash). The code works  
> on Mac OS X, but I doubt it’s portable. I don’t know how to make it  
> work on other systems.
> 
> I can see three ultimate solutions (in order of preference):
> 
> a) Properly duplicate the dir handle so we have a new one with its own  
> iterator (I can’t find a fopendir function anywhere)
> b) Simple duplicate the dir handle as in my example
> c) Don’t copy dir handles into threads (return (DIR*)NULL; I tried  
> that and it works)
> 
> If b or c happens, I think this needs to be documented in threads.pm.  
> We may have to choose between different items in the list at configure- 
> time, based on OS.
> 

Attached is a patch to fix this. On systems with fchdir, it dwims (a).
On other systems the dir handle is simply not passed to the thread (c).


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About