authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-12-16 10:56:53+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-12-16 10:56:53+01:00
logc257f892fdeda9c738d4a3afdf80a12775269884
treea57673939888845bd3eb1553da5d6a23342e0e7f
parent2c7a2aefbfd0dbab190f912b4fbcbda96fb5ac44

Revert "Revert "Use eventfd in ChildProcess on Linux""

This reverts commit 2c7a2aefbfd0dbab190f912b4fbcbda96fb5ac44.

1 files changed, 14 insertions(+), 8 deletions(-)

lib/std/child_process.zig+14-8
...@@ -280,10 +280,7 @@ pub const ChildProcess = struct {...@@ -280,10 +280,7 @@ pub const ChildProcess = struct {
280 }280 }
281281
282 fn cleanupAfterWait(self: *ChildProcess, status: u32) !Term {282 fn cleanupAfterWait(self: *ChildProcess, status: u32) !Term {
283 defer {283 defer destroyPipe(self.err_pipe);
284 os.close(self.err_pipe[0]);
285 os.close(self.err_pipe[1]);
286 }
287284
288 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after285 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after
289 // waitpid, so this write is guaranteed to be after the child286 // waitpid, so this write is guaranteed to be after the child
...@@ -359,7 +356,16 @@ pub const ChildProcess = struct {...@@ -359,7 +356,16 @@ pub const ChildProcess = struct {
359356
360 // This pipe is used to communicate errors between the time of fork357 // This pipe is used to communicate errors between the time of fork
361 // and execve from the child process to the parent process.358 // and execve from the child process to the parent process.
362 const err_pipe = try os.pipe();359 const err_pipe = blk: {
360 if (builtin.os == .linux) {
361 const fd = try os.eventfd(0, 0);
362 // There's no distinction between the readable and the writeable
363 // end with eventfd
364 break :blk [2]os.fd_t{ fd, fd };
365 } else {
366 break :blk try os.pipe();
367 }
368 };
363 errdefer destroyPipe(err_pipe);369 errdefer destroyPipe(err_pipe);
364370
365 const pid_result = try os.fork();371 const pid_result = try os.fork();
...@@ -773,7 +779,7 @@ fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const...@@ -773,7 +779,7 @@ fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const
773779
774fn destroyPipe(pipe: [2]os.fd_t) void {780fn destroyPipe(pipe: [2]os.fd_t) void {
775 os.close(pipe[0]);781 os.close(pipe[0]);
776 os.close(pipe[1]);782 if (pipe[0] != pipe[1]) os.close(pipe[1]);
777}783}
778784
779// Child of fork calls this to report an error to the fork parent.785// Child of fork calls this to report an error to the fork parent.
...@@ -787,12 +793,12 @@ const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);...@@ -787,12 +793,12 @@ const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);
787793
788fn writeIntFd(fd: i32, value: ErrInt) !void {794fn writeIntFd(fd: i32, value: ErrInt) !void {
789 const stream = &File.openHandle(fd).outStream().stream;795 const stream = &File.openHandle(fd).outStream().stream;
790 stream.writeIntNative(ErrInt, value) catch return error.SystemResources;796 stream.writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources;
791}797}
792798
793fn readIntFd(fd: i32) !ErrInt {799fn readIntFd(fd: i32) !ErrInt {
794 const stream = &File.openHandle(fd).inStream().stream;800 const stream = &File.openHandle(fd).inStream().stream;
795 return stream.readIntNative(ErrInt) catch return error.SystemResources;801 return @intCast(ErrInt, stream.readIntNative(u64) catch return error.SystemResources);
796}802}
797803
798/// Caller must free result.804/// Caller must free result.