commit
This commit is contained in:
commit
5659d5fdaf
5 changed files with 211 additions and 0 deletions
51
include/cppshell/shell.hpp
Normal file
51
include/cppshell/shell.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
#if !defined(__linux__)
|
||||
#error Only linux supported
|
||||
#endif
|
||||
|
||||
namespace cppshell {
|
||||
class Shell {
|
||||
public:
|
||||
Shell(const std::string& shell = "bash");
|
||||
|
||||
void Execute(const std::string& command) {
|
||||
#if defined(SIGPIPE_ALWAYS_IGNORE)
|
||||
ExecuteImpl(command, false);
|
||||
#else
|
||||
ExecuteImpl(command, true);
|
||||
#endif
|
||||
}
|
||||
|
||||
int GetExitCodeLastCommand();
|
||||
|
||||
~Shell() {
|
||||
#if defined(SIGPIPE_ALWAYS_IGNORE)
|
||||
Destroy(false);
|
||||
#else
|
||||
Destroy(true);
|
||||
#endif
|
||||
}
|
||||
|
||||
private:
|
||||
void ExecuteImpl(const std::string& command, bool need_ignore_sigpipe);
|
||||
|
||||
void Destroy(bool need_ignore_sigpipe);
|
||||
|
||||
void MakeUniqueDirectory();
|
||||
void MakeFifoFile();
|
||||
|
||||
private:
|
||||
std::string unique_directory_;
|
||||
std::string command_transmission_file_;
|
||||
|
||||
pid_t pid_shell_process_;
|
||||
int fd_exit_codes_transmission_;
|
||||
|
||||
std::ofstream command_transmission_;
|
||||
FILE* exit_codes_receiving_;
|
||||
};
|
||||
} // namespace cppshell
|
9
include/cppshell/utils/signals.hpp
Normal file
9
include/cppshell/utils/signals.hpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
struct SigpipeState {
|
||||
bool sigpipe_unblock = false;
|
||||
};
|
||||
|
||||
bool IgnoreSigpipe();
|
||||
void UnignoreSigpipe();
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue