authorgravatar for sayedmurtazamuttahary@gmail.commurtaza <sayedmurtazamuttahary@gmail.com> 2026-01-27 16:36:08+01:00
committergravatar for sayedmurtazamuttahary@gmail.commurtaza <sayedmurtazamuttahary@gmail.com> 2026-04-07 10:27:01+02:00
log07b49c61ff8e84751d8a51e9b4d3bd2ffb7797de
treeae79adb89ba1bcfbcf619a771d664b3808489fee
parenta38c6bbcc4542dbae607536cdd9fde139c19863f

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


11 files changed, 111 insertions(+), 42 deletions(-)

lib/compiler/reduce.zig+5-1
......@@ -291,7 +291,11 @@ fn termToInteresting(term: std.process.Child.Term) Interestingness {
291291 std.debug.print("interestingness check terminated with signal {t}\n", .{sig});
292292 return .boring;
293293 },
294 else => {
294 .stopped => |sig| {
295 std.debug.print("interestingness check stopped with signal {d}\n", .{sig});
296 return .boring;
297 },
298 .unknown => {
295299 std.debug.print("interestingness check aborted unexpectedly\n", .{});
296300 return .boring;
297301 },
lib/compiler/std-docs.zig+8-1
......@@ -423,7 +423,14 @@ fn buildWasmBinary(
423423 );
424424 return error.WasmCompilationFailed;
425425 },
426 .stopped, .unknown => {
426 .stopped => |sig| {
427 std.log.err(
428 "the following command stopped unexpectedly with signal {d}:\n{s}",
429 .{ sig, try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) },
430 );
431 return error.WasmCompilationFailed;
432 },
433 .unknown => {
427434 std.log.err(
428435 "the following command terminated unexpectedly:\n{s}",
429436 .{try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)},
lib/std/Build/Step.zig+6-13
......@@ -725,19 +725,12 @@ pub inline fn handleChildProcUnsupported(s: *Step) error{ OutOfMemory, MakeFaile
725725/// Asserts that the caller has already populated `s.result_failed_command`.
726726pub fn handleChildProcessTerm(s: *Step, term: std.process.Child.Term) error{ MakeFailed, OutOfMemory }!void {
727727 assert(s.result_failed_command != null);
728 switch (term) {
729 .exited => |code| {
730 if (code != 0) {
731 return s.fail("process exited with error code {d}", .{code});
732 }
733 },
734 .signal => |sig| {
735 return s.fail("process terminated with signal {t}", .{sig});
736 },
737 .stopped, .unknown => {
738 return s.fail("process terminated unexpectedly", .{});
739 },
740 }
728 return switch (term) {
729 .exited => |code| if (code != 0) s.fail("process exited with error code {d}", .{code}),
730 .signal => |sig| s.fail("process terminated with signal {t}", .{sig}),
731 .stopped => |sig| s.fail("process stopped with signal {d}", .{sig}),
732 .unknown => s.fail("process terminated unexpectedly", .{}),
733 };
741734}
742735
743736pub fn allocPrintCmd(
lib/std/Build/WebServer.zig+8-1
......@@ -681,7 +681,14 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
681681 );
682682 return error.WasmCompilationFailed;
683683 },
684 .stopped, .unknown => {
684 .stopped => |sig| {
685 log.err(
686 "the following command stopped unexpectedly with signal {d}:\n{s}",
687 .{ sig, try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items) },
688 );
689 return error.WasmCompilationFailed;
690 },
691 .unknown => {
685692 log.err(
686693 "the following command terminated unexpectedly:\n{s}",
687694 .{try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)},
lib/std/zig/system.zig+18-4
......@@ -1185,11 +1185,25 @@ fn detectAndroidApiLevel(io: Io) !u32 {
11851185 return error.ApiLevelQueryFailed;
11861186 };
11871187
1188 const term = try child.wait(io);
1189 if (term != .exited or term.exited != 0) {
1190 std.log.err("getprop terminated abnormally: {}", .{term});
1191 return error.ApiLevelQueryFailed;
1188 switch (try child.wait(io)) {
1189 .exited => |code| if (code != 0) {
1190 std.log.err("getprop terminated abnormally with exit code: {d}", .{code});
1191 return error.ApiLevelQueryFailed;
1192 },
1193 .signal => |sig| {
1194 std.log.err("getprop terminated abnormally with signal: {t}", .{sig});
1195 return error.ApiLevelQueryFailed;
1196 },
1197 .stopped => |sig| {
1198 std.log.err("getprop stopped abnormally with signal: {d}", .{sig});
1199 return error.ApiLevelQueryFailed;
1200 },
1201 .unknown => {
1202 std.log.err("getprop terminated abnormally", .{});
1203 return error.ApiLevelQueryFailed;
1204 },
11921205 }
1206
11931207 return api_level;
11941208}
11951209
src/Compilation.zig+10-2
......@@ -5870,7 +5870,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
58705870 log.err("clang failed with stderr: {s}", .{stderr});
58715871 return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig});
58725872 },
5873 else => {
5873 .stopped => |sig| {
5874 log.err("clang failed with stderr: {s}", .{stderr});
5875 return comp.failCObj(c_object, "clang stopped with signal {d}", .{sig});
5876 },
5877 .unknown => {
58745878 log.err("clang terminated with stderr: {s}", .{stderr});
58755879 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});
58765880 },
......@@ -6297,7 +6301,11 @@ fn spawnZigRc(
62976301 log.err("zig rc signaled {t} with stderr:\n{s}", .{ sig, stderr });
62986302 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
62996303 },
6300 else => {
6304 .stopped => |sig| {
6305 log.err("zig rc stopped {d} with stderr:\n{s}", .{ sig, stderr });
6306 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
6307 },
6308 .unknown => {
63016309 log.err("zig rc terminated with stderr:\n{s}", .{stderr});
63026310 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
63036311 },
src/main.zig+15-3
......@@ -4580,7 +4580,11 @@ fn runOrTest(
45804580 const cmd = try std.mem.join(arena, " ", argv.items);
45814581 fatal("the following command terminated with signal {t}:\n{s}", .{ sig, cmd });
45824582 },
4583 else => {
4583 .stopped => |sig| {
4584 const cmd = try std.mem.join(arena, " ", argv.items);
4585 fatal("the following command stopped with signal {d}:\n{s}", .{ sig, cmd });
4586 },
4587 .unknown => {
45844588 process.exit(1);
45854589 },
45864590 }
......@@ -5631,7 +5635,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
56315635 const cmd = try std.mem.join(arena, " ", child_argv.items);
56325636 fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });
56335637 },
5634 else => {
5638 .stopped => |sig| {
5639 const cmd = try std.mem.join(arena, " ", child_argv.items);
5640 fatal("the following build command stopped with signal {d}:\n{s}", .{ sig, cmd });
5641 },
5642 .unknown => {
56355643 const cmd = try std.mem.join(arena, " ", child_argv.items);
56365644 fatal("the following build command crashed:\n{s}", .{cmd});
56375645 },
......@@ -5933,7 +5941,11 @@ fn jitCmdInner(
59335941 const cmd = try std.mem.join(arena, " ", child_argv.items);
59345942 fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });
59355943 },
5936 else => {
5944 .stopped => |sig| {
5945 const cmd = try std.mem.join(arena, " ", child_argv.items);
5946 fatal("the following build command stopped with signal {d}:\n{s}", .{ sig, cmd });
5947 },
5948 .unknown => {
59375949 const cmd = try std.mem.join(arena, " ", child_argv.items);
59385950 fatal("the following build command crashed:\n{s}", .{cmd});
59395951 },
tools/doctest.zig+6-1
......@@ -1141,7 +1141,12 @@ fn run(
11411141 dumpArgs(args);
11421142 return error.ChildCrashed;
11431143 },
1144 else => {
1144 .stopped => |sig| {
1145 std.debug.print("{s}\nThe following command stopped with signal {d}:\n", .{ result.stderr, sig });
1146 dumpArgs(args);
1147 return error.ChildCrashed;
1148 },
1149 .unknown => {
11451150 std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr});
11461151 dumpArgs(args);
11471152 return error.ChildCrashed;
tools/incr-check.zig+16-14
......@@ -568,7 +568,10 @@ const Eval = struct {
568568 .signal => |sig| {
569569 eval.fatal("generated executable '{s}' terminated with signal {t}", .{ binary_path, sig });
570570 },
571 .stopped, .unknown => {
571 .stopped => |sig| {
572 eval.fatal("generated executable '{s}' stopped with signal {d}", .{ binary_path, sig });
573 },
574 .unknown => {
572575 eval.fatal("generated executable '{s}' terminated unexpectedly", .{binary_path});
573576 },
574577 }
......@@ -627,19 +630,17 @@ const Eval = struct {
627630 }) catch |err| {
628631 eval.fatal("failed to spawn zig cc for '{s}': {t}", .{ c_path, err });
629632 };
633
634 if (result.term == .exited and result.term.exited == 0) return;
635
636 if (result.stderr.len != 0) {
637 std.log.err("zig cc stderr:\n{s}", .{result.stderr});
638 }
630639 switch (result.term) {
631 .exited => |code| if (code != 0) {
632 if (result.stderr.len != 0) {
633 std.log.err("zig cc stderr:\n{s}", .{result.stderr});
634 }
635 eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code });
636 },
637 .signal, .stopped, .unknown => {
638 if (result.stderr.len != 0) {
639 std.log.err("zig cc stderr:\n{s}", .{result.stderr});
640 }
641 eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path});
642 },
640 .exited => |code| eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code }),
641 .signal => |sig| eval.fatal("zig cc for '{s}' terminated unexpectedly with signal {t}", .{ c_path, sig }),
642 .stopped => |sig| eval.fatal("zig cc for '{s}' stopped unexpectedly with signal {d}", .{ c_path, sig }),
643 .unknown => eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path}),
643644 }
644645 }
645646
......@@ -918,7 +919,8 @@ fn waitChild(child: *std.process.Child, eval: *Eval) void {
918919 switch (term) {
919920 .exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),
920921 .signal => |sig| eval.fatal("compiler terminated with signal {t}", .{sig}),
921 .stopped, .unknown => eval.fatal("compiler terminated unexpectedly", .{}),
922 .stopped => |sig| eval.fatal("compiler stopped unexpectedly with signal {d}", .{sig}),
923 .unknown => eval.fatal("compiler terminated unexpectedly", .{}),
922924 }
923925}
924926
tools/update_clang_options.zig+10-1
......@@ -688,7 +688,16 @@ pub fn main(init: std.process.Init) !void {
688688
689689 const json_text = switch (child_result.term) {
690690 .exited => |code| if (code == 0) child_result.stdout else {
691 fatal("llvm-tblgen exited with code {d}", .{code});
691 fatal("llvm-tblgen exited with code {d}\n", .{code});
692 },
693 .signal => |sig| {
694 fatal("llvm-tblgen terminated with signal {t}\n", .{sig});
695 },
696 .stopped => |sig| {
697 fatal("llvm-tblgen stopped with signal {d}\n", .{sig});
698 },
699 .unknown => {
700 fatal("llvm-tblgen crashed\n", .{});
692701 },
693702 else => fatal("llvm-tblgen crashed", .{}),
694703 };
tools/update_cpu_features.zig+9-1
......@@ -2012,7 +2012,15 @@ fn processOneTarget(io: Io, job: Job) void {
20122012 std.debug.print("llvm-tblgen exited with code {d}\n", .{code});
20132013 std.process.exit(1);
20142014 },
2015 else => {
2015 .signal => |sig| {
2016 std.debug.print("llvm-tblgen terminated with signal {t}\n", .{sig});
2017 std.process.exit(1);
2018 },
2019 .stopped => |sig| {
2020 std.debug.print("llvm-tblgen stopped with signal {d}\n", .{sig});
2021 std.process.exit(1);
2022 },
2023 .unknown => {
20162024 std.debug.print("llvm-tblgen crashed\n", .{});
20172025 std.process.exit(1);
20182026 },