[PATCH] Fix usage of posix_spawn_file_actions_addopen

Hal Finkel hfinkel at anl.gov
Fri Jul 26 09:07:13 PDT 2013


Rafael,

This also seems to work well (and is simpler), thanks!

 -Hal

----- Original Message -----
> How about creating the std::string in the caller? would the attached
> patch (with comments about what is going on) work?
> 
> On 26 July 2013 10:25, Hal Finkel <hfinkel at anl.gov> wrote:
> > Hello,
> >
> > The Execute function in Unix/Program.inc uses posix_spawn, when
> > available (and when no memory limit is requested), to execute
> > child programs. When file descriptor redirection is specified,
> > posix_spawn_file_actions_addopen is used to add an open file
> > action to the posix_spawn request. Unfortunately, the argument to
> > posix_spawn_file_actions_addopen is obtained by calling
> > File.c_str(), and so the lifetime of the provided pointer is
> > limited. On systems using glibc, this does not work. The
> > implementation assumes that the lifetime of the provided pointer
> > will not end prior to the call to posix_spawn itself(*).
> >
> > This problem was causing bugpoint to (nondeterministically) fail to
> > execute gcc on some of my systems.
> >
> > I've attached a patch which extends the lifetime of the strings
> > provided to posix_spawn_file_actions_addopen, allowing this to
> > work correctly with glibc. The standard does not seem to specify
> > one way or the other what string lifetime is expected.
> > Alternatively, we could consider glibc broken in this area, and
> > avoid using posix_spawn with glibc.
> >
> > Please review.
> >
> > Thanks again,
> > Hal
> >
> > (*) You can see this by looking at the source, see:
> > http://fossies.org/dox/glibc-2.17/spawn__faction__addopen_8c_source.html#l00027
> >
> > As a quick example of something else, here's a different
> > implementation that does make a copy of the provided string:
> > https://github.com/evanphx/ulysses-libc/blob/master/src/process/posix_spawn_file_actions_addopen.c
> >
> > --
> > Hal Finkel
> > Assistant Computational Scientist
> > Leadership Computing Facility
> > Argonne National Laboratory
> 

-- 
Hal Finkel
Assistant Computational Scientist
Leadership Computing Facility
Argonne National Laboratory



More information about the llvm-commits mailing list