| ... | ... | @@ -13,8 +13,6 @@ const builtin = @import("builtin"); |
| 13 | 13 | const Os = builtin.Os; |
| 14 | 14 | const LinkedList = std.LinkedList; |
| 15 | 15 | |
| 16 | | var children_nodes = LinkedList(&ChildProcess).init(); |
| 17 | | |
| 18 | 16 | const is_windows = builtin.os == Os.windows; |
| 19 | 17 | |
| 20 | 18 | pub const ChildProcess = struct { |
| ... | ... | @@ -296,8 +294,6 @@ pub const ChildProcess = struct { |
| 296 | 294 | } |
| 297 | 295 | |
| 298 | 296 | fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term { |
| 299 | | children_nodes.remove(&self.llnode); |
| 300 | | |
| 301 | 297 | defer { |
| 302 | 298 | os.close(self.err_pipe[0]); |
| 303 | 299 | os.close(self.err_pipe[1]); |
| ... | ... | @@ -427,9 +423,6 @@ pub const ChildProcess = struct { |
| 427 | 423 | self.llnode = LinkedList(&ChildProcess).Node.init(self); |
| 428 | 424 | self.term = null; |
| 429 | 425 | |
| 430 | | // TODO make this atomic so it works even with threads |
| 431 | | children_nodes.prepend(&self.llnode); |
| 432 | | |
| 433 | 426 | if (self.stdin_behavior == StdIo.Pipe) { os.close(stdin_pipe[0]); } |
| 434 | 427 | if (self.stdout_behavior == StdIo.Pipe) { os.close(stdout_pipe[1]); } |
| 435 | 428 | if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); } |
| ... | ... | @@ -773,31 +766,3 @@ fn readIntFd(fd: i32) !ErrInt { |
| 773 | 766 | os.posixRead(fd, bytes[0..]) catch return error.SystemResources; |
| 774 | 767 | return mem.readInt(bytes[0..], ErrInt, builtin.endian); |
| 775 | 768 | } |
| 776 | | |
| 777 | | extern fn sigchld_handler(_: i32) void { |
| 778 | | while (true) { |
| 779 | | var status: i32 = undefined; |
| 780 | | const pid_result = posix.waitpid(-1, &status, posix.WNOHANG); |
| 781 | | if (pid_result == 0) { |
| 782 | | return; |
| 783 | | } |
| 784 | | const err = posix.getErrno(pid_result); |
| 785 | | if (err > 0) { |
| 786 | | if (err == posix.ECHILD) { |
| 787 | | return; |
| 788 | | } |
| 789 | | unreachable; |
| 790 | | } |
| 791 | | handleTerm(i32(pid_result), status); |
| 792 | | } |
| 793 | | } |
| 794 | | |
| 795 | | fn handleTerm(pid: i32, status: i32) void { |
| 796 | | var it = children_nodes.first; |
| 797 | | while (it) |node| : (it = node.next) { |
| 798 | | if (node.data.pid == pid) { |
| 799 | | node.data.handleWaitResult(status); |
| 800 | | return; |
| 801 | | } |
| 802 | | } |
| 803 | | } |