| author | |
| committer | |
| log | 988ddd1bed003f2c2e7436d5f245a06cb8d024ce |
| tree | c49caa1fe8eba717b77bd491df56ff049629d12e |
| parent | e5894221f7a886c8b0cc21b8369e4d3bf11890b0 |
This issue with atexit() functions after forking isn't isolated to linux
I'm sure, the proper way to do this when linking libc is to use _exit(2)2 files changed, 4 insertions(+), 2 deletions(-)
lib/std/c.zig+1| ... | ... | @@ -81,6 +81,7 @@ pub extern "c" fn fread(ptr: [*]u8, size_of_type: usize, item_count: usize, stre |
| 81 | 81 | pub extern "c" fn printf(format: [*:0]const u8, ...) c_int; |
| 82 | 82 | pub extern "c" fn abort() noreturn; |
| 83 | 83 | pub extern "c" fn exit(code: c_int) noreturn; |
| 84 | pub extern "c" fn _exit(code: c_int) noreturn; | |
| 84 | 85 | pub extern "c" fn isatty(fd: fd_t) c_int; |
| 85 | 86 | pub extern "c" fn close(fd: fd_t) c_int; |
| 86 | 87 | pub extern "c" fn lseek(fd: fd_t, offset: off_t, whence: c_int) off_t; |
lib/std/child_process.zig+3-2| ... | ... | @@ -848,8 +848,9 @@ fn forkChildErrReport(fd: i32, err: ChildProcess.SpawnError) noreturn { |
| 848 | 848 | // which we really do not want to run in the fork child. I caught LLVM doing this and |
| 849 | 849 | // it caused a deadlock instead of doing an exit syscall. In the words of Avril Lavigne, |
| 850 | 850 | // "Why'd you have to go and make things so complicated?" |
| 851 | if (std.Target.current.os.tag == .linux) { | |
| 852 | std.os.linux.exit(1); // By-pass libc regardless of whether it is linked. | |
| 851 | if (builtin.link_libc) { | |
| 852 | // The _exit(2) function does nothing but make the exit syscall, unlike exit(3) | |
| 853 | std.c._exit(1); | |
| 853 | 854 | } |
| 854 | 855 | os.exit(1); |
| 855 | 856 | } |