mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-08 01:24:49 +01:00
Io.Threaded.spawnPosix: implement passing file descriptors as stdio (#31379)
`std.process.spawn`: remove the TODO for nonblocking file stdio and document the behavior. Fix a bug in Io.Uring.dup2 where the function does not return on success Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31379 Reviewed-by: Andrew Kelley <andrew@ziglang.org> Co-authored-by: breakmit <breakmit@noreply.codeberg.org> Co-committed-by: breakmit <breakmit@noreply.codeberg.org>
This commit is contained in:
parent
30c8a75997
commit
46658257f4
4 changed files with 10 additions and 10 deletions
|
|
@ -4404,10 +4404,7 @@ fn setUpChildIo(
|
|||
.close => closeFd(std_fileno),
|
||||
.inherit => {},
|
||||
.ignore => try ev.dup2(dev_null_fd, std_fileno),
|
||||
.file => |file| {
|
||||
if (file.flags.nonblocking) @panic("TODO implement setUpChildIo when nonblocking file is used");
|
||||
try ev.dup2(file.handle, std_fileno);
|
||||
},
|
||||
.file => |file| try ev.dup2(file.handle, std_fileno),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15659,7 +15659,7 @@ fn setUpChildIo(stdio: process.SpawnOptions.StdIo, pipe_fd: i32, std_fileno: i32
|
|||
.close => closeFd(std_fileno),
|
||||
.inherit => {},
|
||||
.ignore => try dup2(dev_null_fd, std_fileno),
|
||||
.file => @panic("TODO implement setUpChildIo when file is used"),
|
||||
.file => |file| try dup2(file.handle, std_fileno),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4550,10 +4550,7 @@ fn setUpChildIo(
|
|||
.close => _ = linux.close(std_fileno),
|
||||
.inherit => {},
|
||||
.ignore => try dup2(sync, dev_null_fd, std_fileno),
|
||||
.file => |file| {
|
||||
if (file.flags.nonblocking) @panic("TODO implement setUpChildIo when nonblocking file is used");
|
||||
try dup2(sync, file.handle, std_fileno);
|
||||
},
|
||||
.file => |file| try dup2(sync, file.handle, std_fileno),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4565,7 +4562,7 @@ pub fn dup2(sync: *CancelRegion.Sync, old_fd: fd_t, new_fd: fd_t) DupError!void
|
|||
while (true) {
|
||||
try sync.cancel_region.await(.nothing);
|
||||
switch (linux.errno(linux.dup2(old_fd, new_fd))) {
|
||||
.SUCCESS => {},
|
||||
.SUCCESS => return,
|
||||
.BUSY, .INTR => {},
|
||||
.INVAL => |err| return errnoBug(err), // invalid parameters
|
||||
.BADF => |err| return errnoBug(err), // use after free
|
||||
|
|
|
|||
|
|
@ -409,6 +409,12 @@ pub const SpawnOptions = struct {
|
|||
/// Inherit the corresponding stream from the parent process.
|
||||
inherit,
|
||||
/// Pass an already open file from the parent to the child.
|
||||
///
|
||||
/// Nonblocking mode will be kept in the child process if present. This is
|
||||
/// likely not supported by the child process. For example:
|
||||
/// - Zig's std.Io.File.stdout() assumes blocking mode
|
||||
/// - Rust explicity documents that nonblocking stdio may cause panics
|
||||
/// - C++ standard streams do not support nonblocking file descriptors
|
||||
file: File,
|
||||
/// Pass a null stream to the child process by opening "/dev/null" on POSIX
|
||||
/// and "NUL" on Windows.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue