Skip to content

Commit

Permalink
Temporary workaround for BSD WEXITSTATUS libc bug
Browse files Browse the repository at this point in the history
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
  • Loading branch information
krobelus authored and faho committed Dec 26, 2024
1 parent 6b029e8 commit af2d81d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/proc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,22 @@ impl ProcStatus {
}

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

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

/// Return the value appropriate to populate $status.
pub fn status_value(&self) -> i32 {
if self.signal_exited() {
128 + self.signal_code()
} else if self.normal_exited() {
self.exit_code()
i32::from(self.exit_code())
} else {
panic!("Process is not exited")
}
Expand Down

0 comments on commit af2d81d

Please sign in to comment.