|
Ninja
|
Subprocess wraps a single async subprocess. More...
#include <subprocess.h>
Public Member Functions | |
| bool | Done () const |
| ExitStatus | Finish () |
| Returns ExitSuccess on successful process exit, ExitInterrupted if the process was interrupted, ExitFailure if it otherwise failed. More... | |
| const std::string & | GetOutput () const |
| ~Subprocess () | |
Private Member Functions | |
| void | OnPipeReady () |
| bool | Start (struct SubprocessSet *set, const std::string &command) |
| Subprocess (bool use_console) | |
| bool | TryFinish (int waitpid_options) |
| Call waitpid() on the subprocess with the provided options and update the pid_ and exit_status_ fields. More... | |
Private Attributes | |
| std::string | buf_ |
| ExitStatus | exit_status_ |
| In POSIX platforms it is necessary to use waitpid(WNOHANG) to know whether a certain subprocess has finished. More... | |
| int | fd_ |
| The file descriptor that will be used in ppoll/pselect() for this process, if any. More... | |
| pid_t | pid_ |
| PID of the subprocess. Set to -1 when the subprocess is reaped. More... | |
| bool | use_console_ |
Friends | |
| struct | SubprocessSet |
Subprocess wraps a single async subprocess.
It is entirely passive: it expects the caller to notify it when its fds are ready for reading, as well as call Finish() to reap the child once done() is true.
Definition at line 42 of file subprocess.h.
| Subprocess::~Subprocess | ( | ) |
Definition at line 48 of file subprocess-posix.cc.
|
private |
Definition at line 44 of file subprocess-posix.cc.
| bool Subprocess::Done | ( | ) | const |
Definition at line 214 of file subprocess-posix.cc.
References fd_, pid_, and use_console_.
Referenced by TEST_F().
| ExitStatus Subprocess::Finish | ( | ) |
Returns ExitSuccess on successful process exit, ExitInterrupted if the process was interrupted, ExitFailure if it otherwise failed.
Definition at line 178 of file subprocess-posix.cc.
References exit_status_, pid_, and TryFinish().
Referenced by TEST_F(), RealCommandRunner::WaitForCommand(), and ~Subprocess().
| const string & Subprocess::GetOutput | ( | ) | const |
Definition at line 222 of file subprocess-posix.cc.
References buf_.
Referenced by TEST_F(), and RealCommandRunner::WaitForCommand().
|
private |
Definition at line 150 of file subprocess-posix.cc.
|
private |
Definition at line 56 of file subprocess-posix.cc.
References environ, Fatal(), fd_, SubprocessSet::old_mask_, pid_, SetCloseOnExec(), and use_console_.
Referenced by SubprocessSet::Add().
|
private |
Call waitpid() on the subprocess with the provided options and update the pid_ and exit_status_ fields.
Return a boolean indicating whether the subprocess has indeed terminated.
Definition at line 164 of file subprocess-posix.cc.
References exit_status_, Fatal(), and pid_.
Referenced by Finish().
|
friend |
Definition at line 95 of file subprocess.h.
|
private |
Definition at line 58 of file subprocess.h.
Referenced by GetOutput(), and OnPipeReady().
|
private |
In POSIX platforms it is necessary to use waitpid(WNOHANG) to know whether a certain subprocess has finished.
This is done for terminal subprocesses. However, this also causes the subprocess to be reaped before Finish() is called, so we need to store the ExitStatus so that a later Finish() invocation can return it.
Definition at line 86 of file subprocess.h.
Referenced by Finish(), and TryFinish().
|
private |
The file descriptor that will be used in ppoll/pselect() for this process, if any.
Otherwise -1. In non-console mode, this is the read-side of a pipe that was created specifically for this subprocess. The write-side of the pipe is given to the subprocess as combined stdout and stderr. In console mode no pipe is created: fd_ is -1, and process termination is detected using the SIGCHLD signal and waitpid(WNOHANG).
Definition at line 78 of file subprocess.h.
Referenced by Done(), OnPipeReady(), Start(), and ~Subprocess().
|
private |
PID of the subprocess. Set to -1 when the subprocess is reaped.
Definition at line 80 of file subprocess.h.
Referenced by Done(), Finish(), Start(), TryFinish(), and ~Subprocess().
|
private |
Definition at line 93 of file subprocess.h.