Skip to content

Commit 1aa0e2e

Browse files
committed
std.child_process: enable non-standard pipes
The user provides an array of struct with info for direction for the pipe. Each struct also contains the space for the input and output end of pipe, which simplifies handling. Typically a low number of non-standard pipes are used, so no premature optimization and complicating the usage. Also, it is expected that the upper bound of used pipes per process is comptime-known, so slicing a continuous chunk would be most efficient. * provide user with function pointer to enable parsing of necessary file descriptor on Linux and file handles on Windows in the child process - They can not be comptime-set, because the Kernel or user expects the program to work in all cases. * keep logic the same as for posix_spawn * use fcntl and SetHandleInformation to prevent file leakage into subsequently created children * test if both fcntl and HandleInformation were correctly set * test non-standard stream with 1 pipe type Note: Standard streams are expected to be inheritable by child processes, so those streams are "intentionally leaked to the child". Benchmarking with realistic workloads is needed to decide the final design. Especially, since storing space for one additionally unused pipe end can be wasteful. This is ziglang#11701 with conflicts fixed and will be used for the panic test runner.
1 parent 44ee1c8 commit 1aa0e2e

File tree

13 files changed

+469
-96
lines changed

13 files changed

+469
-96
lines changed

lib/std/build.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,8 +971,8 @@ pub const Builder = struct {
971971
child.cwd = cwd;
972972
child.env_map = env_map;
973973

974-
const term = child.spawnAndWait() catch |err| {
975-
log.err("Unable to spawn {s}: {s}", .{ argv[0], @errorName(err) });
974+
const term = child.spawnAndWait(null) catch |err| {
975+
log.err("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
976976
return err;
977977
};
978978

@@ -1187,7 +1187,7 @@ pub const Builder = struct {
11871187
child.stderr_behavior = stderr_behavior;
11881188
child.env_map = self.env_map;
11891189

1190-
try child.spawn();
1190+
try child.spawn(null);
11911191

11921192
const stdout = child.stdout.?.reader().readAllAlloc(self.allocator, max_output_size) catch {
11931193
return error.ReadFailure;

lib/std/build/RunStep.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ pub fn runCommand(
224224
if (print)
225225
printCmd(cwd, argv);
226226

227-
child.spawn() catch |err| {
227+
child.spawn(null) catch |err| {
228228
std.debug.print("Unable to spawn {s}: {s}\n", .{ argv[0], @errorName(err) });
229229
return err;
230230
};

0 commit comments

Comments
 (0)