authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-28 22:17:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-28 22:17:50-07:00
log29fd13009391060a2d6783fb0b91cb075c2e6cce
treeb2f2b9603c1ad67a6d59c6d38f52b962d1091bb8
parent5fed42d70a9ce23581bc8e1651a417161f269663

std.ChildProcess: bypass libc exit() in fork child error case

Comment reproduced here: If we're linking libc, some naughty applications may have registered atexit handlers which we really do not want to run in the fork child. I caught LLVM doing this and it caused a deadlock instead of doing an exit syscall. In the words of Avril Lavigne, "Why'd you have to go and make things so complicated?"

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

lib/std/child_process.zig+8-1
......@@ -485,7 +485,7 @@ pub const ChildProcess = struct {
485485 const any_ignore = (self.stdin_behavior == StdIo.Ignore or self.stdout_behavior == StdIo.Ignore or self.stderr_behavior == StdIo.Ignore);
486486
487487 const nul_handle = if (any_ignore)
488 // "\Device\Null" or "\??\NUL"
488 // "\Device\Null" or "\??\NUL"
489489 windows.OpenFile(&[_]u16{ '\\', 'D', 'e', 'v', 'i', 'c', 'e', '\\', 'N', 'u', 'l', 'l' }, .{
490490 .access_mask = windows.GENERIC_READ | windows.SYNCHRONIZE,
491491 .share_access = windows.FILE_SHARE_READ,
......@@ -816,6 +816,13 @@ fn destroyPipe(pipe: [2]os.fd_t) void {
816816// Then the child exits.
817817fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn {
818818 writeIntFd(fd, @as(ErrInt, @errorToInt(err))) catch {};
819 // If we're linking libc, some naughty applications may have registered atexit handlers
820 // which we really do not want to run in the fork child. I caught LLVM doing this and
821 // it caused a deadlock instead of doing an exit syscall. In the words of Avril Lavigne,
822 // "Why'd you have to go and make things so complicated?"
823 if (std.Target.current.os.tag == .linux) {
824 std.os.linux.exit(1); // By-pass libc regardless of whether it is linked.
825 }
819826 os.exit(1);
820827}
821828