[swift-corelibs-dev] Recommended posix_spawnattr_t for NSTask's implementation

Dan Stenmark daniel.j.stenmark at gmail.com
Fri Dec 18 15:25:05 CST 2015


I’m assuming that OS X’s method for setting a pthread’s cwd is private API.  Unless a better way to accomplish the same end-goal is in the works, is there any way to expose it?

In regards to Linux, the more I look at this, the less attractive posix_spawn() appears as a way of implementing this on that platform.  I’ll likely have a better idea how to approach this following some prototyping later tonight, but my current line of thinking involves vfork() -> unshare() -> chdir() -> execve().

Dan

> On Dec 18, 2015, at 12:39 PM, Pierre Habouzit <pierre at habouzit.net> wrote:
> 
> FWIW Glibc implements posix_spawn on posix platforms in terms of {,v}fork + execve.
> So that means that SIGCHLD can be used.
> 
> I don’t think linux has per-thread wd, since linux has had atcalls for a very long time, which makes this system interface not useful and only weird (pthread_{,f}chdir).
> 
> I don’t think there’s a good way to fix this beside asking for POSIX to have a posix_spawnattr_setwd(attr, const char *); or changing it around the spawn, which of course, is bad and racy
> 
> The other alternative is to use a trampoline execv() when -[NSTask currentDirectoryPath] has been set that will just chdir() and exec's again. it’s not really pretty but does the job. Given that this should be the exception and not the rule, maybe that’s acceptable.
> 
> 
> -Pierre
> 
>> On Dec 18, 2015, at 11:37 AM, David Smith via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
>> 
>> One issue that we ran into in the ObjC NSTask is setting the current working directory in the child process. We worked around the lack of an API for that by using per-thread working directories, which is kind of awful. I'm not up to date on what the best approach to use for this on Linux would be; it sounds like clone() can do it, but I don't know if that's exposed at the posix_spawn level at all.
>> 
>> 	David
>> 
>>> On Dec 18, 2015, at 11:08 AM, Dan Stenmark via swift-corelibs-dev <swift-corelibs-dev at swift.org> wrote:
>>> 
>>> I hope to take a crack at implementing some of NSTask this weekend.  What are the recommended posix_spawnattr_t flags that should be set?  Do we also want to take the opportunity to expose the ability to override some of these flags (like POSIX_SPAWN_SETPGROUP) or do we want to avoid tying this with posix_spawn() too closely?
>>> 
>>> Dan
>>> _______________________________________________
>>> swift-corelibs-dev mailing list
>>> swift-corelibs-dev at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev
>> 
>> _______________________________________________
>> swift-corelibs-dev mailing list
>> swift-corelibs-dev at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-corelibs-dev
> 



More information about the swift-corelibs-dev mailing list