mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std.process.Child: fix spawning child proc with new cwd fd
Before this fix, the dup2 of the progress pipe was clobbering the cwd fd, causing the fchdir to return ENOTDIR in between fork() and exec().
This commit is contained in:
parent
b7889f262a
commit
947a3a1be9
1 changed files with 4 additions and 1 deletions
|
|
@ -654,7 +654,6 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
|
||||||
setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
if (prog_pipe[1] != -1) posix.dup2(prog_pipe[1], prog_fileno) catch |err| forkChildErrReport(err_pipe[1], err);
|
|
||||||
|
|
||||||
if (self.cwd_dir) |cwd| {
|
if (self.cwd_dir) |cwd| {
|
||||||
posix.fchdir(cwd.fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
posix.fchdir(cwd.fd) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
|
|
@ -662,6 +661,10 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
|
||||||
posix.chdir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
|
posix.chdir(cwd) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must happen after fchdir above, the cwd file descriptor might be
|
||||||
|
// equal to prog_fileno and be clobbered by this dup2 call.
|
||||||
|
if (prog_pipe[1] != -1) posix.dup2(prog_pipe[1], prog_fileno) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
|
|
||||||
if (self.gid) |gid| {
|
if (self.gid) |gid| {
|
||||||
posix.setregid(gid, gid) catch |err| forkChildErrReport(err_pipe[1], err);
|
posix.setregid(gid, gid) catch |err| forkChildErrReport(err_pipe[1], err);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue