authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-22 11:36:42-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-04-22 11:36:42-04:00
loge0b635e825b72e1308dd0e2bbee578dafe62d9dc
treeaa9bc22da7198c04a8b3d2cf1dea5280a21bb1cd
parent0cce115476628ad1bb266309225efa5714d56321

std.os.ChildProcess: fix closing wrong file descriptors


2 files changed, 20 insertions(+), 19 deletions(-)

std/os/child_process.zig+2-3
...@@ -66,10 +66,9 @@ pub const ChildProcess = struct {...@@ -66,10 +66,9 @@ pub const ChildProcess = struct {
66 break;66 break;
67 }67 }
6868
69 // TODO oops!
70 test (self.stdin) |*stdin| { stdin.close(); }69 test (self.stdin) |*stdin| { stdin.close(); }
71 test (self.stdin) |*stdout| { stdout.close(); }70 test (self.stdout) |*stdout| { stdout.close(); }
72 test (self.stdin) |*stderr| { stderr.close(); }71 test (self.stderr) |*stderr| { stderr.close(); }
7372
74 // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after73 // Write @maxValue(ErrInt) to the write end of the err_pipe. This is after
75 // waitpid, so this write is guaranteed to be after the child74 // waitpid, so this write is guaranteed to be after the child
test/tests.zig+18-16
...@@ -195,6 +195,12 @@ pub const CompareOutputContext = struct {...@@ -195,6 +195,12 @@ pub const CompareOutputContext = struct {
195 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));195 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
196 };196 };
197197
198 var stdout = Buffer.initNull(b.allocator);
199 var stderr = Buffer.initNull(b.allocator);
200
201 %%(??child.stdout).readAll(&stdout);
202 %%(??child.stderr).readAll(&stderr);
203
198 const term = child.wait() %% |err| {204 const term = child.wait() %% |err| {
199 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));205 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
200 };206 };
...@@ -211,11 +217,6 @@ pub const CompareOutputContext = struct {...@@ -211,11 +217,6 @@ pub const CompareOutputContext = struct {
211 },217 },
212 };218 };
213219
214 var stdout = Buffer.initNull(b.allocator);
215 var stderr = Buffer.initNull(b.allocator);
216
217 %%(??child.stdout).readAll(&stdout);
218 %%(??child.stderr).readAll(&stderr);
219220
220 if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {221 if (!mem.eql(u8, self.expected_output, stdout.toSliceConst())) {
221 %%io.stderr.printf(222 %%io.stderr.printf(
...@@ -521,6 +522,12 @@ pub const CompileErrorContext = struct {...@@ -521,6 +522,12 @@ pub const CompileErrorContext = struct {
521 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));522 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
522 };523 };
523524
525 var stdout_buf = Buffer.initNull(b.allocator);
526 var stderr_buf = Buffer.initNull(b.allocator);
527
528 %%(??child.stdout).readAll(&stdout_buf);
529 %%(??child.stderr).readAll(&stderr_buf);
530
524 const term = child.wait() %% |err| {531 const term = child.wait() %% |err| {
525 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));532 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
526 };533 };
...@@ -537,11 +544,6 @@ pub const CompileErrorContext = struct {...@@ -537,11 +544,6 @@ pub const CompileErrorContext = struct {
537 },544 },
538 };545 };
539546
540 var stdout_buf = Buffer.initNull(b.allocator);
541 var stderr_buf = Buffer.initNull(b.allocator);
542
543 %%(??child.stdout).readAll(&stdout_buf);
544 %%(??child.stderr).readAll(&stderr_buf);
545547
546 const stdout = stdout_buf.toSliceConst();548 const stdout = stdout_buf.toSliceConst();
547 const stderr = stderr_buf.toSliceConst();549 const stderr = stderr_buf.toSliceConst();
...@@ -783,6 +785,12 @@ pub const ParseHContext = struct {...@@ -783,6 +785,12 @@ pub const ParseHContext = struct {
783 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));785 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
784 };786 };
785787
788 var stdout_buf = Buffer.initNull(b.allocator);
789 var stderr_buf = Buffer.initNull(b.allocator);
790
791 %%(??child.stdout).readAll(&stdout_buf);
792 %%(??child.stderr).readAll(&stderr_buf);
793
786 const term = child.wait() %% |err| {794 const term = child.wait() %% |err| {
787 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));795 debug.panic("Unable to spawn {}: {}\n", b.zig_exe, @errorName(err));
788 };796 };
...@@ -803,12 +811,6 @@ pub const ParseHContext = struct {...@@ -803,12 +811,6 @@ pub const ParseHContext = struct {
803 },811 },
804 };812 };
805813
806 var stdout_buf = Buffer.initNull(b.allocator);
807 var stderr_buf = Buffer.initNull(b.allocator);
808
809 %%(??child.stdout).readAll(&stdout_buf);
810 %%(??child.stderr).readAll(&stderr_buf);
811
812 const stdout = stdout_buf.toSliceConst();814 const stdout = stdout_buf.toSliceConst();
813 const stderr = stderr_buf.toSliceConst();815 const stderr = stderr_buf.toSliceConst();
814816