+ // Block all signals around vfork; see http://ewontfix.com/7/.
+ //
+ // As the child may run in the same address space as the parent until
+ // the actual execve() system call, any (custom) signal handlers that
+ // the parent has might alter parent's memory if invoked in the child,
+ // with undefined results. So we block all signals in the parent before
+ // vfork(), which will cause them to be blocked in the child as well (we
+ // rely on the fact that Linux, just like all sane implementations, only
+ // clones the calling thread). Then, in the child, we reset all signals
+ // to their default dispositions (while still blocked), and unblock them
+ // (so the exec()ed process inherits the parent's signal mask)
+ //
+ // The parent also unblocks all signals as soon as vfork() returns.
+ sigset_t allBlocked;
+ int r = ::sigfillset(&allBlocked);
+ checkUnixError(r, "sigfillset");
+ sigset_t oldSignals;
+ r = pthread_sigmask(SIG_SETMASK, &allBlocked, &oldSignals);
+ checkPosixError(r, "pthread_sigmask");
+