Add config tmp directory
This commit is contained in:
parent
ec465d2dc7
commit
411dcf5fda
|
@ -10,7 +10,7 @@
|
||||||
namespace cppshell {
|
namespace cppshell {
|
||||||
class Shell {
|
class Shell {
|
||||||
public:
|
public:
|
||||||
Shell(const std::string& shell = "bash");
|
Shell(const std::string& shell = "bash", const std::string& path_to_tmp_directory = "/tmp");
|
||||||
|
|
||||||
void Execute(const std::string& command);
|
void Execute(const std::string& command);
|
||||||
|
|
||||||
|
@ -21,11 +21,9 @@ class Shell {
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void ExecuteImpl(const std::string& command, bool need_ignore_sigpipe);
|
|
||||||
|
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
void MakeUniqueDirectory();
|
void MakeUniqueDirectory(const std::string& path_to_tmp_directory);
|
||||||
void MakeFifoFile();
|
void MakeFifoFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
namespace cppshell {
|
namespace cppshell {
|
||||||
Shell::Shell(const std::string& shell) {
|
Shell::Shell(const std::string& shell, const std::string& path_to_tmp_directory) {
|
||||||
MakeUniqueDirectory();
|
MakeUniqueDirectory(path_to_tmp_directory);
|
||||||
MakeFifoFile();
|
MakeFifoFile();
|
||||||
|
|
||||||
int fds_exit_codes[2];
|
int fds_exit_codes[2];
|
||||||
|
@ -41,8 +41,8 @@ Shell::Shell(const std::string& shell) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shell::MakeUniqueDirectory() {
|
void Shell::MakeUniqueDirectory(const std::string& path_to_tmp_directory) {
|
||||||
unique_directory_ = "/tmp/cppshell_XXXXXX";
|
unique_directory_ = path_to_tmp_directory + "/cppshell_XXXXXX";
|
||||||
if (mkdtemp(const_cast<char*>(unique_directory_.data())) == nullptr) {
|
if (mkdtemp(const_cast<char*>(unique_directory_.data())) == nullptr) {
|
||||||
throw std::logic_error("make unique directory failed");
|
throw std::logic_error("make unique directory failed");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue