ochameau/jetpack-subprocess — pull request #7 by ochameau (2013-10-28 13:33:03+00:00)
Title: Use posix_spawn instead of fork/exec to prevent crashes on MacOS Maverick

https://bugzilla.mozilla.org/show_bug.cgi?id=928168

I never really looked deeply into subprocess.jsm code, but calling fork() directly from JS looks very scary.
I have hard time figuring out what happens with the JS engine and especially with the garbage collector!!

And surprisingly, the crash being reported on Maverick happens during fork call when a call to free is made to an already freed object or a wrong address. I haven't been able to figure out very precisely what exactly crashes, as it is very challenging to plug a debugger (and especially lldb) to the very early stages of fork...

I'm convinced we should avoid executing javascript in another process like that. There is some alternatives to fork+exec, posix_spawn looks like a good candidate. It will do the fork+exec for us and nothing magical will happen in JS anymore.

posix_spawn comes with some limitations: lack of workdir support for the child (we have to change the parent process workdir) and no easy way to close all file descriptors in the child (I haven't found a way to do it on Mac).
But I think it is still better than doing a fork in JS.