authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-16 18:15:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-16 18:15:31-07:00
log2aff27d92247eed3b64ffc68da8fae9e5994ea0b
treef8287a9f1e07269c5ebd2d3e0a86483c23270e25
parent0e4c3934a02cda80a72a730593ece41c7fa8026a
parent5c16022c81effc2d684aaf21217dce0f7708946a

Merge branch '6604'

closes #6604

2 files changed, 15 insertions(+), 9 deletions(-)

lib/std/child_process.zig+1-1
......@@ -269,7 +269,7 @@ pub const ChildProcess = struct {
269269 }
270270
271271 fn waitUnwrapped(self: *ChildProcess) void {
272 const status = os.waitpid(self.pid, 0);
272 const status = os.waitpid(self.pid, 0).status;
273273 self.cleanupStreams();
274274 self.handleWaitResult(status);
275275 }
lib/std/os.zig+14-8
......@@ -3121,16 +3121,24 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
31213121 }
31223122}
31233123
3124pub fn waitpid(pid: i32, flags: u32) u32 {
3125 // TODO allow implicit pointer cast from *u32 to *c_uint ?
3124pub const WaitPidResult = struct {
3125 pid: pid_t,
3126 status: u32,
3127};
3128
3129pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
31263130 const Status = if (builtin.link_libc) c_uint else u32;
31273131 var status: Status = undefined;
31283132 while (true) {
3129 switch (errno(system.waitpid(pid, &status, flags))) {
3130 0 => return @bitCast(u32, status),
3133 const rc = system.waitpid(pid, &status, flags);
3134 switch (errno(rc)) {
3135 0 => return .{
3136 .pid = @intCast(pid_t, rc),
3137 .status = @bitCast(u32, status),
3138 },
31313139 EINTR => continue,
31323140 ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.
3133 EINVAL => unreachable, // The options argument was invalid
3141 EINVAL => unreachable, // Invalid flags.
31343142 else => unreachable,
31353143 }
31363144 }
......@@ -5434,9 +5442,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
54345442 }
54355443}
54365444
5437pub const SetrlimitError = error{
5438 PermissionDenied,
5439} || UnexpectedError;
5445pub const SetrlimitError = error{PermissionDenied} || UnexpectedError;
54405446
54415447pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
54425448 // TODO implement for systems other than linux and enable test