From 54e29e718a816e6cbbcbf2f439c73e29c1e63ed1 Mon Sep 17 00:00:00 2001 From: Peter Griess Date: Wed, 20 Nov 2013 13:51:57 -0800 Subject: [PATCH] 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 --- folly/Subprocess.cpp | 7 +++++-- folly/Subprocess.h | 13 ++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/folly/Subprocess.cpp b/folly/Subprocess.cpp index 846076dd..6581a5b8 100644 --- a/folly/Subprocess.cpp +++ b/folly/Subprocess.cpp @@ -16,11 +16,12 @@ #include "folly/Subprocess.h" +#if __linux__ #include +#endif #include #include #include -#include #include #include @@ -362,7 +363,7 @@ void Subprocess::spawnInternal( // // The parent also unblocks all signals as soon as vfork() returns. sigset_t allBlocked; - r = ::sigfillset(&allBlocked); + r = sigfillset(&allBlocked); checkUnixError(r, "sigfillset"); sigset_t oldSignals; @@ -445,6 +446,7 @@ int Subprocess::prepareChild(const Options& options, } } +#if __linux__ // Opt to receive signal on parent death, if requested if (options.parentDeathSignal_ != 0) { r = prctl(PR_SET_PDEATHSIG, options.parentDeathSignal_, 0, 0, 0); @@ -452,6 +454,7 @@ int Subprocess::prepareChild(const Options& options, return errno; } } +#endif return 0; } diff --git a/folly/Subprocess.h b/folly/Subprocess.h index 74e9fe9b..b2c13303 100644 --- a/folly/Subprocess.h +++ b/folly/Subprocess.h @@ -56,7 +56,11 @@ #include #include +#if __APPLE__ +#include +#else #include +#endif #include #include @@ -201,8 +205,7 @@ class Subprocess : private boost::noncopyable { public: Options() : closeOtherFds_(false), - usePath_(false), - parentDeathSignal_(0) { + usePath_(false) { } /** @@ -261,6 +264,7 @@ class Subprocess : private boost::noncopyable { */ Options& usePath() { usePath_ = true; return *this; } +#if __linux__ /** * Child will receive a signal when the parent exits. */ @@ -268,6 +272,7 @@ class Subprocess : private boost::noncopyable { parentDeathSignal_ = sig; return *this; } +#endif /** * Helpful way to combine Options. @@ -279,7 +284,9 @@ class Subprocess : private boost::noncopyable { FdMap fdActions_; bool closeOtherFds_; bool usePath_; - int parentDeathSignal_; +#if __linux__ + int parentDeathSignal_{0}; +#endif }; static Options pipeStdin() { return Options().stdin(PIPE); } -- 2.34.1