mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 13:36:02 +01:00
Change builderOut from Pipe to AutoCloseFD
(cherry picked from commit 6029c763c2)
This commit is contained in:
parent
6613e7ebfb
commit
94eba8a85a
1 changed files with 17 additions and 17 deletions
|
|
@ -824,8 +824,9 @@ private:
|
||||||
|
|
||||||
std::string currentHookLine;
|
std::string currentHookLine;
|
||||||
|
|
||||||
/* 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. */
|
||||||
|
|
@ -1606,7 +1607,7 @@ void DerivationGoal::buildDone()
|
||||||
hook->builderOut.readSide = -1;
|
hook->builderOut.readSide = -1;
|
||||||
hook->fromHook.readSide = -1;
|
hook->fromHook.readSide = -1;
|
||||||
} else
|
} else
|
||||||
builderOut.readSide = -1;
|
builderOut.close();
|
||||||
|
|
||||||
/* Close the log file. */
|
/* Close the log file. */
|
||||||
closeLogFile();
|
closeLogFile();
|
||||||
|
|
@ -2243,11 +2244,11 @@ void DerivationGoal::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");
|
||||||
|
|
||||||
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))
|
||||||
|
|
@ -2256,11 +2257,11 @@ void DerivationGoal::startBuilder()
|
||||||
if (chown(slaveName.c_str(), buildUser->getUID(), 0))
|
if (chown(slaveName.c_str(), buildUser->getUID(), 0))
|
||||||
throw SysError("changing owner of pseudoterminal slave");
|
throw SysError("changing owner of pseudoterminal slave");
|
||||||
} 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");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlockpt(builderOut.readSide.get()))
|
if (unlockpt(builderOut.get()))
|
||||||
throw SysError("unlocking pseudoterminal");
|
throw SysError("unlocking pseudoterminal");
|
||||||
|
|
||||||
result.startTime = time(0);
|
result.startTime = time(0);
|
||||||
|
|
@ -2415,12 +2416,11 @@ void DerivationGoal::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. */
|
||||||
while (true) {
|
while (true) {
|
||||||
string msg = readLine(builderOut.readSide.get());
|
string msg = readLine(builderOut.get());
|
||||||
if (string(msg, 0, 1) == "\1") {
|
if (string(msg, 0, 1) == "\1") {
|
||||||
if (msg.size() == 1) break;
|
if (msg.size() == 1) break;
|
||||||
throw Error(string(msg, 1));
|
throw Error(string(msg, 1));
|
||||||
|
|
@ -2724,21 +2724,21 @@ void DerivationGoal::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();
|
||||||
|
|
@ -3730,7 +3730,7 @@ void DerivationGoal::deleteTmpDir(bool force)
|
||||||
void DerivationGoal::handleChildOutput(int fd, const string & data)
|
void DerivationGoal::handleChildOutput(int fd, const string & data)
|
||||||
{
|
{
|
||||||
if ((hook && fd == hook->builderOut.readSide.get()) ||
|
if ((hook && fd == hook->builderOut.readSide.get()) ||
|
||||||
(!hook && fd == builderOut.readSide.get()))
|
(!hook && fd == builderOut.get()))
|
||||||
{
|
{
|
||||||
logSize += data.size();
|
logSize += data.size();
|
||||||
if (settings.maxLogSize && logSize > settings.maxLogSize) {
|
if (settings.maxLogSize && logSize > settings.maxLogSize) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue