summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2017-07-25 16:28:59 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2017-07-25 16:28:59 +0000
commite08a430226a3b823278795fe8671c264f9ae6594 (patch)
tree0576375c614c6bfb82a88a96d2b7032fa95efc1e
parent5d9e1edf73ac5ed8f9138099ac31afbd9b649546 (diff)
parentbf93180babacbe0d82543f9c5d487cbffdb47546 (diff)
downloadnix-e08a430226a3b823278795fe8671c264f9ae6594.zip
Merge #692
692: Rename the public ptrace_* functions. r=Susurrus Unlike in C, we have namespacing in Rust. Renaming the functions allows us to avoid a `use nix::sys::ptrace::*` in favor of `use nix::sys::ptrace` and then calling, for example, `ptrace::traceme()` I'm wondering if we should rename the private functions too...
-rw-r--r--CHANGELOG.md3
-rw-r--r--src/sys/ptrace.rs8
-rw-r--r--test/sys/test_ptrace.rs19
-rw-r--r--test/sys/test_wait.rs12
4 files changed, 23 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 97d83504..d5064c9c 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
+### Changed
+- Renamed existing `ptrace` wrappers to encourage namespacing ([#692](https://github.com/nix-rust/nix/pull/692))
+
## [0.9.0] 2017-07-23
### Added
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs
index 73ca9160..877bfcb0 100644
--- a/src/sys/ptrace.rs
+++ b/src/sys/ptrace.rs
@@ -108,7 +108,7 @@ fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, dat
}
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
-pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
+pub fn setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
use self::ptrace::*;
use std::ptr;
@@ -117,19 +117,19 @@ pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()>
}
/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)`
-pub fn ptrace_getevent(pid: Pid) -> Result<c_long> {
+pub fn getevent(pid: Pid) -> Result<c_long> {
use self::ptrace::*;
ptrace_get_data::<c_long>(PTRACE_GETEVENTMSG, pid)
}
/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)`
-pub fn ptrace_getsiginfo(pid: Pid) -> Result<siginfo_t> {
+pub fn getsiginfo(pid: Pid) -> Result<siginfo_t> {
use self::ptrace::*;
ptrace_get_data::<siginfo_t>(PTRACE_GETSIGINFO, pid)
}
/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)`
-pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
+pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
use self::ptrace::*;
let ret = unsafe{
Errno::clear();
diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs
index 57b452cb..0614c13f 100644
--- a/test/sys/test_ptrace.rs
+++ b/test/sys/test_ptrace.rs
@@ -1,37 +1,38 @@
use nix::Error;
-use nix::errno::*;
-use nix::unistd::*;
-use nix::sys::ptrace::*;
-use nix::sys::ptrace::ptrace::*;
+use nix::errno::Errno;
+use nix::unistd::getpid;
+use nix::sys::ptrace;
use std::{mem, ptr};
#[test]
fn test_ptrace() {
+ use nix::sys::ptrace::ptrace::PTRACE_ATTACH;
// Just make sure ptrace can be called at all, for now.
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS
- let err = ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
+ let err = ptrace::ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
assert!(err == Error::Sys(Errno::EPERM) || err == Error::Sys(Errno::ENOSYS));
}
// Just make sure ptrace_setoptions can be called at all, for now.
#[test]
fn test_ptrace_setoptions() {
- let err = ptrace_setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err();
+ use nix::sys::ptrace::ptrace::PTRACE_O_TRACESYSGOOD;
+ let err = ptrace::setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err();
assert!(err != Error::UnsupportedOperation);
}
// Just make sure ptrace_getevent can be called at all, for now.
#[test]
fn test_ptrace_getevent() {
- let err = ptrace_getevent(getpid()).unwrap_err();
+ let err = ptrace::getevent(getpid()).unwrap_err();
assert!(err != Error::UnsupportedOperation);
}
// Just make sure ptrace_getsiginfo can be called at all, for now.
#[test]
fn test_ptrace_getsiginfo() {
- match ptrace_getsiginfo(getpid()) {
+ match ptrace::getsiginfo(getpid()) {
Err(Error::UnsupportedOperation) => panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"),
_ => (),
}
@@ -41,7 +42,7 @@ fn test_ptrace_getsiginfo() {
#[test]
fn test_ptrace_setsiginfo() {
let siginfo = unsafe { mem::uninitialized() };
- match ptrace_setsiginfo(getpid(), &siginfo) {
+ match ptrace::setsiginfo(getpid(), &siginfo) {
Err(Error::UnsupportedOperation) => panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!"),
_ => (),
}
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index 210e6bc8..8d2ca85f 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -41,7 +41,7 @@ fn test_wait_exit() {
// FIXME: qemu-user doesn't implement ptrace on most arches
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod ptrace {
- use nix::sys::ptrace::*;
+ use nix::sys::ptrace;
use nix::sys::ptrace::ptrace::*;
use nix::sys::signal::*;
use nix::sys::wait::*;
@@ -51,7 +51,7 @@ mod ptrace {
use libc::_exit;
fn ptrace_child() -> ! {
- let _ = ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut());
+ ptrace::ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut()).unwrap();
// As recommended by ptrace(2), raise SIGTRAP to pause the child
// until the parent is ready to continue
let _ = raise(SIGTRAP);
@@ -62,16 +62,16 @@ mod ptrace {
// Wait for the raised SIGTRAP
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, SIGTRAP)));
// We want to test a syscall stop and a PTRACE_EVENT stop
- assert!(ptrace_setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());
+ assert!(ptrace::setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());
// First, stop on the next system call, which will be exit()
- assert!(ptrace(PTRACE_SYSCALL, child, ptr::null_mut(), ptr::null_mut()).is_ok());
+ assert!(ptrace::ptrace(PTRACE_SYSCALL, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child)));
// Then get the ptrace event for the process exiting
- assert!(ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
+ assert!(ptrace::ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceEvent(child, SIGTRAP, PTRACE_EVENT_EXIT)));
// Finally get the normal wait() result, now that the process has exited
- assert!(ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
+ assert!(ptrace::ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
}