| ... | @@ -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 | } |
| 3123 | | 3123 | |
| 3124 | pub fn waitpid(pid: i32, flags: u32) u32 { | 3124 | pub const WaitPidResult = struct { |
| 3125 | // TODO allow implicit pointer cast from *u32 to *c_uint ? | 3125 | pid: pid_t, |
| | 3126 | status: u32, |
| | 3127 | }; |
| | 3128 | |
| | 3129 | pub 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 invalid | 3141 | 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 | } |
| 5436 | | 5444 | |
| 5437 | pub const SetrlimitError = error{ | 5445 | pub const SetrlimitError = error{PermissionDenied} || UnexpectedError; |
| 5438 | PermissionDenied, | | |
| 5439 | } || UnexpectedError; | | |
| 5440 | | 5446 | |
| 5441 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { | 5447 | pub fn setrlimit(resource: rlimit_resource, limits: rlimit) SetrlimitError!void { |
| 5442 | // TODO implement for systems other than linux and enable test | 5448 | // TODO implement for systems other than linux and enable test |