Skip to content

Commit af2d81d

Browse files
krobelusfaho
authored andcommitted
Temporary workaround for BSD WEXITSTATUS libc bug
The libc crate has a bug on BSD where WEXITSTATUS is not an 8-bit value, causing assertion failures. Any libc higher than our 0.2.155 would increase our MSRV, see libc commit 5ddbdc29f (Bump MSRV to 1.71, 2024-01-07), so we want to woraround this anyway. It's probably not worth using a patched version of libc since it's just one line. While at it, tighten some types I guess. Upstream fix: rust-lang/libc#4213 Closes fish-shell#10919
1 parent 6b029e8 commit af2d81d

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/proc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,22 @@ impl ProcStatus {
233233
}
234234

235235
/// Return the exit code, given that we normal exited.
236-
pub fn exit_code(&self) -> libc::c_int {
236+
pub fn exit_code(&self) -> u8 {
237237
assert!(self.normal_exited(), "Process is not normal exited");
238-
WEXITSTATUS(self.status())
238+
u8::try_from(WEXITSTATUS(self.status()) & 0xff).unwrap() // Workaround for libc bug
239239
}
240240

241241
/// Return if this status represents success.
242242
pub fn is_success(&self) -> bool {
243-
self.normal_exited() && self.exit_code() == EXIT_SUCCESS
243+
self.normal_exited() && self.exit_code() == u8::try_from(EXIT_SUCCESS).unwrap()
244244
}
245245

246246
/// Return the value appropriate to populate $status.
247247
pub fn status_value(&self) -> i32 {
248248
if self.signal_exited() {
249249
128 + self.signal_code()
250250
} else if self.normal_exited() {
251-
self.exit_code()
251+
i32::from(self.exit_code())
252252
} else {
253253
panic!("Process is not exited")
254254
}

0 commit comments

Comments
 (0)