fix: subprocess should exit if stdout/err cannot be read

This commit is contained in:
CJ van den Berg 2024-04-08 17:59:58 +02:00
parent a7b3c3e1e8
commit 45d5c282bd

View file

@ -210,12 +210,14 @@ const Proc = struct {
if (self.child.stdin) |*fd| {
fd.close();
self.child.stdin = null;
tp.env.get().trace(tp.message.fmt(.{ self.tag, "stdin", "closed" }).to(tp.message.c_buffer_type));
}
}
fn dispatch_stdout(self: *Proc) tp.result {
var buffer: [max_chunk_size]u8 = undefined;
const bytes = self.child.stdout.?.read(&buffer) catch |e| switch (e) {
const stdout = self.child.stdout orelse return tp.exit("cannot read closed stdout");
const bytes = stdout.read(&buffer) catch |e| switch (e) {
error.WouldBlock => return,
else => return tp.exit_error(e),
};
@ -226,7 +228,8 @@ const Proc = struct {
fn dispatch_stderr(self: *Proc) tp.result {
var buffer: [max_chunk_size]u8 = undefined;
const bytes = self.child.stderr.?.read(&buffer) catch |e| switch (e) {
const stderr = self.child.stderr orelse return tp.exit("cannot read closed stderr");
const bytes = stderr.read(&buffer) catch |e| switch (e) {
error.WouldBlock => return,
else => return tp.exit_error(e),
};