projects
/
folly.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use explicit memory order in Baton::post
[folly.git]
/
folly
/
Subprocess.h
diff --git
a/folly/Subprocess.h
b/folly/Subprocess.h
index 01e6d2c07ab148b833a2c2915fa0d67b4e2f6550..72cf3fe05ea628023f7d6f618d82b4d18b14b179 100644
(file)
--- a/
folly/Subprocess.h
+++ b/
folly/Subprocess.h
@@
-93,8
+93,9
@@
#pragma once
#pragma once
-#include <sys/types.h>
#include <signal.h>
#include <signal.h>
+#include <sys/types.h>
+
#if __APPLE__
#include <sys/wait.h>
#else
#if __APPLE__
#include <sys/wait.h>
#else
@@
-102,8
+103,8
@@
#endif
#include <exception>
#endif
#include <exception>
-#include <vector>
#include <string>
#include <string>
+#include <vector>
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_map.hpp>
@@
-126,7
+127,6
@@
namespace folly {
*/
class Subprocess;
class ProcessReturnCode {
*/
class Subprocess;
class ProcessReturnCode {
- friend class Subprocess;
public:
enum State {
// Subprocess starts in the constructor, so this state designates only
public:
enum State {
// Subprocess starts in the constructor, so this state designates only
@@
-134,12
+134,22
@@
class ProcessReturnCode {
NOT_STARTED,
RUNNING,
EXITED,
NOT_STARTED,
RUNNING,
EXITED,
- KILLED
+ KILLED
,
};
};
+ static ProcessReturnCode makeNotStarted() {
+ return ProcessReturnCode(RV_NOT_STARTED);
+ }
+
+ static ProcessReturnCode makeRunning() {
+ return ProcessReturnCode(RV_RUNNING);
+ }
+
+ static ProcessReturnCode make(int status);
+
// Default-initialized for convenience. Subprocess::returnCode() will
// never produce this value.
// Default-initialized for convenience. Subprocess::returnCode() will
// never produce this value.
- ProcessReturnCode() :
ProcessReturnCode
(RV_NOT_STARTED) {}
+ ProcessReturnCode() :
rawStatus_
(RV_NOT_STARTED) {}
// Trivially copyable
ProcessReturnCode(const ProcessReturnCode& p) = default;
// Trivially copyable
ProcessReturnCode(const ProcessReturnCode& p) = default;
@@
-209,7
+219,10
@@
class ProcessReturnCode {
/**
* Base exception thrown by the Subprocess methods.
*/
/**
* Base exception thrown by the Subprocess methods.
*/
-class SubprocessError : public std::exception {};
+class SubprocessError : public std::runtime_error {
+ public:
+ using std::runtime_error::runtime_error;
+};
/**
* Exception thrown by *Checked methods of Subprocess.
/**
* Exception thrown by *Checked methods of Subprocess.
@@
-217,12
+230,10
@@
class SubprocessError : public std::exception {};
class CalledProcessError : public SubprocessError {
public:
explicit CalledProcessError(ProcessReturnCode rc);
class CalledProcessError : public SubprocessError {
public:
explicit CalledProcessError(ProcessReturnCode rc);
- ~CalledProcessError() throw() = default;
- const char* what() const throw() override { return what_.c_str(); }
+ ~CalledProcessError() throw() override = default;
ProcessReturnCode returnCode() const { return returnCode_; }
private:
ProcessReturnCode returnCode_;
ProcessReturnCode returnCode() const { return returnCode_; }
private:
ProcessReturnCode returnCode_;
- std::string what_;
};
/**
};
/**
@@
-231,13
+242,11
@@
class CalledProcessError : public SubprocessError {
class SubprocessSpawnError : public SubprocessError {
public:
SubprocessSpawnError(const char* executable, int errCode, int errnoValue);
class SubprocessSpawnError : public SubprocessError {
public:
SubprocessSpawnError(const char* executable, int errCode, int errnoValue);
- ~SubprocessSpawnError() throw() = default;
- const char* what() const throw() override { return what_.c_str(); }
+ ~SubprocessSpawnError() throw() override = default;
int errnoValue() const { return errnoValue_; }
private:
int errnoValue_;
int errnoValue() const { return errnoValue_; }
private:
int errnoValue_;
- std::string what_;
};
/**
};
/**
@@
-353,7
+362,7
@@
class Subprocess {
/**
* Child will be made a process group leader when it starts. Upside: one
/**
* Child will be made a process group leader when it starts. Upside: one
- * can reliably
all its kill
non-daemonizing descendants. Downside: the
+ * can reliably
kill all its
non-daemonizing descendants. Downside: the
* child will not receive Ctrl-C etc during interactive use.
*/
Options& processGroupLeader() {
* child will not receive Ctrl-C etc during interactive use.
*/
Options& processGroupLeader() {
@@
-813,9
+822,6
@@
class Subprocess {
std::vector<ChildPipe> takeOwnershipOfPipes();
private:
std::vector<ChildPipe> takeOwnershipOfPipes();
private:
- static const int RV_RUNNING = ProcessReturnCode::RV_RUNNING;
- static const int RV_NOT_STARTED = ProcessReturnCode::RV_NOT_STARTED;
-
// spawn() sets up a pipe to read errors from the child,
// then calls spawnInternal() to do the bulk of the work. Once
// spawnInternal() returns it reads the error pipe to see if the child
// spawn() sets up a pipe to read errors from the child,
// then calls spawnInternal() to do the bulk of the work. Once
// spawnInternal() returns it reads the error pipe to see if the child
@@
-851,7
+857,7
@@
class Subprocess {
size_t findByChildFd(const int childFd) const;
pid_t pid_{-1};
size_t findByChildFd(const int childFd) const;
pid_t pid_{-1};
- ProcessReturnCode returnCode_
{RV_NOT_STARTED}
;
+ ProcessReturnCode returnCode_;
/**
* Represents a pipe between this process, and the child process (or its
/**
* Represents a pipe between this process, and the child process (or its
@@
-882,4
+888,4
@@
class Subprocess {
std::vector<Pipe> pipes_;
};
std::vector<Pipe> pipes_;
};
-}
// namespace folly
+} // namespace folly