Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.3-maintainence] Fix "unexpected EOF" errors on macOS #9495

Draft
wants to merge 1 commit into
base: 2.3-maintenance
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 27 additions & 25 deletions src/libstore/build.cc
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,10 @@ class DerivationGoal : public Goal
/* Pipe for the builder's standard output/error. */
Pipe builderOut;

/* Slave side of the pseudoterminal used for the builder's
standard output/error. */
Path slaveName;

/* Pipe for synchronising updates to the builder user namespace. */
Pipe userNamespaceSync;

Expand Down Expand Up @@ -2228,14 +2232,12 @@ void DerivationGoal::startBuilder()
/* Create the log file. */
Path logFile = openLogFile();

/* Create a pipe to get the output of the builder. */
//builderOut.create();

/* Create a pseudoterminal to get the output of the builder. */
builderOut.readSide = posix_openpt(O_RDWR | O_NOCTTY);
if (!builderOut.readSide)
throw SysError("opening pseudoterminal master");

std::string slaveName(ptsname(builderOut.readSide.get()));
slaveName = ptsname(builderOut.readSide.get());

if (buildUser) {
if (chmod(slaveName.c_str(), 0600))
Expand All @@ -2248,30 +2250,9 @@ void DerivationGoal::startBuilder()
throw SysError("granting access to pseudoterminal slave");
}

#if 0
// Mount the pt in the sandbox so that the "tty" command works.
// FIXME: this doesn't work with the new devpts in the sandbox.
if (useChroot)
dirsInChroot[slaveName] = {slaveName, false};
#endif

if (unlockpt(builderOut.readSide.get()))
throw SysError("unlocking pseudoterminal");

builderOut.writeSide = open(slaveName.c_str(), O_RDWR | O_NOCTTY);
if (!builderOut.writeSide)
throw SysError("opening pseudoterminal slave");

// Put the pt into raw mode to prevent \n -> \r\n translation.
struct termios term;
if (tcgetattr(builderOut.writeSide.get(), &term))
throw SysError("getting pseudoterminal attributes");

cfmakeraw(&term);

if (tcsetattr(builderOut.writeSide.get(), TCSANOW, &term))
throw SysError("putting pseudoterminal into raw mode");

result.startTime = time(0);

/* Fork a child to build the package. */
Expand Down Expand Up @@ -2320,7 +2301,11 @@ void DerivationGoal::startBuilder()

options.allowVfork = false;

Pipe sendPid;
sendPid.create();

Pid helper = startProcess([&]() {
sendPid.readSide.close();

/* Drop additional groups here because we can't do it
after we've created the new user namespace. FIXME:
Expand Down Expand Up @@ -2368,6 +2353,8 @@ void DerivationGoal::startBuilder()
_exit(0);
}, options);

sendPid.writeSide.close();

int res = helper.wait();
if (res != 0 && settings.sandboxFallback) {
useChroot = false;
Expand Down Expand Up @@ -2724,6 +2711,21 @@ void DerivationGoal::runChild()

try { /* child */

/* Open the slave side of the pseudoterminal. */
builderOut.writeSide = open(slaveName.c_str(), O_RDWR | O_NOCTTY);
if (!builderOut.writeSide)
throw SysError("opening pseudoterminal slave");

// Put the pt into raw mode to prevent \n -> \r\n translation.
struct termios term;
if (tcgetattr(builderOut.writeSide.get(), &term))
throw SysError("getting pseudoterminal attributes");

cfmakeraw(&term);

if (tcsetattr(builderOut.writeSide.get(), TCSANOW, &term))
throw SysError("putting pseudoterminal into raw mode");

commonChildInit(builderOut);

try {
Expand Down
Loading