forked from lix-project/lix
Change builderOut from Pipe to AutoCloseFD
This commit is contained in:
parent
cb28e4fe2a
commit
6029c763c2
|
@ -292,7 +292,7 @@ void LocalDerivationGoal::closeReadPipes()
|
||||||
if (hook) {
|
if (hook) {
|
||||||
DerivationGoal::closeReadPipes();
|
DerivationGoal::closeReadPipes();
|
||||||
} else
|
} else
|
||||||
builderOut.readSide = -1;
|
builderOut.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -803,12 +803,12 @@ void LocalDerivationGoal::startBuilder()
|
||||||
Path logFile = openLogFile();
|
Path logFile = openLogFile();
|
||||||
|
|
||||||
/* Create a pseudoterminal to get the output of the builder. */
|
/* Create a pseudoterminal to get the output of the builder. */
|
||||||
builderOut.readSide = posix_openpt(O_RDWR | O_NOCTTY);
|
builderOut = posix_openpt(O_RDWR | O_NOCTTY);
|
||||||
if (!builderOut.readSide)
|
if (!builderOut)
|
||||||
throw SysError("opening pseudoterminal master");
|
throw SysError("opening pseudoterminal master");
|
||||||
|
|
||||||
// FIXME: not thread-safe, use ptsname_r
|
// FIXME: not thread-safe, use ptsname_r
|
||||||
slaveName = ptsname(builderOut.readSide.get());
|
slaveName = ptsname(builderOut.get());
|
||||||
|
|
||||||
if (buildUser) {
|
if (buildUser) {
|
||||||
if (chmod(slaveName.c_str(), 0600))
|
if (chmod(slaveName.c_str(), 0600))
|
||||||
|
@ -819,12 +819,12 @@ void LocalDerivationGoal::startBuilder()
|
||||||
}
|
}
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
else {
|
else {
|
||||||
if (grantpt(builderOut.readSide.get()))
|
if (grantpt(builderOut.get()))
|
||||||
throw SysError("granting access to pseudoterminal slave");
|
throw SysError("granting access to pseudoterminal slave");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (unlockpt(builderOut.readSide.get()))
|
if (unlockpt(builderOut.get()))
|
||||||
throw SysError("unlocking pseudoterminal");
|
throw SysError("unlocking pseudoterminal");
|
||||||
|
|
||||||
buildResult.startTime = time(0);
|
buildResult.startTime = time(0);
|
||||||
|
@ -980,15 +980,14 @@ void LocalDerivationGoal::startBuilder()
|
||||||
|
|
||||||
/* parent */
|
/* parent */
|
||||||
pid.setSeparatePG(true);
|
pid.setSeparatePG(true);
|
||||||
builderOut.writeSide = -1;
|
worker.childStarted(shared_from_this(), {builderOut.get()}, true, true);
|
||||||
worker.childStarted(shared_from_this(), {builderOut.readSide.get()}, true, true);
|
|
||||||
|
|
||||||
/* Check if setting up the build environment failed. */
|
/* Check if setting up the build environment failed. */
|
||||||
std::vector<std::string> msgs;
|
std::vector<std::string> msgs;
|
||||||
while (true) {
|
while (true) {
|
||||||
std::string msg = [&]() {
|
std::string msg = [&]() {
|
||||||
try {
|
try {
|
||||||
return readLine(builderOut.readSide.get());
|
return readLine(builderOut.get());
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
auto status = pid.wait();
|
auto status = pid.wait();
|
||||||
e.addTrace({}, "while waiting for the build environment for '%s' to initialize (%s, previous messages: %s)",
|
e.addTrace({}, "while waiting for the build environment for '%s' to initialize (%s, previous messages: %s)",
|
||||||
|
@ -1000,7 +999,7 @@ void LocalDerivationGoal::startBuilder()
|
||||||
}();
|
}();
|
||||||
if (msg.substr(0, 1) == "\2") break;
|
if (msg.substr(0, 1) == "\2") break;
|
||||||
if (msg.substr(0, 1) == "\1") {
|
if (msg.substr(0, 1) == "\1") {
|
||||||
FdSource source(builderOut.readSide.get());
|
FdSource source(builderOut.get());
|
||||||
auto ex = readError(source);
|
auto ex = readError(source);
|
||||||
ex.addTrace({}, "while setting up the build environment");
|
ex.addTrace({}, "while setting up the build environment");
|
||||||
throw ex;
|
throw ex;
|
||||||
|
@ -1631,21 +1630,21 @@ void LocalDerivationGoal::runChild()
|
||||||
try { /* child */
|
try { /* child */
|
||||||
|
|
||||||
/* Open the slave side of the pseudoterminal. */
|
/* Open the slave side of the pseudoterminal. */
|
||||||
builderOut.writeSide = open(slaveName.c_str(), O_RDWR | O_NOCTTY);
|
AutoCloseFD builderOut = open(slaveName.c_str(), O_RDWR | O_NOCTTY);
|
||||||
if (!builderOut.writeSide)
|
if (!builderOut)
|
||||||
throw SysError("opening pseudoterminal slave");
|
throw SysError("opening pseudoterminal slave");
|
||||||
|
|
||||||
// Put the pt into raw mode to prevent \n -> \r\n translation.
|
// Put the pt into raw mode to prevent \n -> \r\n translation.
|
||||||
struct termios term;
|
struct termios term;
|
||||||
if (tcgetattr(builderOut.writeSide.get(), &term))
|
if (tcgetattr(builderOut.get(), &term))
|
||||||
throw SysError("getting pseudoterminal attributes");
|
throw SysError("getting pseudoterminal attributes");
|
||||||
|
|
||||||
cfmakeraw(&term);
|
cfmakeraw(&term);
|
||||||
|
|
||||||
if (tcsetattr(builderOut.writeSide.get(), TCSANOW, &term))
|
if (tcsetattr(builderOut.get(), TCSANOW, &term))
|
||||||
throw SysError("putting pseudoterminal into raw mode");
|
throw SysError("putting pseudoterminal into raw mode");
|
||||||
|
|
||||||
commonChildInit(builderOut.writeSide.get());
|
commonChildInit(builderOut.get());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setupSeccomp();
|
setupSeccomp();
|
||||||
|
@ -2887,7 +2886,7 @@ void LocalDerivationGoal::deleteTmpDir(bool force)
|
||||||
bool LocalDerivationGoal::isReadDesc(int fd)
|
bool LocalDerivationGoal::isReadDesc(int fd)
|
||||||
{
|
{
|
||||||
return (hook && DerivationGoal::isReadDesc(fd)) ||
|
return (hook && DerivationGoal::isReadDesc(fd)) ||
|
||||||
(!hook && fd == builderOut.readSide.get());
|
(!hook && fd == builderOut.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,9 @@ struct LocalDerivationGoal : public DerivationGoal
|
||||||
/* The path of the temporary directory in the sandbox. */
|
/* The path of the temporary directory in the sandbox. */
|
||||||
Path tmpDirInSandbox;
|
Path tmpDirInSandbox;
|
||||||
|
|
||||||
/* Pipe for the builder's standard output/error. */
|
/* Master side of the pseudoterminal used for the builder's
|
||||||
Pipe builderOut;
|
standard output/error. */
|
||||||
|
AutoCloseFD builderOut;
|
||||||
|
|
||||||
/* Slave side of the pseudoterminal used for the builder's
|
/* Slave side of the pseudoterminal used for the builder's
|
||||||
standard output/error. */
|
standard output/error. */
|
||||||
|
|
Loading…
Reference in a new issue