96 #include <sys/types.h> 108 #include <boost/container/flat_map.hpp> 109 #include <boost/operators.hpp> 233 using std::runtime_error::runtime_error;
271 static const int CLOSE = -1;
272 static const int PIPE = -2;
273 static const int PIPE_IN = -3;
274 static const int PIPE_OUT = -4;
290 virtual int operator()() = 0;
327 return fd(STDIN_FILENO, action);
334 return fd(STDOUT_FILENO, action);
343 return fd(STDERR_FILENO, action);
347 return fd(STDIN_FILENO, PIPE_IN);
350 return fd(STDOUT_FILENO, PIPE_OUT);
353 return fd(STDERR_FILENO, PIPE_OUT);
369 closeOtherFds_ =
true;
394 parentDeathSignal_ =
sig;
405 processGroupLeader_ =
true;
459 dangerousPostForkPreExecCallback_ = cob;
481 cloneFlags_ = cloneFlags;
487 typedef boost::container::flat_map<int, int>
FdMap;
489 bool closeOtherFds_{
false};
490 bool usePath_{
false};
491 bool processGroupLeader_{
false};
495 int parentDeathSignal_{0};
530 const std::vector<std::string>&
argv,
532 const char* executable =
nullptr,
533 const std::vector<std::string>* env =
nullptr);
544 "Prefer not running in a shell or use `shellify`.")]]
548 const std::vector<std::string>* env =
nullptr);
607 void sendSignal(
int signal);
645 std::pair<IOBufQueue, IOBufQueue> communicateIOBuf(
648 std::pair<std::string, std::string> communicate(
748 template <
class Callback>
767 char delimiter =
'\n',
769 : fdLineCb_(
std::forward<Callback>(fdLineCb)),
770 maxLineLength_(maxLineLength),
771 delimiter_(delimiter),
776 auto it = fdToSplitter_.find(cfd);
777 auto& splitter = (it != fdToSplitter_.end())
790 ssize_t ret =
readNoInt(pfd, buf, bufSize_);
791 if (ret == -1 && errno == EAGAIN) {
815 template <
class Callback>
819 char delimiter =
'\n',
823 std::forward<Callback>(fdLineCb), maxLineLength, delimiter, bufSize);
837 void enableNotifications(
int childFd,
bool enabled);
843 bool notificationsEnabled(
int childFd)
const;
856 void closeParentFd(
int childFd);
862 void setAllNonBlocking();
870 return pipes_[findByChildFd(childFd)].pipe.fd();
900 std::vector<ChildPipe> takeOwnershipOfPipes();
908 std::unique_ptr<
const char*[]> argv,
909 const char* executable,
911 const std::vector<std::string>* env);
913 std::unique_ptr<
const char*[]> argv,
914 const char* executable,
916 const std::vector<std::string>* env,
924 const sigset_t* sigmask,
925 const char* childDir)
const;
927 const char* executable,
936 void readChildErrorPipe(
int pfd,
const char* executable);
939 size_t findByChildFd(
const int childFd)
const;
950 struct Pipe :
private boost::totally_ordered<Pipe> {
953 int direction = PIPE_IN;
957 return childFd < other.
childFd;
960 return childFd == other.
childFd;
ProcessReturnCode returnCode_
static constexpr int RV_RUNNING
virtual ~DangerousPostForkPreExecCallback()
std::unordered_map< int, LineSplitter > fdToSplitter_
ProcessReturnCode & operator=(const ProcessReturnCode &p)=default
static ProcessReturnCode makeNotStarted()
static ProcessReturnCode makeRunning()
ProcessReturnCode returnCode() const
Options & chdir(const std::string &dir)
static constexpr int RV_NOT_STARTED
ChildPipe(int fd, folly::File &&ppe)
Options & stdinFd(int action)
static ProcessReturnCode make(int status)
gen::StreamSplitter< StreamSplitterCallback > LineSplitter
constexpr detail::Map< Move > move
ssize_t readNoInt(int fd, void *buf, size_t count)
void runChild(const char *file)
—— Concurrent Priority Queue Implementation ——
requires E e noexcept(noexcept(s.error(std::move(e))))
StreamSplitterCallback(Callback &cb, int fd)
std::vector< Pipe > pipes_
ProcessReturnCode(int rv)
bool operator()(int pfd, int cfd)
std::unique_ptr< AsyncFizzServer::HandshakeCallback > cb_
Options & processGroupLeader()
ProcessReturnCode returnCode_
constexpr detail::Sig< Sig > const sig
bool wait(Waiter *waiter, bool shouldSleep, Waiter *&next)
ReadLinesCallback(Callback &&fdLineCb, uint64_t maxLineLength=0, char delimiter= '\n', uint64_t bufSize=1024)
Options & closeOtherFds()
void checkUnixError(ssize_t ret, Args &&...args)
Options & stderrFd(int action)
const uint64_t maxLineLength_
bool operator==(const Pipe &other) const
int poll(PollDescriptor fds[], nfds_t nfds, int timeout)
void enforce(State state) const
ProcessReturnCode returnCode() const
bool operator<(const Pipe &other) const
Options & stdoutFd(int action)
Options & dangerousPostForkPreExecCallback(DangerousPostForkPreExecCallback *cob)
boost::container::flat_map< int, int > FdMap
Range< const char * > StringPiece
int parentFd(int childFd) const
bool operator()(StringPiece s)
void pipe(CPUExecutor cpu, IOExecutor io)
static auto readLinesCallback(Callback &&fdLineCb, uint64_t maxLineLength=0, char delimiter= '\n', uint64_t bufSize=1024) -> ReadLinesCallback< typename std::decay< Callback >::type >