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 {...@@ -269,7 +269,7 @@ pub const ChildProcess = struct {
269 }269 }
270270
271 fn waitUnwrapped(self: *ChildProcess) void {271 fn waitUnwrapped(self: *ChildProcess) void {
272 const status = os.waitpid(self.pid, 0);272 const status = os.waitpid(self.pid, 0).status;
273 self.cleanupStreams();273 self.cleanupStreams();
274 self.handleWaitResult(status);274 self.handleWaitResult(status);
275 }275 }
lib/std/os.zig+14-8
...@@ -3121,16 +3121,24 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {...@@ -3121,16 +3121,24 @@ pub fn getsockoptError(sockfd: fd_t) ConnectError!void {
3121 }3121 }
3122}3122}
31233123
3124pub fn waitpid(pid: i32, flags: u32) u32 {3124pub const WaitPidResult = struct {
3125 // TODO allow implicit pointer cast from *u32 to *c_uint ?3125 pid: pid_t,
3126 status: u32,
3127};
3128
3129pub fn waitpid(pid: pid_t, flags: u32) WaitPidResult {
3126 const Status = if (builtin.link_libc) c_uint else u32;3130 const Status = if (builtin.link_libc) c_uint else u32;
3127 var status: Status = undefined;3131 var status: Status = undefined;
3128 while (true) {3132 while (true) {
3129 switch (errno(system.waitpid(pid, &status, flags))) {3133 const rc = system.waitpid(pid, &status, flags);
3130 0 => return @bitCast(u32, status),3134 switch (errno(rc)) {
3135 0 => return .{
3136 .pid = @intCast(pid_t, rc),
3137 .status = @bitCast(u32, status),
3138 },
3131 EINTR => continue,3139 EINTR => continue,
3132 ECHILD => unreachable, // The process specified does not exist. It would be a race condition to handle this error.3140 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 invalid3141 EINVAL => unreachable, // Invalid flags.
3134 else => unreachable,3142 else => unreachable,
3135 }3143 }
3136 }3144 }
...@@ -5434,9 +5442,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {...@@ -5434,9 +5442,7 @@ pub fn getrlimit(resource: rlimit_resource) GetrlimitError!rlimit {
5434 }5442 }
5435}5443}
54365444
5437pub const SetrlimitError = error{5445pub const SetrlimitError = error{PermissionDenied} || UnexpectedError;
5438 PermissionDenied,
5439} || UnexpectedError;
54405446
5441pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {5447pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void {
5442 // TODO implement for systems other than linux and enable test5448 // TODO implement for systems other than linux and enable test