Skip to content

Commit

Permalink
remove more signal handling stuff from std.os.ChildProcess
Browse files Browse the repository at this point in the history
439621e failed to remove
everything. this finishes the job
  • Loading branch information
andrewrk committed Apr 3, 2018
1 parent d1f8e72 commit 9dfd1a7
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions std/os/child_process.zig
Expand Up @@ -13,8 +13,6 @@ const builtin = @import("builtin");
const Os = builtin.Os;
const LinkedList = std.LinkedList;

var children_nodes = LinkedList(&ChildProcess).init();

const is_windows = builtin.os == Os.windows;

pub const ChildProcess = struct {
Expand Down Expand Up @@ -296,8 +294,6 @@ pub const ChildProcess = struct {
}

fn cleanupAfterWait(self: &ChildProcess, status: i32) !Term {
children_nodes.remove(&self.llnode);

defer {
os.close(self.err_pipe[0]);
os.close(self.err_pipe[1]);
Expand Down Expand Up @@ -427,9 +423,6 @@ pub const ChildProcess = struct {
self.llnode = LinkedList(&ChildProcess).Node.init(self);
self.term = null;

// TODO make this atomic so it works even with threads
children_nodes.prepend(&self.llnode);

if (self.stdin_behavior == StdIo.Pipe) { os.close(stdin_pipe[0]); }
if (self.stdout_behavior == StdIo.Pipe) { os.close(stdout_pipe[1]); }
if (self.stderr_behavior == StdIo.Pipe) { os.close(stderr_pipe[1]); }
Expand Down Expand Up @@ -773,31 +766,3 @@ fn readIntFd(fd: i32) !ErrInt {
os.posixRead(fd, bytes[0..]) catch return error.SystemResources;
return mem.readInt(bytes[0..], ErrInt, builtin.endian);
}

extern fn sigchld_handler(_: i32) void {
while (true) {
var status: i32 = undefined;
const pid_result = posix.waitpid(-1, &status, posix.WNOHANG);
if (pid_result == 0) {
return;
}
const err = posix.getErrno(pid_result);
if (err > 0) {
if (err == posix.ECHILD) {
return;
}
unreachable;
}
handleTerm(i32(pid_result), status);
}
}

fn handleTerm(pid: i32, status: i32) void {
var it = children_nodes.first;
while (it) |node| : (it = node.next) {
if (node.data.pid == pid) {
node.data.handleWaitResult(status);
return;
}
}
}

0 comments on commit 9dfd1a7

Please sign in to comment.