#include <string>
#include <boost/container/flat_map.hpp>
-#include <boost/operators.hpp>
#include <folly/Exception.h>
#include <folly/File.h>
* the close-on-exec flag is set (fcntl FD_CLOEXEC) and inherited
* otherwise.
*/
- class Options : private boost::orable<Options> {
+ class Options {
friend class Subprocess;
public:
Options() {} // E.g. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58328
}
#endif
- /**
- * Helpful way to combine Options.
- */
- Options& operator|=(const Options& other);
-
private:
typedef boost::container::flat_map<int, int> FdMap;
FdMap fdActions_;
std::vector<Pipe> pipes_;
};
-inline Subprocess::Options& Subprocess::Options::operator|=(
- const Subprocess::Options& other) {
- if (this == &other) return *this;
- // Replace
- for (auto& p : other.fdActions_) {
- fdActions_[p.first] = p.second;
- }
- closeOtherFds_ |= other.closeOtherFds_;
- usePath_ |= other.usePath_;
- processGroupLeader_ |= other.processGroupLeader_;
- return *this;
-}
-
} // namespace folly
});
// Normal execution with pipes
checkFdLeak([] {
- Subprocess proc("echo foo; echo bar >&2",
- Subprocess::pipeStdout() | Subprocess::pipeStderr());
+ Subprocess proc(
+ "echo foo; echo bar >&2",
+ Subprocess::Options().pipeStdout().pipeStderr());
auto p = proc.communicate();
EXPECT_EQ("foo\n", p.first);
EXPECT_EQ("bar\n", p.second);
data.append(line);
}
- Subprocess proc("wc -l", Subprocess::pipeStdin() | Subprocess::pipeStdout());
+ Subprocess proc("wc -l", Subprocess::Options().pipeStdin().pipeStdout());
auto p = proc.communicate(data);
EXPECT_EQ(folly::format("{}\n", numLines).str(), p.first);
proc.waitChecked();
const int bytes = 10 << 20;
std::string line(bytes, 'x');
- Subprocess proc("tr a-z A-Z",
- Subprocess::pipeStdin() | Subprocess::pipeStdout());
+ Subprocess proc("tr a-z A-Z", Subprocess::Options().pipeStdin().pipeStdout());
auto p = proc.communicate(line);
EXPECT_EQ(bytes, p.first.size());
EXPECT_EQ(std::string::npos, p.first.find_first_not_of('X'));
std::vector<Subprocess::ChildPipe> pipes;
{
Subprocess proc(
- "echo $'oh\\nmy\\ncat' | wc -l &", Subprocess::pipeStdout()
- );
+ "echo $'oh\\nmy\\ncat' | wc -l &", Subprocess::Options().pipeStdout());
pipes = proc.takeOwnershipOfPipes();
proc.waitChecked();
}