authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-16 01:39:41-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-16 01:39:41-05:00
log2c7a2aefbfd0dbab190f912b4fbcbda96fb5ac44
tree0cf4434ee0f8be1e788669000c60e122adad1bf9
parent0f38410ea6f60ce9cebf373069d4abfcac0e77e6
signaturelock-open Commit is signed but in an unrecognized format.

Revert "Use eventfd in ChildProcess on Linux"

This reverts commit b169f7b0d51fa9e7cf570479079369b9736093ff. This caused `integer cast truncated bits` at std/child_process.zig:801:12 Can be reproduced on my machine simply by running `make`.

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

lib/std/child_process.zig+8-14
...@@ -280,7 +280,10 @@ pub const ChildProcess = struct {...@@ -280,7 +280,10 @@ 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 destroyPipe(self.err_pipe);283 defer {
284 os.close(self.err_pipe[0]);
285 os.close(self.err_pipe[1]);
286 }
284287
285 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after288 // Write maxInt(ErrInt) to the write end of the err_pipe. This is after
286 // waitpid, so this write is guaranteed to be after the child289 // waitpid, so this write is guaranteed to be after the child
...@@ -356,16 +359,7 @@ pub const ChildProcess = struct {...@@ -356,16 +359,7 @@ pub const ChildProcess = struct {
356359
357 // This pipe is used to communicate errors between the time of fork360 // This pipe is used to communicate errors between the time of fork
358 // and execve from the child process to the parent process.361 // and execve from the child process to the parent process.
359 const err_pipe = blk: {362 const err_pipe = try os.pipe();
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 };
369 errdefer destroyPipe(err_pipe);363 errdefer destroyPipe(err_pipe);
370364
371 const pid_result = try os.fork();365 const pid_result = try os.fork();
...@@ -779,7 +773,7 @@ fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const...@@ -779,7 +773,7 @@ fn windowsMakePipeOut(rd: *?windows.HANDLE, wr: *?windows.HANDLE, sattr: *const
779773
780fn destroyPipe(pipe: [2]os.fd_t) void {774fn destroyPipe(pipe: [2]os.fd_t) void {
781 os.close(pipe[0]);775 os.close(pipe[0]);
782 if (pipe[0] != pipe[1]) os.close(pipe[1]);776 os.close(pipe[1]);
783}777}
784778
785// Child of fork calls this to report an error to the fork parent.779// Child of fork calls this to report an error to the fork parent.
...@@ -793,12 +787,12 @@ const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);...@@ -793,12 +787,12 @@ const ErrInt = @IntType(false, @sizeOf(anyerror) * 8);
793787
794fn writeIntFd(fd: i32, value: ErrInt) !void {788fn writeIntFd(fd: i32, value: ErrInt) !void {
795 const stream = &File.openHandle(fd).outStream().stream;789 const stream = &File.openHandle(fd).outStream().stream;
796 stream.writeIntNative(u64, @intCast(u64, value)) catch return error.SystemResources;790 stream.writeIntNative(ErrInt, value) catch return error.SystemResources;
797}791}
798792
799fn readIntFd(fd: i32) !ErrInt {793fn readIntFd(fd: i32) !ErrInt {
800 const stream = &File.openHandle(fd).inStream().stream;794 const stream = &File.openHandle(fd).inStream().stream;
801 return @intCast(ErrInt, stream.readIntNative(u64) catch return error.SystemResources);795 return stream.readIntNative(ErrInt) catch return error.SystemResources;
802}796}
803797
804/// Caller must free result.798/// Caller must free result.