Skip to content

Commit 96b29d6

Browse files
committed
Auto merge of rust-lang#85490 - CDirkx:fix-vxworks, r=dtolnay
Fix `vxworks` Some PRs made the `vxworks` target not build anymore. This PR fixes that: - rust-lang#82973: copy `ExitStatusError` implementation from `unix`. - rust-lang#84716: no `libc::chroot` available on `vxworks`, so for now don't implement `os::unix::fs::chroot`.
2 parents a45afc4 + 1f0db72 commit 96b29d6

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

std/src/os/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ impl DirBuilderExt for fs::DirBuilder {
906906
/// }
907907
/// ```
908908
#[unstable(feature = "unix_chroot", issue = "84715")]
909-
#[cfg(not(target_os = "fuchsia"))]
909+
#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
910910
pub fn chroot<P: AsRef<Path>>(dir: P) -> io::Result<()> {
911911
sys::fs::chroot(dir.as_ref())
912912
}

std/src/sys/unix/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
13291329
Ok(bytes_copied as u64)
13301330
}
13311331

1332-
#[cfg(not(target_os = "fuchsia"))]
1332+
#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
13331333
pub fn chroot(dir: &Path) -> io::Result<()> {
13341334
let dir = cstr(dir)?;
13351335
cvt(unsafe { libc::chroot(dir.as_ptr()) })?;

std/src/sys/unix/process/process_unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl ExitStatus {
495495

496496
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
497497
// This assumes that WIFEXITED(status) && WEXITSTATUS==0 corresponds to status==0. This is
498-
// true on all actual versios of Unix, is widely assumed, and is specified in SuS
498+
// true on all actual versions of Unix, is widely assumed, and is specified in SuS
499499
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html . If it is not
500500
// true for a platform pretending to be Unix, the tests (our doctests, and also
501501
// procsss_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.

std/src/sys/unix/process/process_vxworks.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use crate::convert::{TryFrom, TryInto};
12
use crate::fmt;
23
use crate::io::{self, Error, ErrorKind};
4+
use crate::num::NonZeroI32;
5+
use crate::os::raw::NonZero_c_int;
36
use crate::sys;
47
use crate::sys::cvt;
58
use crate::sys::process::process_common::*;
@@ -187,8 +190,16 @@ impl ExitStatus {
187190
libc::WIFEXITED(self.0)
188191
}
189192

190-
pub fn success(&self) -> bool {
191-
self.code() == Some(0)
193+
pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
194+
// This assumes that WIFEXITED(status) && WEXITSTATUS==0 corresponds to status==0. This is
195+
// true on all actual versions of Unix, is widely assumed, and is specified in SuS
196+
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html . If it is not
197+
// true for a platform pretending to be Unix, the tests (our doctests, and also
198+
// procsss_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
199+
match NonZero_c_int::try_from(self.0) {
200+
Ok(failure) => Err(ExitStatusError(failure)),
201+
Err(_) => Ok(()),
202+
}
192203
}
193204

194205
pub fn code(&self) -> Option<i32> {
@@ -235,3 +246,18 @@ impl fmt::Display for ExitStatus {
235246
}
236247
}
237248
}
249+
250+
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
251+
pub struct ExitStatusError(NonZero_c_int);
252+
253+
impl Into<ExitStatus> for ExitStatusError {
254+
fn into(self) -> ExitStatus {
255+
ExitStatus(self.0.into())
256+
}
257+
}
258+
259+
impl ExitStatusError {
260+
pub fn code(self) -> Option<NonZeroI32> {
261+
ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())
262+
}
263+
}

0 commit comments

Comments
 (0)