mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
audit: handle process.Child.Term exhaustively and give useful exit information
This commit is contained in:
@@ -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;
|
||||
},
|
||||
|
||||
@@ -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
@@ -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(
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user