about summary refs log tree commit diff
path: root/src/libstd/sys/unix
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-31 10:20:31 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-31 10:20:31 -0800
commitaec67c2ee0f673ea7b0e21c2fe7e0f26a523d823 (patch)
tree032a8ec1398c7334c20b791a4c4c460feb5e2c79 /src/libstd/sys/unix
parent582cba183f18eea5c40b6c035d63ad449a9e8604 (diff)
downloadrust-aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.tar.gz
rust-aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.zip
Revert "std: Re-enable at_exit()"
This reverts commit 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7.

Conflicts:
	src/libstd/sys/windows/os.rs
Diffstat (limited to 'src/libstd/sys/unix')
-rw-r--r--src/libstd/sys/unix/backtrace.rs12
-rw-r--r--src/libstd/sys/unix/mod.rs16
-rw-r--r--src/libstd/sys/unix/mutex.rs2
-rw-r--r--src/libstd/sys/unix/os.rs9
-rw-r--r--src/libstd/sys/unix/pipe.rs2
-rw-r--r--src/libstd/sys/unix/process.rs15
-rw-r--r--src/libstd/sys/unix/rwlock.rs1
-rw-r--r--src/libstd/sys/unix/stack_overflow.rs1
-rw-r--r--src/libstd/sys/unix/tcp.rs4
-rw-r--r--src/libstd/sys/unix/timer.rs11
-rw-r--r--src/libstd/sys/unix/tty.rs1
11 files changed, 43 insertions, 31 deletions
diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs
index 0ec34fb1318..ddae9a132c3 100644
--- a/src/libstd/sys/unix/backtrace.rs
+++ b/src/libstd/sys/unix/backtrace.rs
@@ -83,12 +83,12 @@
 /// to symbols. This is a bit of a hokey implementation as-is, but it works for
 /// all unix platforms we support right now, so it at least gets the job done.
 
-use prelude::*;
-
 use c_str::CString;
-use io::IoResult;
+use io::{IoResult, Writer};
 use libc;
 use mem;
+use option::Option::{mod, Some, None};
+use result::Result::{Ok, Err};
 use sync::{StaticMutex, MUTEX_INIT};
 
 use sys_common::backtrace::*;
@@ -151,7 +151,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> {
     // I/O done here is blocking I/O, not green I/O, so we don't have to
     // worry about this being a native vs green mutex.
     static LOCK: StaticMutex = MUTEX_INIT;
-    let _g = LOCK.lock();
+    let _g = unsafe { LOCK.lock() };
 
     try!(writeln!(w, "stack backtrace:"));
 
@@ -241,8 +241,12 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
 
 #[cfg(not(any(target_os = "macos", target_os = "ios")))]
 fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
+    use iter::{Iterator, IteratorExt};
     use os;
+    use path::GenericPath;
+    use ptr::PtrExt;
     use ptr;
+    use slice::SliceExt;
 
     ////////////////////////////////////////////////////////////////////////
     // libbacktrace.h API
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs
index dd4141de998..c82dacf1e44 100644
--- a/src/libstd/sys/unix/mod.rs
+++ b/src/libstd/sys/unix/mod.rs
@@ -10,14 +10,30 @@
 
 #![allow(missing_docs)]
 #![allow(non_camel_case_types)]
+#![allow(unused_imports)]
+#![allow(dead_code)]
+#![allow(unused_unsafe)]
+#![allow(unused_mut)]
 
 extern crate libc;
 
+use num;
 use num::{Int, SignedInt};
 use prelude::*;
 use io::{mod, IoResult, IoError};
 use sys_common::mkerr_libc;
 
+macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
+    static $name: Helper<$m> = Helper {
+        lock: ::sync::MUTEX_INIT,
+        cond: ::sync::CONDVAR_INIT,
+        chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
+        signal: ::cell::UnsafeCell { value: 0 },
+        initialized: ::cell::UnsafeCell { value: false },
+        shutdown: ::cell::UnsafeCell { value: false },
+    };
+) }
+
 pub mod backtrace;
 pub mod c;
 pub mod ext;
diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs
index c9cb46b0289..81f8659d6ae 100644
--- a/src/libstd/sys/unix/mutex.rs
+++ b/src/libstd/sys/unix/mutex.rs
@@ -11,6 +11,7 @@
 use cell::UnsafeCell;
 use kinds::Sync;
 use sys::sync as ffi;
+use sys_common::mutex;
 
 pub struct Mutex { inner: UnsafeCell<ffi::pthread_mutex_t> }
 
