diff options
author | Markus Jais <markusjais@gmx.de> | 2015-05-19 20:38:52 +0200 |
---|---|---|
committer | Markus Jais <markusjais@gmx.de> | 2015-05-19 20:38:52 +0200 |
commit | f2ca2b0d3c5011383b7398bbbd5d81314ad5e88f (patch) | |
tree | a480fbe3024f0d02b53f10fbded7bde7e3441af2 | |
parent | a0073d1f9f7c98a0dcef84fe5c152340906a825c (diff) | |
download | nix-f2ca2b0d3c5011383b7398bbbd5d81314ad5e88f.zip |
added getpid and getppid
-rw-r--r-- | src/unistd.rs | 11 | ||||
-rw-r--r-- | test/test_unistd.rs | 8 |
2 files changed, 18 insertions, 1 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index a4e37412..1852721d 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -14,7 +14,7 @@ pub use self::linux::*; mod ffi { use libc::{c_char, c_int, size_t}; pub use libc::{close, read, write, pipe, ftruncate, unlink}; - pub use libc::funcs::posix88::unistd::fork; + pub use libc::funcs::posix88::unistd::{fork, getpid, getppid}; extern { // duplicate a file descriptor @@ -88,6 +88,15 @@ pub fn fork() -> Result<Fork> { } #[inline] +pub fn getpid() -> pid_t { + unsafe { ffi::getpid() } // no error handling, according to man page: "These functions are always successful." +} +#[inline] +pub fn getppid() -> pid_t { + unsafe { ffi::getppid() } // no error handling, according to man page: "These functions are always successful." +} + +#[inline] pub fn dup(oldfd: Fd) -> Result<Fd> { let res = unsafe { ffi::dup(oldfd) }; diff --git a/test/test_unistd.rs b/test/test_unistd.rs index 5c0076c9..50af197c 100644 --- a/test/test_unistd.rs +++ b/test/test_unistd.rs @@ -29,6 +29,14 @@ fn test_fork_and_waitpid() { } } +#[test] +fn test_getpid() { + let pid = getpid(); + let ppid = getppid(); + assert!(pid > 0); + assert!(ppid > 0); +} + macro_rules! execve_test_factory( ($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => ( #[test] |