forked from lix-project/lix
Fix deadlock in runProgram() when input is larger than the pipe buffer size
This commit is contained in:
parent
e8186085e0
commit
fbbc4d8dda
|
@ -870,11 +870,14 @@ string runProgram(Path program, bool searchPath, const Strings & args,
|
||||||
|
|
||||||
out.writeSide = -1;
|
out.writeSide = -1;
|
||||||
|
|
||||||
/* FIXME: This can deadlock if the input is too long. */
|
std::thread writerThread;
|
||||||
|
|
||||||
if (!input.empty()) {
|
if (!input.empty()) {
|
||||||
in.readSide = -1;
|
in.readSide = -1;
|
||||||
|
writerThread = std::thread([&]() {
|
||||||
writeFull(in.writeSide.get(), input);
|
writeFull(in.writeSide.get(), input);
|
||||||
in.writeSide = -1;
|
in.writeSide = -1;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
string result = drainFD(out.readSide.get());
|
string result = drainFD(out.readSide.get());
|
||||||
|
@ -885,6 +888,9 @@ string runProgram(Path program, bool searchPath, const Strings & args,
|
||||||
throw ExecError(status, format("program ‘%1%’ %2%")
|
throw ExecError(status, format("program ‘%1%’ %2%")
|
||||||
% program % statusToString(status));
|
% program % statusToString(status));
|
||||||
|
|
||||||
|
if (!input.empty())
|
||||||
|
writerThread.join();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue