aboutsummaryrefslogtreecommitdiff
path: root/lib/std/process/Child.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-12-05 19:08:37 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-12-23 22:15:07 -0800
commitaafddc2ea13e40a8262d9378aeca2e097a37ac03 (patch)
tree46770e51147a635a43c2e7356e62064466b51c34 /lib/std/process/Child.zig
parenteab354b2f5d7242c036523394023e9824be7eca9 (diff)
downloadzig-aafddc2ea13e40a8262d9378aeca2e097a37ac03.tar.gz
zig-aafddc2ea13e40a8262d9378aeca2e097a37ac03.zip
update all occurrences of close() to close(io)
Diffstat (limited to 'lib/std/process/Child.zig')
-rw-r--r--lib/std/process/Child.zig43
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/std/process/Child.zig b/lib/std/process/Child.zig
index 6dad72df44..be3026ff10 100644
--- a/lib/std/process/Child.zig
+++ b/lib/std/process/Child.zig
@@ -4,6 +4,7 @@ const builtin = @import("builtin");
const native_os = builtin.os.tag;
const std = @import("../std.zig");
+const Io = std.Io;
const unicode = std.unicode;
const fs = std.fs;
const process = std.process;
@@ -277,17 +278,17 @@ pub fn spawnAndWait(self: *ChildProcess) SpawnError!Term {
}
/// Forcibly terminates child process and then cleans up all resources.
-pub fn kill(self: *ChildProcess) !Term {
+pub fn kill(self: *ChildProcess, io: Io) !Term {
if (native_os == .windows) {
- return self.killWindows(1);
+ return self.killWindows(io, 1);
} else {
- return self.killPosix();
+ return self.killPosix(io);
}
}
-pub fn killWindows(self: *ChildProcess, exit_code: windows.UINT) !Term {
+pub fn killWindows(self: *ChildProcess, io: Io, exit_code: windows.UINT) !Term {
if (self.term) |term| {
- self.cleanupStreams();
+ self.cleanupStreams(io);
return term;
}
@@ -303,20 +304,20 @@ pub fn killWindows(self: *ChildProcess, exit_code: windows.UINT) !Term {
},
else => return err,
};
- try self.waitUnwrappedWindows();
+ try self.waitUnwrappedWindows(io);
return self.term.?;
}
-pub fn killPosix(self: *ChildProcess) !Term {
+pub fn killPosix(self: *ChildProcess, io: Io) !Term {
if (self.term) |term| {
- self.cleanupStreams();
+ self.cleanupStreams(io);
return term;
}
posix.kill(self.id, posix.SIG.TERM) catch |err| switch (err) {
error.ProcessNotFound => return error.AlreadyTerminated,
else => return err,
};
- self.waitUnwrappedPosix();
+ self.waitUnwrappedPosix(io);
return self.term.?;
}
@@ -354,15 +355,15 @@ pub fn waitForSpawn(self: *ChildProcess) SpawnError!void {
}
/// Blocks until child process terminates and then cleans up all resources.
-pub fn wait(self: *ChildProcess) WaitError!Term {
+pub fn wait(self: *ChildProcess, io: Io) WaitError!Term {
try self.waitForSpawn(); // report spawn errors
if (self.term) |term| {
- self.cleanupStreams();
+ self.cleanupStreams(io);
return term;
}
switch (native_os) {
- .windows => try self.waitUnwrappedWindows(),
- else => self.waitUnwrappedPosix(),
+ .windows => try self.waitUnwrappedWindows(io),
+ else => self.waitUnwrappedPosix(io),
}
self.id = undefined;
return self.term.?;
@@ -474,7 +475,7 @@ pub fn run(args: struct {
};
}
-fn waitUnwrappedWindows(self: *ChildProcess) WaitError!void {
+fn waitUnwrappedWindows(self: *ChildProcess, io: Io) WaitError!void {
const result = windows.WaitForSingleObjectEx(self.id, windows.INFINITE, false);
self.term = @as(SpawnError!Term, x: {
@@ -492,11 +493,11 @@ fn waitUnwrappedWindows(self: *ChildProcess) WaitError!void {
posix.close(self.id);
posix.close(self.thread_handle);
- self.cleanupStreams();
+ self.cleanupStreams(io);
return result;
}
-fn waitUnwrappedPosix(self: *ChildProcess) void {
+fn waitUnwrappedPosix(self: *ChildProcess, io: Io) void {
const res: posix.WaitPidResult = res: {
if (self.request_resource_usage_statistics) {
switch (native_os) {
@@ -527,7 +528,7 @@ fn waitUnwrappedPosix(self: *ChildProcess) void {
break :res posix.waitpid(self.id, 0);
};
const status = res.status;
- self.cleanupStreams();
+ self.cleanupStreams(io);
self.handleWaitResult(status);
}
@@ -535,17 +536,17 @@ fn handleWaitResult(self: *ChildProcess, status: u32) void {
self.term = statusToTerm(status);
}
-fn cleanupStreams(self: *ChildProcess) void {
+fn cleanupStreams(self: *ChildProcess, io: Io) void {
if (self.stdin) |*stdin| {
- stdin.close();
+ stdin.close(io);
self.stdin = null;
}
if (self.stdout) |*stdout| {
- stdout.close();
+ stdout.close(io);
self.stdout = null;
}
if (self.stderr) |*stderr| {
- stderr.close();
+ stderr.close(io);
self.stderr = null;
}
}