Skip to content

Commit

Permalink
Auto merge of #293 - dhylands:gettid, r=kamalmarhubi
Browse files Browse the repository at this point in the history
Add gettid

I tested this under linux, and I noticed that this seems to also be built for OSX. It would be appreciated if someone could test this under OSX.

I'm not familiar enough with rust to know if there is a way of integrating this without creating a sub-crate.
homu committed Mar 8, 2016
2 parents 3f0c3e1 + ca75212 commit 1380807
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ preadv_pwritev = []
signalfd = []

[dependencies]
libc = "0.2.7"
libc = "0.2.8"
bitflags = "0.4"
cfg-if = "0.1.0"

6 changes: 6 additions & 0 deletions src/unistd.rs
Original file line number Diff line number Diff line change
@@ -56,6 +56,12 @@ pub fn setpgid(pid: pid_t, pgid: pid_t) -> Result<()> {
Errno::result(res).map(drop)
}

#[cfg(any(target_os = "linux", target_os = "android"))]
#[inline]
pub fn gettid() -> pid_t {
unsafe { libc::syscall(libc::SYS_gettid) as pid_t } // no error handling, according to man page: "These functions are always successful."
}

#[inline]
pub fn dup(oldfd: RawFd) -> Result<RawFd> {
let res = unsafe { libc::dup(oldfd) };
11 changes: 11 additions & 0 deletions test/test_unistd.rs
Original file line number Diff line number Diff line change
@@ -54,6 +54,17 @@ fn test_getpid() {
assert!(ppid > 0);
}

#[cfg(any(target_os = "linux", target_os = "android"))]
mod linux_android {
use nix::unistd::gettid;

#[test]
fn test_gettid() {
let tid = gettid();
assert!(tid > 0);
}
}

macro_rules! execve_test_factory(
($test_name:ident, $syscall:ident, $unix_sh:expr, $android_sh:expr) => (
#[test]

0 comments on commit 1380807

Please sign in to comment.