Skip to content

Commit e08a430

Browse files
committed
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...
2 parents 5d9e1ed + bf93180 commit e08a430

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased]
77

8+
### Changed
9+
- Renamed existing `ptrace` wrappers to encourage namespacing ([#692](https://github.com/nix-rust/nix/pull/692))
10+
811
## [0.9.0] 2017-07-23
912

1013
### Added

src/sys/ptrace.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, dat
108108
}
109109

110110
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
111-
pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
111+
pub fn setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> {
112112
use self::ptrace::*;
113113
use std::ptr;
114114

@@ -117,19 +117,19 @@ pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()>
117117
}
118118

119119
/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)`
120-
pub fn ptrace_getevent(pid: Pid) -> Result<c_long> {
120+
pub fn getevent(pid: Pid) -> Result<c_long> {
121121
use self::ptrace::*;
122122
ptrace_get_data::<c_long>(PTRACE_GETEVENTMSG, pid)
123123
}
124124

125125
/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)`
126-
pub fn ptrace_getsiginfo(pid: Pid) -> Result<siginfo_t> {
126+
pub fn getsiginfo(pid: Pid) -> Result<siginfo_t> {
127127
use self::ptrace::*;
128128
ptrace_get_data::<siginfo_t>(PTRACE_GETSIGINFO, pid)
129129
}
130130

131131
/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)`
132-
pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
132+
pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
133133
use self::ptrace::*;
134134
let ret = unsafe{
135135
Errno::clear();

test/sys/test_ptrace.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
use nix::Error;
2-
use nix::errno::*;
3-
use nix::unistd::*;
4-
use nix::sys::ptrace::*;
5-
use nix::sys::ptrace::ptrace::*;
2+
use nix::errno::Errno;
3+
use nix::unistd::getpid;
4+
use nix::sys::ptrace;
65

76
use std::{mem, ptr};
87

98
#[test]
109
fn test_ptrace() {
10+
use nix::sys::ptrace::ptrace::PTRACE_ATTACH;
1111
// Just make sure ptrace can be called at all, for now.
1212
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS
13-
let err = ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
13+
let err = ptrace::ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
1414
assert!(err == Error::Sys(Errno::EPERM) || err == Error::Sys(Errno::ENOSYS));
1515
}
1616

1717
// Just make sure ptrace_setoptions can be called at all, for now.
1818
#[test]
1919
fn test_ptrace_setoptions() {
20-
let err = ptrace_setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err();
20+
use nix::sys::ptrace::ptrace::PTRACE_O_TRACESYSGOOD;
21+
let err = ptrace::setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err();
2122
assert!(err != Error::UnsupportedOperation);
2223
}
2324

2425
// Just make sure ptrace_getevent can be called at all, for now.
2526
#[test]
2627
fn test_ptrace_getevent() {
27-
let err = ptrace_getevent(getpid()).unwrap_err();
28+
let err = ptrace::getevent(getpid()).unwrap_err();
2829
assert!(err != Error::UnsupportedOperation);
2930
}
3031

3132
// Just make sure ptrace_getsiginfo can be called at all, for now.
3233
#[test]
3334
fn test_ptrace_getsiginfo() {
34-
match ptrace_getsiginfo(getpid()) {
35+
match ptrace::getsiginfo(getpid()) {
3536
Err(Error::UnsupportedOperation) => panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"),
3637
_ => (),
3738
}
@@ -41,7 +42,7 @@ fn test_ptrace_getsiginfo() {
4142
#[test]
4243
fn test_ptrace_setsiginfo() {
4344
let siginfo = unsafe { mem::uninitialized() };
44-
match ptrace_setsiginfo(getpid(), &siginfo) {
45+
match ptrace::setsiginfo(getpid(), &siginfo) {
4546
Err(Error::UnsupportedOperation) => panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!"),
4647
_ => (),
4748
}

test/sys/test_wait.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn test_wait_exit() {
4141
// FIXME: qemu-user doesn't implement ptrace on most arches
4242
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
4343
mod ptrace {
44-
use nix::sys::ptrace::*;
44+
use nix::sys::ptrace;
4545
use nix::sys::ptrace::ptrace::*;
4646
use nix::sys::signal::*;
4747
use nix::sys::wait::*;
@@ -51,7 +51,7 @@ mod ptrace {
5151
use libc::_exit;
5252

5353
fn ptrace_child() -> ! {
54-
let _ = ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut());
54+
ptrace::ptrace(PTRACE_TRACEME, Pid::from_raw(0), ptr::null_mut(), ptr::null_mut()).unwrap();
5555
// As recommended by ptrace(2), raise SIGTRAP to pause the child
5656
// until the parent is ready to continue
5757
let _ = raise(SIGTRAP);
@@ -62,16 +62,16 @@ mod ptrace {
6262
// Wait for the raised SIGTRAP
6363
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, SIGTRAP)));
6464
// We want to test a syscall stop and a PTRACE_EVENT stop
65-
assert!(ptrace_setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());
65+
assert!(ptrace::setoptions(child, PTRACE_O_TRACESYSGOOD | PTRACE_O_TRACEEXIT).is_ok());
6666

6767
// First, stop on the next system call, which will be exit()
68-
assert!(ptrace(PTRACE_SYSCALL, child, ptr::null_mut(), ptr::null_mut()).is_ok());
68+
assert!(ptrace::ptrace(PTRACE_SYSCALL, child, ptr::null_mut(), ptr::null_mut()).is_ok());
6969
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceSyscall(child)));
7070
// Then get the ptrace event for the process exiting
71-
assert!(ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
71+
assert!(ptrace::ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
7272
assert_eq!(waitpid(child, None), Ok(WaitStatus::PtraceEvent(child, SIGTRAP, PTRACE_EVENT_EXIT)));
7373
// Finally get the normal wait() result, now that the process has exited
74-
assert!(ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
74+
assert!(ptrace::ptrace(PTRACE_CONT, child, ptr::null_mut(), ptr::null_mut()).is_ok());
7575
assert_eq!(waitpid(child, None), Ok(WaitStatus::Exited(child, 0)));
7676
}
7777

0 commit comments

Comments
 (0)