Commit 54e29e71 authored by Peter Griess's avatar Peter Griess

Get Subprocess running for Mac OS X

Summary:
- D1030008 added Subprocess to libfolly in automake builds. This
surfaced some ambient compilation errors that slipped through in my
prior run through porting this.
- Mac OS X uses a nonstandard location for wait.h
- Non-Linux platforms don't support prctl; gate that on Linux

Test Plan:
- fbmake runtests in fbcode
- make check on Mac OS X

Reviewed By: davejwatson@fb.com

FB internal diff: D1066273

Blame Revision: D1030008
parent c807fe1f
...@@ -16,11 +16,12 @@ ...@@ -16,11 +16,12 @@
#include "folly/Subprocess.h" #include "folly/Subprocess.h"
#if __linux__
#include <sys/prctl.h> #include <sys/prctl.h>
#endif
#include <fcntl.h> #include <fcntl.h>
#include <poll.h> #include <poll.h>
#include <unistd.h> #include <unistd.h>
#include <wait.h>
#include <array> #include <array>
#include <algorithm> #include <algorithm>
...@@ -362,7 +363,7 @@ void Subprocess::spawnInternal( ...@@ -362,7 +363,7 @@ void Subprocess::spawnInternal(
// //
// The parent also unblocks all signals as soon as vfork() returns. // The parent also unblocks all signals as soon as vfork() returns.
sigset_t allBlocked; sigset_t allBlocked;
r = ::sigfillset(&allBlocked); r = sigfillset(&allBlocked);
checkUnixError(r, "sigfillset"); checkUnixError(r, "sigfillset");
sigset_t oldSignals; sigset_t oldSignals;
...@@ -445,6 +446,7 @@ int Subprocess::prepareChild(const Options& options, ...@@ -445,6 +446,7 @@ int Subprocess::prepareChild(const Options& options,
} }
} }
#if __linux__
// Opt to receive signal on parent death, if requested // Opt to receive signal on parent death, if requested
if (options.parentDeathSignal_ != 0) { if (options.parentDeathSignal_ != 0) {
r = prctl(PR_SET_PDEATHSIG, options.parentDeathSignal_, 0, 0, 0); r = prctl(PR_SET_PDEATHSIG, options.parentDeathSignal_, 0, 0, 0);
...@@ -452,6 +454,7 @@ int Subprocess::prepareChild(const Options& options, ...@@ -452,6 +454,7 @@ int Subprocess::prepareChild(const Options& options,
return errno; return errno;
} }
} }
#endif
return 0; return 0;
} }
......
...@@ -56,7 +56,11 @@ ...@@ -56,7 +56,11 @@
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> #include <signal.h>
#if __APPLE__
#include <sys/wait.h>
#else
#include <wait.h> #include <wait.h>
#endif
#include <exception> #include <exception>
#include <vector> #include <vector>
...@@ -201,8 +205,7 @@ class Subprocess : private boost::noncopyable { ...@@ -201,8 +205,7 @@ class Subprocess : private boost::noncopyable {
public: public:
Options() Options()
: closeOtherFds_(false), : closeOtherFds_(false),
usePath_(false), usePath_(false) {
parentDeathSignal_(0) {
} }
/** /**
...@@ -261,6 +264,7 @@ class Subprocess : private boost::noncopyable { ...@@ -261,6 +264,7 @@ class Subprocess : private boost::noncopyable {
*/ */
Options& usePath() { usePath_ = true; return *this; } Options& usePath() { usePath_ = true; return *this; }
#if __linux__
/** /**
* Child will receive a signal when the parent exits. * Child will receive a signal when the parent exits.
*/ */
...@@ -268,6 +272,7 @@ class Subprocess : private boost::noncopyable { ...@@ -268,6 +272,7 @@ class Subprocess : private boost::noncopyable {
parentDeathSignal_ = sig; parentDeathSignal_ = sig;
return *this; return *this;
} }
#endif
/** /**
* Helpful way to combine Options. * Helpful way to combine Options.
...@@ -279,7 +284,9 @@ class Subprocess : private boost::noncopyable { ...@@ -279,7 +284,9 @@ class Subprocess : private boost::noncopyable {
FdMap fdActions_; FdMap fdActions_;
bool closeOtherFds_; bool closeOtherFds_;
bool usePath_; bool usePath_;
int parentDeathSignal_; #if __linux__
int parentDeathSignal_{0};
#endif
}; };
static Options pipeStdin() { return Options().stdin(PIPE); } static Options pipeStdin() { return Options().stdin(PIPE); }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment