diff options
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)); } |