Remove os::waitpid because:

- The return value meant different things on different
   platforms (on windows, it was the exit code, on unix it was
   the status information returned from waitpid).
 - It was undocumented.
 - There also exists run::waitpid, which does much the same
   thing but has a more consistent return value and also some
   documentation.
This commit is contained in:
gareth 2013-04-22 21:58:19 +01:00
parent 91aeecf7e3
commit 690120d6bc
2 changed files with 19 additions and 30 deletions

View File

@ -60,7 +60,6 @@ pub mod rustrt {
unsafe fn rust_get_argv() -> **c_char;
unsafe fn rust_path_is_dir(path: *libc::c_char) -> c_int;
unsafe fn rust_path_exists(path: *libc::c_char) -> c_int;
unsafe fn rust_process_wait(pid: c_int) -> c_int;
unsafe fn rust_set_exit_status(code: libc::intptr_t);
}
}
@ -352,31 +351,6 @@ pub fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int {
}
}
#[cfg(windows)]
pub fn waitpid(pid: pid_t) -> c_int {
unsafe {
let status = rustrt::rust_process_wait(pid);
if status < 0 {
fail!(fmt!("failure in rust_process_wait: %s", last_os_error()));
}
return status;
}
}
#[cfg(unix)]
pub fn waitpid(pid: pid_t) -> c_int {
unsafe {
use libc::funcs::posix01::wait::*;
let mut status = 0 as c_int;
assert!((waitpid(pid, &mut status, 0 as c_int) !=
(-1 as c_int)));
return status;
}
}
pub struct Pipe { mut in: c_int, mut out: c_int }
#[cfg(unix)]

View File

@ -36,6 +36,7 @@ pub mod rustrt {
in_fd: c_int,
out_fd: c_int,
err_fd: c_int) -> run::RunProgramResult;
unsafe fn rust_process_wait(pid: c_int) -> c_int;
}
}
@ -503,17 +504,27 @@ pub fn readclose(fd: c_int) -> ~str {
}
}
/// Waits for a process to exit and returns the exit code
/**
* Waits for a process to exit and returns the exit code, failing
* if there is no process with the specified id.
*/
pub fn waitpid(pid: pid_t) -> int {
return waitpid_os(pid);
#[cfg(windows)]
fn waitpid_os(pid: pid_t) -> int {
os::waitpid(pid) as int
let status = unsafe { rustrt::rust_process_wait(pid) };
if status < 0 {
fail!(fmt!("failure in rust_process_wait: %s", os::last_os_error()));
}
return status as int;
}
#[cfg(unix)]
fn waitpid_os(pid: pid_t) -> int {
use libc::funcs::posix01::wait::*;
#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
fn WIFEXITED(status: i32) -> bool {
@ -538,7 +549,11 @@ pub fn waitpid(pid: pid_t) -> int {
status >> 8i32
}
let status = os::waitpid(pid);
let mut status = 0 as c_int;
if unsafe { waitpid(pid, &mut status, 0) } == -1 {
fail!(fmt!("failure in waitpid: %s", os::last_os_error()));
}
return if WIFEXITED(status) {
WEXITSTATUS(status) as int
} else {
@ -584,7 +599,7 @@ mod tests {
writeclose(pipe_in.out, copy expected);
let actual = readclose(pipe_out.in);
readclose(pipe_err.in);
os::waitpid(pid);
run::waitpid(pid);
debug!(copy expected);
debug!(copy actual);