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 {...@@ -291,7 +291,11 @@ fn termToInteresting(term: std.process.Child.Term) Interestingness {
291 std.debug.print("interestingness check terminated with signal {t}\n", .{sig});291 std.debug.print("interestingness check terminated with signal {t}\n", .{sig});
292 return .boring;292 return .boring;
293 },293 },
294 else => {294 .stopped => |sig| {
295 std.debug.print("interestingness check stopped with signal {d}\n", .{sig});
296 return .boring;
297 },
298 .unknown => {
295 std.debug.print("interestingness check aborted unexpectedly\n", .{});299 std.debug.print("interestingness check aborted unexpectedly\n", .{});
296 return .boring;300 return .boring;
297 },301 },
lib/compiler/std-docs.zig+8-1
...@@ -423,7 +423,14 @@ fn buildWasmBinary(...@@ -423,7 +423,14 @@ fn buildWasmBinary(
423 );423 );
424 return error.WasmCompilationFailed;424 return error.WasmCompilationFailed;
425 },425 },
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 => {
427 std.log.err(434 std.log.err(
428 "the following command terminated unexpectedly:\n{s}",435 "the following command terminated unexpectedly:\n{s}",
429 .{try std.Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)},436 .{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...@@ -725,19 +725,12 @@ pub inline fn handleChildProcUnsupported(s: *Step) error{ OutOfMemory, MakeFaile
725/// Asserts that the caller has already populated `s.result_failed_command`.725/// Asserts that the caller has already populated `s.result_failed_command`.
726pub fn handleChildProcessTerm(s: *Step, term: std.process.Child.Term) error{ MakeFailed, OutOfMemory }!void {726pub fn handleChildProcessTerm(s: *Step, term: std.process.Child.Term) error{ MakeFailed, OutOfMemory }!void {
727 assert(s.result_failed_command != null);727 assert(s.result_failed_command != null);
728 switch (term) {728 return switch (term) {
729 .exited => |code| {729 .exited => |code| if (code != 0) s.fail("process exited with error code {d}", .{code}),
730 if (code != 0) {730 .signal => |sig| s.fail("process terminated with signal {t}", .{sig}),
731 return s.fail("process exited with error code {d}", .{code});731 .stopped => |sig| s.fail("process stopped with signal {d}", .{sig}),
732 }732 .unknown => s.fail("process terminated unexpectedly", .{}),
733 },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 }
741}734}
742735
743pub fn allocPrintCmd(736pub fn allocPrintCmd(
lib/std/Build/WebServer.zig+8-1
...@@ -681,7 +681,14 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim...@@ -681,7 +681,14 @@ fn buildClientWasm(ws: *WebServer, arena: Allocator, optimize: std.builtin.Optim
681 );681 );
682 return error.WasmCompilationFailed;682 return error.WasmCompilationFailed;
683 },683 },
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 => {
685 log.err(692 log.err(
686 "the following command terminated unexpectedly:\n{s}",693 "the following command terminated unexpectedly:\n{s}",
687 .{try Build.Step.allocPrintCmd(arena, .inherit, null, argv.items)},694 .{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 {...@@ -1185,11 +1185,25 @@ fn detectAndroidApiLevel(io: Io) !u32 {
1185 return error.ApiLevelQueryFailed;1185 return error.ApiLevelQueryFailed;
1186 };1186 };
11871187
1188 const term = try child.wait(io);1188 switch (try child.wait(io)) {
1189 if (term != .exited or term.exited != 0) {1189 .exited => |code| if (code != 0) {
1190 std.log.err("getprop terminated abnormally: {}", .{term});1190 std.log.err("getprop terminated abnormally with exit code: {d}", .{code});
1191 return error.ApiLevelQueryFailed;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 },
1192 }1205 }
1206
1193 return api_level;1207 return api_level;
1194}1208}
11951209
src/Compilation.zig+10-2
...@@ -5870,7 +5870,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr...@@ -5870,7 +5870,11 @@ fn updateCObject(comp: *Compilation, c_object: *CObject, c_obj_prog_node: std.Pr
5870 log.err("clang failed with stderr: {s}", .{stderr});5870 log.err("clang failed with stderr: {s}", .{stderr});
5871 return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig});5871 return comp.failCObj(c_object, "clang terminated with signal {t}", .{sig});
5872 },5872 },
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 => {
5874 log.err("clang terminated with stderr: {s}", .{stderr});5878 log.err("clang terminated with stderr: {s}", .{stderr});
5875 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});5879 return comp.failCObj(c_object, "clang terminated unexpectedly", .{});
5876 },5880 },
...@@ -6297,7 +6301,11 @@ fn spawnZigRc(...@@ -6297,7 +6301,11 @@ fn spawnZigRc(
6297 log.err("zig rc signaled {t} with stderr:\n{s}", .{ sig, stderr });6301 log.err("zig rc signaled {t} with stderr:\n{s}", .{ sig, stderr });
6298 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});6302 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
6299 },6303 },
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 => {
6301 log.err("zig rc terminated with stderr:\n{s}", .{stderr});6309 log.err("zig rc terminated with stderr:\n{s}", .{stderr});
6302 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});6310 return comp.failWin32Resource(win32_resource, "zig rc terminated unexpectedly", .{});
6303 },6311 },
src/main.zig+15-3
...@@ -4580,7 +4580,11 @@ fn runOrTest(...@@ -4580,7 +4580,11 @@ fn runOrTest(
4580 const cmd = try std.mem.join(arena, " ", argv.items);4580 const cmd = try std.mem.join(arena, " ", argv.items);
4581 fatal("the following command terminated with signal {t}:\n{s}", .{ sig, cmd });4581 fatal("the following command terminated with signal {t}:\n{s}", .{ sig, cmd });
4582 },4582 },
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 => {
4584 process.exit(1);4588 process.exit(1);
4585 },4589 },
4586 }4590 }
...@@ -5631,7 +5635,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,...@@ -5631,7 +5635,11 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8,
5631 const cmd = try std.mem.join(arena, " ", child_argv.items);5635 const cmd = try std.mem.join(arena, " ", child_argv.items);
5632 fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });5636 fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });
5633 },5637 },
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 => {
5635 const cmd = try std.mem.join(arena, " ", child_argv.items);5643 const cmd = try std.mem.join(arena, " ", child_argv.items);
5636 fatal("the following build command crashed:\n{s}", .{cmd});5644 fatal("the following build command crashed:\n{s}", .{cmd});
5637 },5645 },
...@@ -5933,7 +5941,11 @@ fn jitCmdInner(...@@ -5933,7 +5941,11 @@ fn jitCmdInner(
5933 const cmd = try std.mem.join(arena, " ", child_argv.items);5941 const cmd = try std.mem.join(arena, " ", child_argv.items);
5934 fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });5942 fatal("the following build command terminated with signal {t}:\n{s}", .{ sig, cmd });
5935 },5943 },
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 => {
5937 const cmd = try std.mem.join(arena, " ", child_argv.items);5949 const cmd = try std.mem.join(arena, " ", child_argv.items);
5938 fatal("the following build command crashed:\n{s}", .{cmd});5950 fatal("the following build command crashed:\n{s}", .{cmd});
5939 },5951 },
tools/doctest.zig+6-1
...@@ -1141,7 +1141,12 @@ fn run(...@@ -1141,7 +1141,12 @@ fn run(
1141 dumpArgs(args);1141 dumpArgs(args);
1142 return error.ChildCrashed;1142 return error.ChildCrashed;
1143 },1143 },
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 => {
1145 std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr});1150 std.debug.print("{s}\nThe following command crashed:\n", .{result.stderr});
1146 dumpArgs(args);1151 dumpArgs(args);
1147 return error.ChildCrashed;1152 return error.ChildCrashed;
tools/incr-check.zig+16-14
...@@ -568,7 +568,10 @@ const Eval = struct {...@@ -568,7 +568,10 @@ const Eval = struct {
568 .signal => |sig| {568 .signal => |sig| {
569 eval.fatal("generated executable '{s}' terminated with signal {t}", .{ binary_path, sig });569 eval.fatal("generated executable '{s}' terminated with signal {t}", .{ binary_path, sig });
570 },570 },
571 .stopped, .unknown => {571 .stopped => |sig| {
572 eval.fatal("generated executable '{s}' stopped with signal {d}", .{ binary_path, sig });
573 },
574 .unknown => {
572 eval.fatal("generated executable '{s}' terminated unexpectedly", .{binary_path});575 eval.fatal("generated executable '{s}' terminated unexpectedly", .{binary_path});
573 },576 },
574 }577 }
...@@ -627,19 +630,17 @@ const Eval = struct {...@@ -627,19 +630,17 @@ const Eval = struct {
627 }) catch |err| {630 }) catch |err| {
628 eval.fatal("failed to spawn zig cc for '{s}': {t}", .{ c_path, err });631 eval.fatal("failed to spawn zig cc for '{s}': {t}", .{ c_path, err });
629 };632 };
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 }
630 switch (result.term) {639 switch (result.term) {
631 .exited => |code| if (code != 0) {640 .exited => |code| eval.fatal("zig cc for '{s}' failed with code {d}", .{ c_path, code }),
632 if (result.stderr.len != 0) {641 .signal => |sig| eval.fatal("zig cc for '{s}' terminated unexpectedly with signal {t}", .{ c_path, sig }),
633 std.log.err("zig cc stderr:\n{s}", .{result.stderr});642 .stopped => |sig| eval.fatal("zig cc for '{s}' stopped unexpectedly with signal {d}", .{ c_path, sig }),
634 }643 .unknown => eval.fatal("zig cc for '{s}' terminated unexpectedly", .{c_path}),
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 },
643 }644 }
644 }645 }
645646
...@@ -918,7 +919,8 @@ fn waitChild(child: *std.process.Child, eval: *Eval) void {...@@ -918,7 +919,8 @@ fn waitChild(child: *std.process.Child, eval: *Eval) void {
918 switch (term) {919 switch (term) {
919 .exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),920 .exited => |code| if (code != 0) eval.fatal("compiler failed with code {d}", .{code}),
920 .signal => |sig| eval.fatal("compiler terminated with signal {t}", .{sig}),921 .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", .{}),
922 }924 }
923}925}
924926
tools/update_clang_options.zig+10-1
...@@ -688,7 +688,16 @@ pub fn main(init: std.process.Init) !void {...@@ -688,7 +688,16 @@ pub fn main(init: std.process.Init) !void {
688688
689 const json_text = switch (child_result.term) {689 const json_text = switch (child_result.term) {
690 .exited => |code| if (code == 0) child_result.stdout else {690 .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", .{});
692 },701 },
693 else => fatal("llvm-tblgen crashed", .{}),702 else => fatal("llvm-tblgen crashed", .{}),
694 };703 };
tools/update_cpu_features.zig+9-1
...@@ -2012,7 +2012,15 @@ fn processOneTarget(io: Io, job: Job) void {...@@ -2012,7 +2012,15 @@ fn processOneTarget(io: Io, job: Job) void {
2012 std.debug.print("llvm-tblgen exited with code {d}\n", .{code});2012 std.debug.print("llvm-tblgen exited with code {d}\n", .{code});
2013 std.process.exit(1);2013 std.process.exit(1);
2014 },2014 },
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 => {
2016 std.debug.print("llvm-tblgen crashed\n", .{});2024 std.debug.print("llvm-tblgen crashed\n", .{});
2017 std.process.exit(1);2025 std.process.exit(1);
2018 },2026 },