Skip to content

Commit daaec28

Browse files
committed
std: Move management of the exit code to std::os
Previously this functionality was located in std::rt::util, but there's no real reason for it to be located in there.
1 parent 429313d commit daaec28

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/libstd/os.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
#[allow(missing_doc)];
3030

31-
#[cfg(unix)]
32-
use c_str::CString;
3331
use clone::Clone;
3432
use container::Container;
3533
#[cfg(target_os = "macos")]
@@ -43,6 +41,7 @@ use ptr;
4341
use str;
4442
use to_str;
4543
use unstable::finally::Finally;
44+
use sync::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
4645

4746
pub use os::consts::*;
4847

@@ -58,6 +57,8 @@ static BUF_BYTES : uint = 2048u;
5857

5958
#[cfg(unix)]
6059
pub fn getcwd() -> Path {
60+
use c_str::CString;
61+
6162
let mut buf = [0 as libc::c_char, ..BUF_BYTES];
6263
unsafe {
6364
if libc::getcwd(buf.as_mut_ptr(), buf.len() as size_t).is_null() {
@@ -675,17 +676,26 @@ pub fn last_os_error() -> ~str {
675676
strerror()
676677
}
677678

679+
static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
680+
678681
/**
679682
* Sets the process exit code
680683
*
681684
* Sets the exit code returned by the process if all supervised tasks
682685
* terminate successfully (without failing). If the current root task fails
683686
* and is supervised by the scheduler then any user-specified exit status is
684-
* ignored and the process exits with the default failure status
687+
* ignored and the process exits with the default failure status.
688+
*
689+
* Note that this is not synchronized against modifications of other threads.
685690
*/
686691
pub fn set_exit_status(code: int) {
687-
use rt;
688-
rt::set_exit_status(code);
692+
unsafe { EXIT_STATUS.store(code, SeqCst) }
693+
}
694+
695+
/// Fetches the process's current exit code. This defaults to 0 and can change
696+
/// by calling `set_exit_status`.
697+
pub fn get_exit_status() -> int {
698+
unsafe { EXIT_STATUS.load(SeqCst) }
689699
}
690700

691701
#[cfg(target_os = "macos")]

0 commit comments

Comments
 (0)