@@ -25,7 +26,6 @@ pub const MUTEX_INIT: Mutex = Mutex {
 
 unsafe impl Sync for Mutex {}
 
-#[allow(dead_code)] // sys isn't exported yet
 impl Mutex {
     #[inline]
     pub unsafe fn new() -> Mutex {
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 446960ab92f..cafe52f8403 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -10,16 +10,17 @@
 
 //! Implementation of `std::os` functionality for unix systems
 
-#![allow(unused_imports)] // lots of cfg code here
-
 use prelude::*;
 
+use error::{FromError, Error};
+use fmt;
 use io::{IoError, IoResult};
-use libc::{mod, c_int, c_char};
-use os;
+use libc::{mod, c_int, c_char, c_void};
 use path::BytesContainer;
 use ptr;
+use sync::atomic::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
 use sys::fs::FileDesc;
+use os;
 
 use os::TMPBUF_SZ;
 
diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs
index 3b868065f8f..868b460aa5e 100644
--- a/src/libstd/sys/unix/pipe.rs
+++ b/src/libstd/sys/unix/pipe.rs
@@ -145,7 +145,7 @@ impl UnixStream {
     fn lock_nonblocking<'a>(&'a self) -> Guard<'a> {
         let ret = Guard {
             fd: self.fd(),
-            guard: self.inner.lock.lock().unwrap(),
+            guard: unsafe { self.inner.lock.lock().unwrap() },
         };
         assert!(set_nonblocking(self.fd(), true).is_ok());
         ret
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index 48df8c4eced..835f4279d9b 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -11,7 +11,7 @@ use self::Req::*;
 
 use libc::{mod, pid_t, c_void, c_int};
 use c_str::CString;
-use io::{IoResult, EndOfFile};
+use io::{mod, IoResult, IoError, EndOfFile};
 use mem;
 use os;
 use ptr;
@@ -327,7 +327,7 @@ impl Process {
         // The actual communication between the helper thread and this thread is
         // quite simple, just a channel moving data around.
 
-        HELPER.boot(register_sigchld, waitpid_helper);
+        unsafe { HELPER.boot(register_sigchld, waitpid_helper) }
 
         match self.try_wait() {
             Some(ret) => return Ok(ret),
@@ -335,7 +335,7 @@ impl Process {
         }
 
         let (tx, rx) = channel();
-        HELPER.send(NewChild(self.pid, tx, deadline));
+        unsafe { HELPER.send(NewChild(self.pid, tx, deadline)); }
         return match rx.recv_opt() {
             Ok(e) => Ok(e),
             Err(()) => Err(timeout("wait timed out")),
@@ -419,15 +419,8 @@ impl Process {
                             Ok(NewChild(pid, tx, deadline)) => {
                                 active.push((pid, tx, deadline));
                             }
-                            // Once we've been disconnected it means the main
-                            // thread is exiting (at_exit has run). We could
-                            // still have active waiter for other threads, so
-                            // we're just going to drop them all on the floor.
-                            // This means that they won't receive a "you're
-                            // done" message in which case they'll be considered
-                            // as timed out, but more generally errors will
-                            // start propagating.
                             Err(comm::Disconnected) => {
+                                assert!(active.len() == 0);
                                 break 'outer;
                             }
                             Err(comm::Empty) => break,
diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs
index 4f9b06685ec..0d63ff14ff2 100644
--- a/src/libstd/sys/unix/rwlock.rs
+++ b/src/libstd/sys/unix/rwlock.rs
@@ -17,7 +17,6 @@ pub const RWLOCK_INIT: RWLock = RWLock {
     inner: UnsafeCell { value: ffi::PTHREAD_RWLOCK_INITIALIZER },
 };
 
-#[allow(dead_code)] // sys isn't exported yet
 impl RWLock {
     #[inline]
     pub unsafe fn new() -> RWLock {
diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs
index f1d7f1784d0..bcbbb8766b7 100644
--- a/src/libstd/sys/unix/stack_overflow.rs
+++ b/src/libstd/sys/unix/stack_overflow.rs
@@ -34,6 +34,7 @@ impl Drop for Handler {
 
 #[cfg(any(target_os = "linux", target_os = "macos"))]
 mod imp {
+    use core::prelude::*;
     use sys_common::stack;
 
     use super::Handler;
diff --git a/src/libstd/sys/unix/tcp.rs b/src/libstd/sys/unix/tcp.rs
index 696d3fb676d..e2a78947e16 100644
--- a/src/libstd/sys/unix/tcp.rs
+++ b/src/libstd/sys/unix/tcp.rs
@@ -135,6 +135,10 @@ impl TcpAcceptor {
         Err(sys_common::eof())
     }
 
+    pub fn socket_name(&mut self) -> IoResult<ip::SocketAddr> {
+        net::sockname(self.fd(), libc::getsockname)
+    }
+
     pub fn set_timeout(&mut self, timeout: Option<u64>) {
         self.deadline = timeout.map(|a| sys::timer::now() + a).unwrap_or(0);
     }
diff --git a/src/libstd/sys/unix/timer.rs b/src/libstd/sys/unix/timer.rs
index 150ec6aad8a..c0ef89666c0 100644
--- a/src/libstd/sys/unix/timer.rs
+++ b/src/libstd/sys/unix/timer.rs
@@ -100,7 +100,7 @@ pub fn now() -> u64 {
 fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
     let mut set: c::fd_set = unsafe { mem::zeroed() };
 
-    let fd = FileDesc::new(input, true);
+    let mut fd = FileDesc::new(input, true);
     let mut timeout: libc::timeval = unsafe { mem::zeroed() };
 
     // active timers are those which are able to be selected upon (and it's a
@@ -168,15 +168,8 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
             1 => {
                 loop {
                     match messages.try_recv() {
-                        // Once we've been disconnected it means the main thread
-                        // is exiting (at_exit has run). We could still have
-                        // active timers for other threads, so we're just going
-                        // to drop them all on the floor. This is all we can
-                        // really do, however, to prevent resource leakage. The
-                        // remaining timers will likely start panicking quickly
-                        // as they attempt to re-use this thread but are
-                        // disallowed to do so.
                         Err(comm::Disconnected) => {
+                            assert!(active.len() == 0);
                             break 'outer;
                         }
 
diff --git a/src/libstd/sys/unix/tty.rs b/src/libstd/sys/unix/tty.rs
index d05047a220f..28c17fd4966 100644
--- a/src/libstd/sys/unix/tty.rs
+++ b/src/libstd/sys/unix/tty.rs
@@ -43,4 +43,5 @@ impl TTY {
     pub fn get_winsize(&mut self) -> IoResult<(int, int)> {
         Err(sys_common::unimpl())
     }
+    pub fn isatty(&self) -> bool { false }
 }