Merge pull request #1189 from NixOS/fix-hang

openConnection(): Don't throw exceptions in forked child
This commit is contained in:
Graham Christensen 2022-03-30 17:16:02 -04:00 committed by GitHub
commit 84f54cb011
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -55,25 +55,11 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
to.create(); to.create();
from.create(); from.create();
child.pid = startProcess([&]() {
restoreProcessContext();
if (dup2(to.readSide.get(), STDIN_FILENO) == -1)
throw SysError("cannot dup input pipe to stdin");
if (dup2(from.writeSide.get(), STDOUT_FILENO) == -1)
throw SysError("cannot dup output pipe to stdout");
if (dup2(stderrFD, STDERR_FILENO) == -1)
throw SysError("cannot dup stderr");
Strings argv; Strings argv;
if (machine->isLocalhost()) { if (machine->isLocalhost()) {
pgmName = "nix-store"; pgmName = "nix-store";
argv = {"nix-store", "--builders", "", "--serve", "--write"}; argv = {"nix-store", "--builders", "", "--serve", "--write"};
} } else {
else {
pgmName = "ssh"; pgmName = "ssh";
auto sshName = machine->sshName; auto sshName = machine->sshName;
Strings extraArgs = extraStoreArgs(sshName); Strings extraArgs = extraStoreArgs(sshName);
@ -92,6 +78,18 @@ static void openConnection(Machine::ptr machine, Path tmpDir, int stderrFD, Chil
append(argv, extraArgs); append(argv, extraArgs);
} }
child.pid = startProcess([&]() {
restoreProcessContext();
if (dup2(to.readSide.get(), STDIN_FILENO) == -1)
throw SysError("cannot dup input pipe to stdin");
if (dup2(from.writeSide.get(), STDOUT_FILENO) == -1)
throw SysError("cannot dup output pipe to stdout");
if (dup2(stderrFD, STDERR_FILENO) == -1)
throw SysError("cannot dup stderr");
execvp(argv.front().c_str(), (char * *) stringsToCharPtrs(argv).data()); // FIXME: remove cast execvp(argv.front().c_str(), (char * *) stringsToCharPtrs(argv).data()); // FIXME: remove cast
throw SysError("cannot start %s", pgmName); throw SysError("cannot start %s", pgmName);