authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-03 18:26:49-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-04-03 18:26:49-04:00
log9dfd1a7c8a79cd5213878c56695f2fcb8aa25580
treea671912a3b6a33560d95073a2ed669c2be94000d
parentd1f8e722b5e48666b4d7d833c0cd6b36f45bd9bb

remove more signal handling stuff from std.os.ChildProcess

439621e44a68b436f958a84fcdb0bdac83613aea failed to remove everything. this finishes the job

1 files changed, 0 insertions(+), 35 deletions(-)

std/os/child_process.zig-35
...@@ -13,8 +13,6 @@ const builtin = @import("builtin");...@@ -13,8 +13,6 @@ const builtin = @import("builtin");
13const Os = builtin.Os;13const Os = builtin.Os;
14const LinkedList = std.LinkedList;14const LinkedList = std.LinkedList;
1515
16var children_nodes = LinkedList(&ChildProcess).init();
17
18const is_windows = builtin.os == Os.windows;16const is_windows = builtin.os == Os.windows;
1917
20pub const ChildProcess = struct {18pub const ChildProcess = struct {
...@@ -296,8 +294,6 @@ pub const ChildProcess = struct {...@@ -296,8 +294,6 @@ pub const ChildProcess = struct {
296 }294 }
297295
298 fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term {296 fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term {
299 children_nodes.remove(&self.llnode);
300
301 defer {297 defer {
302 os.close(self.err_pipe[0]);298 os.close(self.err_pipe[0]);
303 os.close(self.err_pipe[1]);299 os.close(self.err_pipe[1]);
...@@ -427,9 +423,6 @@ pub const ChildProcess = struct {...@@ -427,9 +423,6 @@ pub const ChildProcess = struct {
427 self.llnode = LinkedList(&ChildProcess).Node.init(self);423 self.llnode = LinkedList(&ChildProcess).Node.init(self);
428 self.term = null;424 self.term = null;
429425
430 // TODO make this atomic so it works even with threads
431 children_nodes.prepend(&self.llnode);
432
433 if (self.stdin_behavior == StdIo.Pipe) { os.close(stdin_pipe[0]); }426 if (self.stdin_behavior == StdIo.Pipe) { os.close(stdin_pipe[0]); }
434 if (self.stdout_behavior == StdIo.Pipe) { os.close(stdout_pipe[1]); }427 if (self.stdout_behavior == StdIo.Pipe) { os.close(stdout_pipe[1]); }
435 if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); }428 if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); }
...@@ -773,31 +766,3 @@ fn readIntFd(fd: i32) !ErrInt {...@@ -773,31 +766,3 @@ fn readIntFd(fd: i32) !ErrInt {
773 os.posixRead(fd, bytes[0..]) catch return error.SystemResources;766 os.posixRead(fd, bytes[0..]) catch return error.SystemResources;
774 return mem.readInt(bytes[0..], ErrInt, builtin.endian);767 return mem.readInt(bytes[0..], ErrInt, builtin.endian);
775}768}
776
777extern 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
795fn 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}