diff options
author | eldritch horrors <pennae@lix.systems> | 2024-06-23 15:19:47 +0200 |
---|---|---|
committer | eldritch horrors <pennae@lix.systems> | 2024-06-23 17:29:40 +0000 |
commit | d477b34d1df3b471f8132525b0a008bbd03ddb6d (patch) | |
tree | dbf58b2cfd0f5ed0944ca62dcfc7cd73b34b5dee /src/libutil/processes.cc | |
parent | 2bbdaf0b19066ea1764e8d5810c2b250dbf0a850 (diff) |
libutil: remove runProgram2 stdin functionality
this was only used in one place, and that place has been rewritten to
use a temporary file instead. keeping this around is not very helpful
at this time, and in any case we'd be better off rewriting subprocess
handling in rust where we not only have a much safer library for such
things but also async frameworks necessary for this easily available.
Change-Id: I6f8641b756857c84ae2602cdf41f74ee7a1fda02
Diffstat (limited to 'src/libutil/processes.cc')
-rw-r--r-- | src/libutil/processes.cc | 55 |
1 files changed, 3 insertions, 52 deletions
diff --git a/src/libutil/processes.cc b/src/libutil/processes.cc index e8af12fbd..250092393 100644 --- a/src/libutil/processes.cc +++ b/src/libutil/processes.cc @@ -230,10 +230,9 @@ Pid startProcess(std::function<void()> fun, const ProcessOptions & options) return Pid{pid}; } -std::string runProgram(Path program, bool searchPath, const Strings & args, - const std::optional<std::string> & input, bool isInteractive) +std::string runProgram(Path program, bool searchPath, const Strings & args, bool isInteractive) { - auto res = runProgram(RunOptions {.program = program, .searchPath = searchPath, .args = args, .input = input, .isInteractive = isInteractive}); + auto res = runProgram(RunOptions {.program = program, .searchPath = searchPath, .args = args, .isInteractive = isInteractive}); if (!statusOk(res.first)) throw ExecError(res.first, "program '%1%' %2%", program, statusToString(res.first)); @@ -262,20 +261,9 @@ void runProgram2(const RunOptions & options) { checkInterrupt(); - assert(!(options.standardIn && options.input)); - - std::unique_ptr<Source> source_; - Source * source = options.standardIn; - - if (options.input) { - source_ = std::make_unique<StringSource>(*options.input); - source = source_.get(); - } - /* Create a pipe. */ - Pipe out, in; + Pipe out; if (options.standardOut) out.create(); - if (source) in.create(); ProcessOptions processOptions; @@ -298,8 +286,6 @@ void runProgram2(const RunOptions & options) if (options.mergeStderrToStdout) if (dup2(STDOUT_FILENO, STDERR_FILENO) == -1) throw SysError("cannot dup stdout into stderr"); - if (source && dup2(in.readSide.get(), STDIN_FILENO) == -1) - throw SysError("dupping stdin"); if (options.chdir && chdir((*options.chdir).c_str()) == -1) throw SysError("chdir failed"); @@ -328,47 +314,12 @@ void runProgram2(const RunOptions & options) out.writeSide.close(); - std::thread writerThread; - - std::promise<void> promise; - - Finally doJoin([&]() { - if (writerThread.joinable()) - writerThread.join(); - }); - - - if (source) { - in.readSide.close(); - writerThread = std::thread([&]() { - try { - std::vector<char> buf(8 * 1024); - while (true) { - size_t n; - try { - n = source->read(buf.data(), buf.size()); - } catch (EndOfFile &) { - break; - } - writeFull(in.writeSide.get(), {buf.data(), n}); - } - promise.set_value(); - } catch (...) { - promise.set_exception(std::current_exception()); - } - in.writeSide.close(); - }); - } - if (options.standardOut) drainFD(out.readSide.get(), *options.standardOut); /* Wait for the child to finish. */ int status = pid.wait(); - /* Wait for the writer thread to finish. */ - if (source) promise.get_future().get(); - if (status) throw ExecError(status, "program '%1%' %2%", options.program, statusToString(status)); } |