Skip to content

Commit 690120d

Browse files
garethgareth
gareth
authored and
gareth
committed
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.
1 parent 91aeecf commit 690120d

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

src/libcore/os.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub mod rustrt {
6060
unsafe fn rust_get_argv() -> **c_char;
6161
unsafe fn rust_path_is_dir(path: *libc::c_char) -> c_int;
6262
unsafe fn rust_path_exists(path: *libc::c_char) -> c_int;
63-
unsafe fn rust_process_wait(pid: c_int) -> c_int;
6463
unsafe fn rust_set_exit_status(code: libc::intptr_t);
6564
}
6665
}
@@ -352,31 +351,6 @@ pub fn fsync_fd(fd: c_int, _l: io::fsync::Level) -> c_int {
352351
}
353352
}
354353

355-
356-
#[cfg(windows)]
357-
pub fn waitpid(pid: pid_t) -> c_int {
358-
unsafe {
359-
let status = rustrt::rust_process_wait(pid);
360-
if status < 0 {
361-
fail!(fmt!("failure in rust_process_wait: %s", last_os_error()));
362-
}
363-
return status;
364-
}
365-
}
366-
367-
#[cfg(unix)]
368-
pub fn waitpid(pid: pid_t) -> c_int {
369-
unsafe {
370-
use libc::funcs::posix01::wait::*;
371-
let mut status = 0 as c_int;
372-
373-
assert!((waitpid(pid, &mut status, 0 as c_int) !=
374-
(-1 as c_int)));
375-
return status;
376-
}
377-
}
378-
379-
380354
pub struct Pipe { mut in: c_int, mut out: c_int }
381355

382356
#[cfg(unix)]

src/libcore/run.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub mod rustrt {
3636
in_fd: c_int,
3737
out_fd: c_int,
3838
err_fd: c_int) -> run::RunProgramResult;
39+
unsafe fn rust_process_wait(pid: c_int) -> c_int;
3940
}
4041
}
4142

@@ -503,17 +504,27 @@ pub fn readclose(fd: c_int) -> ~str {
503504
}
504505
}
505506

506-
/// Waits for a process to exit and returns the exit code
507+
/**
508+
* Waits for a process to exit and returns the exit code, failing
509+
* if there is no process with the specified id.
510+
*/
507511
pub fn waitpid(pid: pid_t) -> int {
508512
return waitpid_os(pid);
509513

510514
#[cfg(windows)]
511515
fn waitpid_os(pid: pid_t) -> int {
512-
os::waitpid(pid) as int
516+
let status = unsafe { rustrt::rust_process_wait(pid) };
517+
if status < 0 {
518+
fail!(fmt!("failure in rust_process_wait: %s", os::last_os_error()));
519+
}
520+
return status as int;
513521
}
514522

515523
#[cfg(unix)]
516524
fn waitpid_os(pid: pid_t) -> int {
525+
526+
use libc::funcs::posix01::wait::*;
527+
517528
#[cfg(target_os = "linux")]
518529
#[cfg(target_os = "android")]
519530
fn WIFEXITED(status: i32) -> bool {
@@ -538,7 +549,11 @@ pub fn waitpid(pid: pid_t) -> int {
538549
status >> 8i32
539550
}
540551

541-
let status = os::waitpid(pid);
552+
let mut status = 0 as c_int;
553+
if unsafe { waitpid(pid, &mut status, 0) } == -1 {
554+
fail!(fmt!("failure in waitpid: %s", os::last_os_error()));
555+
}
556+
542557
return if WIFEXITED(status) {
543558
WEXITSTATUS(status) as int
544559
} else {
@@ -584,7 +599,7 @@ mod tests {
584599
writeclose(pipe_in.out, copy expected);
585600
let actual = readclose(pipe_out.in);
586601
readclose(pipe_err.in);
587-
os::waitpid(pid);
602+
run::waitpid(pid);
588603

589604
debug!(copy expected);
590605
debug!(copy actual);

0 commit comments

Comments
 (0)