2 #include <unordered_map>
7 #include "subprocess.h"
9 namespace linuxdeploy {
10 namespace subprocess {
16 // pipes to child process's stdout/stderr
22 // exit code -- will be initialized by close()
25 // these constants help make the pipe code more readable
26 static constexpr int READ_END_ = 0, WRITE_END_ = 1;
28 static std::vector<char*> make_args_vector_(const std::vector<std::string>& args);
30 static std::vector<char*> make_env_vector_(const subprocess_env_map_t& env);
32 static int check_waitpid_status_(int status);
34 static void close_pipe_fd_(int fd);
38 * Create a child process.
39 * @param args parameters for process
40 * @param env additional environment variables (current environment will be copied)
42 process(std::initializer_list<std::string> args, const subprocess_env_map_t& env);
45 * Create a child process.
46 * @param args parameters for process
47 * @param env additional environment variables (current environment will be copied)
49 process(const std::vector<std::string>& args, const subprocess_env_map_t& env);
54 * @return child process's ID
59 * @return child process's stdout file descriptor ID
61 int stdout_fd() const;
65 * @return child process's stderr file descriptor ID
67 int stderr_fd() const;
70 * Close all pipes and wait for process to exit.
71 * If process is not running any more, just returns exit code.
72 * @return child process's exit code
77 * Kill underlying process with given signal. By default, SIGTERM is used to end the process.
79 void kill(int signal = SIGTERM) const;
82 * Check whether process is still alive. Use close() to fetch exit code.
83 * @return true while process is alive, false otherwise