std.os.ChildProcess: fix closing wrong file descriptors

master
Andrew Kelley 2017-04-22 11:36:42 -04:00
parent 0cce115476
commit e0b635e825
2 changed files with 20 additions and 19 deletions

View File

@ -66,10 +66,9 @@ pub const ChildProcess = struct {
break;
}
// TODO oops!
test (self.stdin) |*stdin| { stdin.close(); }
test (self.stdin) |*stdout| { stdout.close(); }
test (self.stdin) |*stderr| { stderr.close(); }
test (self.stdout) |*stdout| { stdout.close(); }
test (self.stderr) |*stderr| { stderr.close(); }
// Write @maxValue(ErrInt) to the write end of the err_pipe. This is after
// waitpid, so this write is guaranteed to be after the child

View File

@ -195,6 +195,12 @@ pub const CompareOutputContext = struct {
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
};
var stdout = Buffer.initNull(b.allocator);
var stderr = Buffer.initNull(b.allocator);
%%(??child.stdout).readAll(&stdout);
%%(??child.stderr).readAll(&stderr);
const term = child.wait() %% |err| {
debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
};
@ -211,11 +217,6 @@ pub const CompareOutputContext = struct {
},
};
var stdout = Buffer.initNull(b.allocator);
var stderr = Buffer.initNull(b.allocator);
%%(??child.stdout).readAll(&stdout);
%%(??child.stderr).readAll(&stderr);
if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
%%io.stderr.printf(
@ -521,6 +522,12 @@ pub const CompileErrorContext = struct {
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
};
var stdout_buf = Buffer.initNull(b.allocator);
var stderr_buf = Buffer.initNull(b.allocator);
%%(??child.stdout).readAll(&stdout_buf);
%%(??child.stderr).readAll(&stderr_buf);
const term = child.wait() %% |err| {
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
};
@ -537,11 +544,6 @@ pub const CompileErrorContext = struct {
},
};
var stdout_buf = Buffer.initNull(b.allocator);
var stderr_buf = Buffer.initNull(b.allocator);
%%(??child.stdout).readAll(&stdout_buf);
%%(??child.stderr).readAll(&stderr_buf);
const stdout = stdout_buf.toSliceConst();
const stderr = stderr_buf.toSliceConst();
@ -783,6 +785,12 @@ pub const ParseHContext = struct {
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
};
var stdout_buf = Buffer.initNull(b.allocator);
var stderr_buf = Buffer.initNull(b.allocator);
%%(??child.stdout).readAll(&stdout_buf);
%%(??child.stderr).readAll(&stderr_buf);
const term = child.wait() %% |err| {
debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
};
@ -803,12 +811,6 @@ pub const ParseHContext = struct {
},
};
var stdout_buf = Buffer.initNull(b.allocator);
var stderr_buf = Buffer.initNull(b.allocator);
%%(??child.stdout).readAll(&stdout_buf);
%%(??child.stderr).readAll(&stderr_buf);
const stdout = stdout_buf.toSliceConst();
const stderr = stderr_buf.toSliceConst();