Use custom process library for notifications

Instead of using Boost.Process here. Last usage of Boost.Process is for
launching the child process.
This commit is contained in:
Robbert van der Helm
2022-04-11 14:55:22 +02:00
parent b80a30ba2a
commit a324042695
3 changed files with 48 additions and 22 deletions
+23 -1
View File
@@ -115,7 +115,7 @@ std::optional<int> Process::Handle::wait() const noexcept {
Process::Process(std::string command) : command_(command) {}
Process::StringResult Process::spawn_get_stdout_line() {
Process::StringResult Process::spawn_get_stdout_line() const {
/// We'll read the results from a pipe. The child writes to the second pipe,
/// we'll read from the first one.
int output_pipe[2];
@@ -167,6 +167,28 @@ Process::StringResult Process::spawn_get_stdout_line() {
}
}
Process::StatusResult Process::spawn_get_status() const {
const auto argv = build_argv();
const auto envp = env_ ? env_->make_environ() : environ;
pid_t child_pid = 0;
const auto result = posix_spawnp(&child_pid, command_.c_str(), nullptr,
nullptr, argv, envp);
if (result == 2) {
return Process::CommandNotFound{};
} else if (result != 0) {
return std::error_code(result, std::system_category());
}
int status = 0;
assert(waitpid(child_pid, &status, 0) > 0);
if (!WIFEXITED(status) || WEXITSTATUS(status) == 127) {
return Process::CommandNotFound{};
} else {
return WEXITSTATUS(status);
}
}
char* const* Process::build_argv() const {
argv_.clear();
+8 -1
View File
@@ -164,7 +164,14 @@ class Process {
* non-zero exit code. Uses `posix_spawn()`, leaves file descriptors in
* tact.
*/
StringResult spawn_get_stdout_line();
StringResult spawn_get_stdout_line() const;
/**
* Spawn the process, leave STDOUT, STDIN and STDERR alone, and return an
* empty string if the program ran successfully. Uses `posix_spawn()`,
* leaves file descriptors in tact.
*/
StatusResult spawn_get_status() const;
private:
/**