aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/processes.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-04-05 23:02:11 +0200
committereldritch horrors <pennae@lix.systems>2024-07-06 12:36:36 +0200
commit4162a66cee97ec16c88d991ef9a6d9baa3740053 (patch)
tree41bcdefb5d85c9c26be3563a3880bc850f41bec3 /src/libutil/processes.hh
parentb6a08a2fed8a48d3759ea67e958c9f9ec5f44d94 (diff)
libutil: return sources from runProgram2
this much more closely mimics what is actually happening: we're reading data from somewhere else, actively, rather than passively waiting. with the data flow matching the underlying system interactions better we can remove a few sinkToSource calls that merely exists to undo the mismatch caused by not treating subprocess output as a data source to begin with Change-Id: If4abfc2f8398fb5e88c9b91a8bdefd5504bb2d11
Diffstat (limited to 'src/libutil/processes.hh')
-rw-r--r--src/libutil/processes.hh9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/libutil/processes.hh b/src/libutil/processes.hh
index 90b2d20af..f61b9696d 100644
--- a/src/libutil/processes.hh
+++ b/src/libutil/processes.hh
@@ -3,6 +3,7 @@
#include "types.hh"
#include "error.hh"
+#include "file-descriptor.hh"
#include <sys/types.h>
#include <sys/stat.h>
@@ -82,7 +83,7 @@ struct RunOptions
std::optional<uid_t> gid;
std::optional<Path> chdir;
std::optional<std::map<std::string, std::string>> environment;
- Sink * standardOut = nullptr;
+ bool captureStdout = false;
bool mergeStderrToStdout = false;
bool isInteractive = false;
};
@@ -94,14 +95,18 @@ struct [[nodiscard("you must call RunningProgram::wait()")]] RunningProgram
private:
Path program;
Pid pid;
+ std::unique_ptr<Source> stdoutSource;
+ AutoCloseFD stdout_;
- RunningProgram(Path program, Pid pid) : program(std::move(program)), pid(std::move(pid)) {}
+ RunningProgram(PathView program, Pid pid, AutoCloseFD stdout);
public:
RunningProgram() = default;
~RunningProgram();
void wait();
+
+ Source * stdout() const { return stdoutSource.get(); }
};
std::pair<int, std::string> runProgram(RunOptions && options);