audit: handle process.Child.Term exhaustively and give useful exit information

This commit is contained in:
murtaza
2026-01-27 16:36:08 +01:00
parent a38c6bbcc4
commit 07b49c61ff
11 changed files with 111 additions and 42 deletions
+5 -1
View File
@@ -291,7 +291,11 @@ fn termToInteresting(term: std.process.Child.Term) Interestingness {
std.debug.print("interestingness check terminated with signal {t}\n", .{sig});
return .boring;
},
else => {
.stopped => |sig| {
std.debug.print("interestingness check stopped with signal {d}\n", .{sig});
return .boring;
},
.unknown => {
std.debug.print("interestingness check aborted unexpectedly\n", .{});
return .boring;
},
+8 -1
View File
@@ -423,7 +423,14 @@ fn buildWasmBinary(
);
return error.WasmCompilationFailed;
},
.stopped, .unknown => {
.stopped => |sig| {
std.log.err(
"the following command stopped unexpectedly with signal {d}:\n{s}",
.{ sig, try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) },
);
return error.WasmCompilationFailed;
},
.unknown => {
std.log.err(
"the following command terminated unexpectedly:\n{s}",
.{try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)},
+6 -13
View File
@@ -725,19 +725,12 @@ pub inline fn handleChildProcUnsupported(s: *Step) error{ OutOfMemory, MakeFaile
/// Asserts that the caller has already populated `s.result_failed_command`.
pub fn handleChildProcessTerm(s: *Step, term: std.process.Child.Term) error{ MakeFailed, OutOfMemory }!void {
assert(s.result_failed_command != null);
switch (term) {
.exited => |code| {
if (code != 0) {
return s.fail("process exited with error code {d}", .{code});
}
},
.signal => |sig| {
return s.fail("process terminated with signal {t}", .{sig});
},
.stopped, .unknown => {
return s.fail("process terminated unexpectedly", .{});
},
}
return switch (term) {
.exited => |code| if (code != 0) s.fail("process exited with error code {d}", .{code}),
.signal => |sig| s.fail("process terminated with signal {t}", .{sig}),
.stopped => |sig| s.fail("process stopped with signal {d}", .{sig}),
.unknown => s.fail("process terminated unexpectedly", .{}),
};
}
pub fn allocPrintCmd(
+8 -1
View File
@@ -681,7 +681,14 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
);
return error.WasmCompilationFailed;
},
.stopped, .unknown => {
.stopped => |sig| {
log.err(
"the following command stopped unexpectedly with signal {d}:\n{s}",
.{ sig, try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) },
);
return error.WasmCompilationFailed;
},
.unknown => {
log.err(
"the following command terminated unexpectedly:\n{s}",
.{try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)},
+18 -4
View File
@@ -1185,11 +1185,25 @@ fn detectAndroidApiLevel(io: Io) !u32 {
return error.ApiLevelQueryFailed;
};
const term = try child.wait(io);
if (term != .exited or term.exited != 0) {
std.log.err("getprop terminated abnormally: {}", .{term});
return error.ApiLevelQueryFailed;
switch (try child.wait(io)) {
.exited => |code| if (code != 0) {
std.log.err("getprop terminated abnormally with exit code: {d}", .{code});
return error.ApiLevelQueryFailed;
},
.signal => |sig| {
std.log.err("getprop terminated abnormally with signal: {t}", .{sig});
return error.ApiLevelQueryFailed;
},
.stopped => |sig| {
std.log.err("getprop stopped abnormally with signal: {d}", .{sig});
return error.ApiLevelQueryFailed;
},
.unknown => {
std.log.err("getprop terminated abnormally", .{});
return error.ApiLevelQueryFailed;
},
}
return api_level;
}
+10 -2
View File
@@ -5870,7 +5870,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
log.err("clang failed with stderr: {s}", .{stderr});
return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig});
},
else => {
.stopped => |sig| {
log.err("clang failed with stderr: {s}", .{stderr});
return comp.failCObj(c_object, "clang stopped with signal {d}", .{sig});
},
.unknown => {
log.err("clang terminated with stderr: {s}", .{stderr});
return comp.failCObj(c_object, "clang terminated unexpectedly", .{});
},
@@ -6297,7 +6301,11 @@ fn spawnZigRc(
log.err("zig rc signaled {t} with stderr:\n{s}", .{ sig, stderr });
return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
},
else => {
.stopped => |sig| {
log.err("zig rc stopped {d} with stderr:\n{s}", .{ sig, stderr });
return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
},
.unknown => {
log.err("zig rc terminated with stderr:\n{s}", .{stderr});
return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
},
+15 -3
View File
@@ -4580,7 +4580,11 @@ fn runOrTest(
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command terminated with signal {t}:\n{s}", .{ sig, cmd });
},
else => {
.stopped => |sig| {
const cmd = try std.mem.join(arena, " ", argv.items);
fatal("the following command stopped with signal {d}:\n{s}", .{ sig, cmd });
},
.unknown => {
process.exit(1);
},
}
@@ -5631,7 +5635,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });
},
else => {
.stopped => |sig| {
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command stopped with signal {d}:\n{s}", .{ sig, cmd });
},
.unknown => {
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command crashed:\n{s}", .{cmd});
},
@@ -5933,7 +5941,11 @@ fn jitCmdInner(
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });
},
else => {
.stopped => |sig| {
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command stopped with signal {d}:\n{s}", .{ sig, cmd });
},
.unknown => {
const cmd = try std.mem.join(arena, " ", child_argv.items);
fatal("the following build command crashed:\n{s}", .{cmd});
},
+6 -1
View File
@@ -1141,7 +1141,12 @@ fn run(
dumpArgs(args);
return error.ChildCrashed;
},
else => {
.stopped => |sig| {
std.debug.print("{s}\nThe following command stopped with signal {d}:\n", .{ result.stderr, sig });
dumpArgs(args);
return error.ChildCrashed;
},
.unknown => {
std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr});
dumpArgs(args);
return error.ChildCrashed;
+16 -14
View File
@@ -568,7 +568,10 @@ const Eval = struct {
.signal => |sig| {
eval.fatal("generated executable '{s}' terminated with signal {t}", .{ binary_path, sig });
},
.stopped, .unknown => {
.stopped => |sig| {
eval.fatal("generated executable '{s}' stopped with signal {d}", .{ binary_path, sig });
},
.unknown => {
eval.fatal("generated executable '{s}' terminated unexpectedly", .{binary_path});
},
}
@@ -627,19 +630,17 @@ const Eval = struct {
}) catch |err| {
eval.fatal("failed to spawn zig cc for '{s}': {t}", .{ c_path, err });
};
if (result.term == .exited and result.term.exited == 0) return;
if (result.stderr.len != 0) {
std.log.err("zig cc stderr:\n{s}", .{result.stderr});
}
switch (result.term) {
.exited => |code| if (code != 0) {
if (result.stderr.len != 0) {
std.log.err("zig cc stderr:\n{s}", .{result.stderr});
}
eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code });
},
.signal, .stopped, .unknown => {
if (result.stderr.len != 0) {
std.log.err("zig cc stderr:\n{s}", .{result.stderr});
}
eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path});
},
.exited => |code| eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code }),
.signal => |sig| eval.fatal("zig cc for '{s}' terminated unexpectedly with signal {t}", .{ c_path, sig }),
.stopped => |sig| eval.fatal("zig cc for '{s}' stopped unexpectedly with signal {d}", .{ c_path, sig }),
.unknown => eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path}),
}
}
@@ -918,7 +919,8 @@ fn waitChild(child: *std.process.Child, eval: *Eval) void {
switch (term) {
.exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),
.signal => |sig| eval.fatal("compiler terminated with signal {t}", .{sig}),
.stopped, .unknown => eval.fatal("compiler terminated unexpectedly", .{}),
.stopped => |sig| eval.fatal("compiler stopped unexpectedly with signal {d}", .{sig}),
.unknown => eval.fatal("compiler terminated unexpectedly", .{}),
}
}
+10 -1
View File
@@ -688,7 +688,16 @@ pub fn main(init: std.process.Init) !void {
const json_text = switch (child_result.term) {
.exited => |code| if (code == 0) child_result.stdout else {
fatal("llvm-tblgen exited with code {d}", .{code});
fatal("llvm-tblgen exited with code {d}\n", .{code});
},
.signal => |sig| {
fatal("llvm-tblgen terminated with signal {t}\n", .{sig});
},
.stopped => |sig| {
fatal("llvm-tblgen stopped with signal {d}\n", .{sig});
},
.unknown => {
fatal("llvm-tblgen crashed\n", .{});
},
else => fatal("llvm-tblgen crashed", .{}),
};
+9 -1
View File
@@ -2012,7 +2012,15 @@ fn processOneTarget(io: Io, job: Job) void {
std.debug.print("llvm-tblgen exited with code {d}\n", .{code});
std.process.exit(1);
},
else => {
.signal => |sig| {
std.debug.print("llvm-tblgen terminated with signal {t}\n", .{sig});
std.process.exit(1);
},
.stopped => |sig| {
std.debug.print("llvm-tblgen stopped with signal {d}\n", .{sig});
std.process.exit(1);
},
.unknown => {
std.debug.print("llvm-tblgen crashed\n", .{});
std.process.exit(1);
},