authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-25 12:39:57-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-11-25 14:18:55-08:00
logaa5341bf85e2aab566ae235c24f85ddaf09e8aee
treef253058036dfd894f1125fb66c1b41cbe06c3262
parentf4e042a4c3e8e299d273f00b757ec9fce840c3a6

std.process.Child: explicit error set for wait


1 files changed, 10 insertions(+), 13 deletions(-)

lib/std/process/Child.zig+10-13
...@@ -293,19 +293,16 @@ pub fn killPosix(self: *ChildProcess) !Term {...@@ -293,19 +293,16 @@ pub fn killPosix(self: *ChildProcess) !Term {
293 error.ProcessNotFound => return error.AlreadyTerminated,293 error.ProcessNotFound => return error.AlreadyTerminated,
294 else => return err,294 else => return err,
295 };295 };
296 try self.waitUnwrapped();296 self.waitUnwrapped();
297 return self.term.?;297 return self.term.?;
298}298}
299299
300/// Blocks until child process terminates and then cleans up all resources.300pub const WaitError = SpawnError || std.os.windows.GetProcessMemoryInfoError;
301pub fn wait(self: *ChildProcess) !Term {
302 const term = if (native_os == .windows)
303 try self.waitWindows()
304 else
305 try self.waitPosix();
306301
302/// Blocks until child process terminates and then cleans up all resources.
303pub fn wait(self: *ChildProcess) WaitError!Term {
304 const term = if (native_os == .windows) try self.waitWindows() else self.waitPosix();
307 self.id = undefined;305 self.id = undefined;
308
309 return term;306 return term;
310}307}
311308
...@@ -408,7 +405,7 @@ pub fn run(args: struct {...@@ -408,7 +405,7 @@ pub fn run(args: struct {
408 };405 };
409}406}
410407
411fn waitWindows(self: *ChildProcess) !Term {408fn waitWindows(self: *ChildProcess) WaitError!Term {
412 if (self.term) |term| {409 if (self.term) |term| {
413 self.cleanupStreams();410 self.cleanupStreams();
414 return term;411 return term;
...@@ -418,17 +415,17 @@ fn waitWindows(self: *ChildProcess) !Term {...@@ -418,17 +415,17 @@ fn waitWindows(self: *ChildProcess) !Term {
418 return self.term.?;415 return self.term.?;
419}416}
420417
421fn waitPosix(self: *ChildProcess) !Term {418fn waitPosix(self: *ChildProcess) SpawnError!Term {
422 if (self.term) |term| {419 if (self.term) |term| {
423 self.cleanupStreams();420 self.cleanupStreams();
424 return term;421 return term;
425 }422 }
426423
427 try self.waitUnwrapped();424 self.waitUnwrapped();
428 return self.term.?;425 return self.term.?;
429}426}
430427
431fn waitUnwrappedWindows(self: *ChildProcess) !void {428fn waitUnwrappedWindows(self: *ChildProcess) WaitError!void {
432 const result = windows.WaitForSingleObjectEx(self.id, windows.INFINITE, false);429 const result = windows.WaitForSingleObjectEx(self.id, windows.INFINITE, false);
433430
434 self.term = @as(SpawnError!Term, x: {431 self.term = @as(SpawnError!Term, x: {
...@@ -450,7 +447,7 @@ fn waitUnwrappedWindows(self: *ChildProcess) !void {...@@ -450,7 +447,7 @@ fn waitUnwrappedWindows(self: *ChildProcess) !void {
450 return result;447 return result;
451}448}
452449
453fn waitUnwrapped(self: *ChildProcess) !void {450fn waitUnwrapped(self: *ChildProcess) void {
454 const res: posix.WaitPidResult = res: {451 const res: posix.WaitPidResult = res: {
455 if (self.request_resource_usage_statistics) {452 if (self.request_resource_usage_statistics) {
456 switch (native_os) {453 switch (native_os) {