Add config tmp directory

This commit is contained in:
Timofey Khoruzhii 2022-10-29 20:11:55 +03:00
parent ec465d2dc7
commit 411dcf5fda
2 changed files with 6 additions and 8 deletions

View file

@ -10,7 +10,7 @@
namespace cppshell {
class Shell {
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);
@ -21,11 +21,9 @@ class Shell {
}
private:
void ExecuteImpl(const std::string& command, bool need_ignore_sigpipe);
void Destroy();
void MakeUniqueDirectory();
void MakeUniqueDirectory(const std::string& path_to_tmp_directory);
void MakeFifoFile();
private:

View file

@ -15,8 +15,8 @@
#include <stdexcept>
namespace cppshell {
Shell::Shell(const std::string& shell) {
MakeUniqueDirectory();
Shell::Shell(const std::string& shell, const std::string& path_to_tmp_directory) {
MakeUniqueDirectory(path_to_tmp_directory);
MakeFifoFile();
int fds_exit_codes[2];
@ -41,8 +41,8 @@ Shell::Shell(const std::string& shell) {
}
}
void Shell::MakeUniqueDirectory() {
unique_directory_ = "/tmp/cppshell_XXXXXX";
void Shell::MakeUniqueDirectory(const std::string& path_to_tmp_directory) {
unique_directory_ = path_to_tmp_directory + "/cppshell_XXXXXX";
if (mkdtemp(const_cast<char*>(unique_directory_.data())) == nullptr) {
throw std::logic_error("make unique directory failed");
}