From b6a08a2fed8a48d3759ea67e958c9f9ec5f44d94 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Fri, 5 Apr 2024 22:22:44 +0200 Subject: libutil: return a program handle from runProgram2 this will let us also return a source for the program output later, which will in turn make sinkToSource unnecessary for program output processing. this may also reopen a path for provigin program input, but that still needs a proper async io framework to avoid problems. Change-Id: Iaf93f47db99c38cfaf134bd60ed6a804d7ddf688 --- src/libutil/processes.hh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/libutil/processes.hh') diff --git a/src/libutil/processes.hh b/src/libutil/processes.hh index 48a195481..90b2d20af 100644 --- a/src/libutil/processes.hh +++ b/src/libutil/processes.hh @@ -87,9 +87,26 @@ struct RunOptions bool isInteractive = false; }; +struct [[nodiscard("you must call RunningProgram::wait()")]] RunningProgram +{ + friend RunningProgram runProgram2(const RunOptions & options); + +private: + Path program; + Pid pid; + + RunningProgram(Path program, Pid pid) : program(std::move(program)), pid(std::move(pid)) {} + +public: + RunningProgram() = default; + ~RunningProgram(); + + void wait(); +}; + std::pair runProgram(RunOptions && options); -void runProgram2(const RunOptions & options); +RunningProgram runProgram2(const RunOptions & options); class ExecError : public Error { -- cgit v1.2.3