]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #85490 - CDirkx:fix-vxworks, r=dtolnay
authorbors <bors@rust-lang.org>
Sun, 23 May 2021 05:40:18 +0000 (05:40 +0000)
committerbors <bors@rust-lang.org>
Sun, 23 May 2021 05:40:18 +0000 (05:40 +0000)
Fix `vxworks`

Some PRs made the `vxworks` target not build anymore. This PR fixes that:

- #82973: copy `ExitStatusError` implementation from `unix`.
- #84716: no `libc::chroot` available on `vxworks`, so for now don't implement `os::unix::fs::chroot`.

library/std/src/os/unix/fs.rs
library/std/src/sys/unix/fs.rs
library/std/src/sys/unix/process/process_unix.rs
library/std/src/sys/unix/process/process_vxworks.rs

index 9cf51be2836fb5c8276f6ee976fc50e4d4eedb73..913c71d41087951b5d2ef41079fec089a6ebe821 100644 (file)
@@ -906,7 +906,7 @@ fn mode(&mut self, mode: u32) -> &mut fs::DirBuilder {
 /// }
 /// ```
 #[unstable(feature = "unix_chroot", issue = "84715")]
-#[cfg(not(target_os = "fuchsia"))]
+#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
 pub fn chroot<P: AsRef<Path>>(dir: P) -> io::Result<()> {
     sys::fs::chroot(dir.as_ref())
 }
index ef14865fbcd39dc174197f68b21a1cd26896fb2a..f8ca67c844c91bac327797d454eaf7ab4b7ea603 100644 (file)
@@ -1329,7 +1329,7 @@ fn fclonefileat(
     Ok(bytes_copied as u64)
 }
 
-#[cfg(not(target_os = "fuchsia"))]
+#[cfg(not(any(target_os = "fuchsia", target_os = "vxworks")))]
 pub fn chroot(dir: &Path) -> io::Result<()> {
     let dir = cstr(dir)?;
     cvt(unsafe { libc::chroot(dir.as_ptr()) })?;
index 7f8065e750038b15ebe4c32ac065792b5b6ff9ba..ed55e1aa715ae5ac5cea3b99fdce5b0d3614f4ee 100644 (file)
@@ -495,7 +495,7 @@ fn exited(&self) -> bool {
 
     pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
         // This assumes that WIFEXITED(status) && WEXITSTATUS==0 corresponds to status==0.  This is
-        // true on all actual versios of Unix, is widely assumed, and is specified in SuS
+        // true on all actual versions of Unix, is widely assumed, and is specified in SuS
         // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html .  If it is not
         // true for a platform pretending to be Unix, the tests (our doctests, and also
         // procsss_unix/tests.rs) will spot it.  `ExitStatusError::code` assumes this too.
index eecdb624b9cfab6b3351fe518e3b1afd1f0e1a9d..c17822f51253266d1e66d3cbde32b88b9809fc1b 100644 (file)
@@ -1,5 +1,8 @@
+use crate::convert::{TryFrom, TryInto};
 use crate::fmt;
 use crate::io::{self, Error, ErrorKind};
+use crate::num::NonZeroI32;
+use crate::os::raw::NonZero_c_int;
 use crate::sys;
 use crate::sys::cvt;
 use crate::sys::process::process_common::*;
@@ -187,8 +190,16 @@ fn exited(&self) -> bool {
         libc::WIFEXITED(self.0)
     }
 
-    pub fn success(&self) -> bool {
-        self.code() == Some(0)
+    pub fn exit_ok(&self) -> Result<(), ExitStatusError> {
+        // This assumes that WIFEXITED(status) && WEXITSTATUS==0 corresponds to status==0.  This is
+        // true on all actual versions of Unix, is widely assumed, and is specified in SuS
+        // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html .  If it is not
+        // true for a platform pretending to be Unix, the tests (our doctests, and also
+        // procsss_unix/tests.rs) will spot it.  `ExitStatusError::code` assumes this too.
+        match NonZero_c_int::try_from(self.0) {
+            Ok(failure) => Err(ExitStatusError(failure)),
+            Err(_) => Ok(()),
+        }
     }
 
     pub fn code(&self) -> Option<i32> {
@@ -235,3 +246,18 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
         }
     }
 }
+
+#[derive(PartialEq, Eq, Clone, Copy, Debug)]
+pub struct ExitStatusError(NonZero_c_int);
+
+impl Into<ExitStatus> for ExitStatusError {
+    fn into(self) -> ExitStatus {
+        ExitStatus(self.0.into())
+    }
+}
+
+impl ExitStatusError {
+    pub fn code(self) -> Option<NonZeroI32> {
+        ExitStatus(self.0.into()).code().map(|st| st.try_into().unwrap())
+    }
+}