about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-12-06 07:43:56 +0000
committerbors <bors@rust-lang.org>2019-12-06 07:43:56 +0000
commitd0126e8ed3cc0d6fcb9dd44c36a46f9ce65010a0 (patch)
tree1e574274dfc984cf278d7a39e154b408f1663485 /src/libstd
parent7b482cdf7ce55e05ee8392e1ade70966e3189cfd (diff)
parentacd2b0835d1b833b851501a9d255ee7882f45a84 (diff)
downloadrust-d0126e8ed3cc0d6fcb9dd44c36a46f9ce65010a0.tar.gz
rust-d0126e8ed3cc0d6fcb9dd44c36a46f9ce65010a0.zip
Auto merge of #67080 - JohnTitor:rollup-2t6fm3u, r=JohnTitor
Rollup of 10 pull requests

Successful merges:

 - #66649 (VxWorks: fix issues in accessing environment variables)
 - #66764 (Tweak wording of `collect()` on bad target type)
 - #66900 (Clean up error codes)
 - #66974 ([CI] fix the `! isCI` check in src/ci/run.sh)
 - #66979 (Add long error for E0631 and update ui tests.)
 - #67017 (cleanup long error explanations)
 - #67021 (Fix docs for formatting delegations)
 - #67041 (add ExitStatusExt into prelude)
 - #67065 (Fix fetching arguments on the wasm32-wasi target)
 - #67066 (Update the revision of wasi-libc used in wasm32-wasi)

Failed merges:

r? @ghost
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sys/vxworks/ext/mod.rs3
-rw-r--r--src/libstd/sys/vxworks/os.rs19
-rw-r--r--src/libstd/sys/vxworks/process/process_vxworks.rs12
-rw-r--r--src/libstd/sys/wasi/args.rs1
4 files changed, 26 insertions, 9 deletions
diff --git a/src/libstd/sys/vxworks/ext/mod.rs b/src/libstd/sys/vxworks/ext/mod.rs
index 251a198f821..8fa9bd9d1e2 100644
--- a/src/libstd/sys/vxworks/ext/mod.rs
+++ b/src/libstd/sys/vxworks/ext/mod.rs
@@ -18,4 +18,7 @@ pub mod prelude {
     #[doc(no_inline)]
     #[stable(feature = "rust1", since = "1.0.0")]
     pub use super::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
+    #[doc(no_inline)]
+    #[stable(feature = "rust1", since = "1.0.0")]
+    pub use super::process::ExitStatusExt;
 }
diff --git a/src/libstd/sys/vxworks/os.rs b/src/libstd/sys/vxworks/os.rs
index baa6c425d2e..71e1d1626c1 100644
--- a/src/libstd/sys/vxworks/os.rs
+++ b/src/libstd/sys/vxworks/os.rs
@@ -11,14 +11,12 @@ use crate::path::{self, PathBuf, Path};
 use crate::ptr;
 use crate::slice;
 use crate::str;
-use crate::sys_common::mutex::Mutex;
+use crate::sys_common::mutex::{Mutex, MutexGuard};
 use crate::sys::cvt;
 /*use sys::fd; this one is probably important */
 use crate::vec;
 
 const TMPBUF_SZ: usize = 128;
-static ENV_LOCK: Mutex = Mutex::new();
-
 
 // This is a terrible fix
 use crate::sys::os_str::Buf;
@@ -200,11 +198,18 @@ pub unsafe fn environ() -> *mut *const *const c_char {
     &mut environ
 }
 
+pub unsafe fn env_lock() -> MutexGuard<'static> {
+    // We never call `ENV_LOCK.init()`, so it is UB to attempt to
+    // acquire this mutex reentrantly!
+    static ENV_LOCK: Mutex = Mutex::new();
+    ENV_LOCK.lock()
+}
+
 /// Returns a vector of (variable, value) byte-vector pairs for all the
 /// environment variables of the current process.
 pub fn env() -> Env {
     unsafe {
-        let _guard = ENV_LOCK.lock();
+        let _guard = env_lock();
         let mut environ = *environ();
         if environ == ptr::null() {
             panic!("os::env() failure getting env string from OS: {}",
@@ -244,7 +249,7 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> {
     // always None as well
     let k = CString::new(k.as_bytes())?;
     unsafe {
-        let _guard = ENV_LOCK.lock();
+        let _guard = env_lock();
         let s = libc::getenv(k.as_ptr()) as *const libc::c_char;
         let ret = if s.is_null() {
             None
@@ -260,7 +265,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> {
     let v = CString::new(v.as_bytes())?;
 
     unsafe {
-        let _guard = ENV_LOCK.lock();
+        let _guard = env_lock();
         cvt(libc::setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ())
     }
 }
@@ -269,7 +274,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> {
     let nbuf = CString::new(n.as_bytes())?;
 
     unsafe {
-        let _guard = ENV_LOCK.lock();
+        let _guard = env_lock();
         cvt(libc::unsetenv(nbuf.as_ptr())).map(|_| ())
     }
 }
diff --git a/src/libstd/sys/vxworks/process/process_vxworks.rs b/src/libstd/sys/vxworks/process/process_vxworks.rs
index 7446471ae31..79bfd770f8e 100644
--- a/src/libstd/sys/vxworks/process/process_vxworks.rs
+++ b/src/libstd/sys/vxworks/process/process_vxworks.rs
@@ -15,6 +15,7 @@ impl Command {
                  -> io::Result<(Process, StdioPipes)> {
         use crate::sys::{cvt_r};
         const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX";
+        let envp = self.capture_env();
 
         if self.saw_nul() {
             return Err(io::Error::new(ErrorKind::InvalidInput,
@@ -52,12 +53,19 @@ impl Command {
                 t!(cvt(libc::chdir(cwd.as_ptr())));
             }
 
+            let c_envp = envp.as_ref().map(|c| c.as_ptr())
+                .unwrap_or_else(|| *sys::os::environ() as *const _);
+            let stack_size = thread::min_stack();
+
+            // ensure that access to the environment is synchronized
+            let _lock = sys::os::env_lock();
+
             let ret = libc::rtpSpawn(
                 self.get_argv()[0],                   // executing program
                 self.get_argv().as_ptr() as *mut *const c_char, // argv
-                *sys::os::environ() as *mut *const c_char,
+                c_envp as *mut *const c_char,
                 100 as c_int,                         // initial priority
-                thread::min_stack(),                  // initial stack size.
+                stack_size,                           // initial stack size.
                 0,                                    // options
                 0                                     // task options
             );
diff --git a/src/libstd/sys/wasi/args.rs b/src/libstd/sys/wasi/args.rs
index 3db36f5e132..02aa68d6f3a 100644
--- a/src/libstd/sys/wasi/args.rs
+++ b/src/libstd/sys/wasi/args.rs
@@ -26,6 +26,7 @@ fn maybe_args() -> Option<Vec<OsString>> {
         let mut argv = Vec::with_capacity(argc);
         let mut buf = Vec::with_capacity(buf_size);
         wasi::args_get(argv.as_mut_ptr(), buf.as_mut_ptr()).ok()?;
+        argv.set_len(argc);
         let mut ret = Vec::with_capacity(argc);
         for ptr in argv {
             let s = CStr::from_ptr(ptr.cast());