diff options
author | Daniel McKenna <danielmckenna93@gmail.com> | 2017-06-01 21:34:36 +0100 |
---|---|---|
committer | xd009642 <danielmckenna93@gmail.com> | 2017-06-13 18:16:57 +0100 |
commit | 43a29431b63516b23016aae76d3c15bf083f091c (patch) | |
tree | e4c7221df798f533ed93819281457507b171bd67 /src/lib.rs | |
parent | 6783ffc206de568ca8867abe6133bdad9110211e (diff) | |
download | nix-43a29431b63516b23016aae76d3c15bf083f091c.zip |
Added ptrace utilities.
Some ptrace functions return structures through the data argument. This commit adds utilities to return data through this mechanism and function specialisations for a few of these functions (getting event messages or the siginfo_t struct). Once the next version of libc is released these utilities will be expanded to include the fpregs and user_regs structs.
Ptrace requests that are now satisfied by a more specific public function will return an unsupported operation error. This has involved adding an UnsupportedOperation to the nix::Error enum and removed the mapping from Error to Errno and from Error to std::io::Error.
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 24 |
1 files changed, 5 insertions, 19 deletions
@@ -75,7 +75,6 @@ use std::{ptr, result}; use std::ffi::{CStr, OsStr}; use std::path::{Path, PathBuf}; use std::os::unix::ffi::OsStrExt; -use std::io; use std::fmt; use std::error; use libc::PATH_MAX; @@ -97,6 +96,9 @@ pub enum Error { /// The operation involved a conversion to Rust's native String type, which failed because the /// string did not contain all valid UTF-8. InvalidUtf8, + /// The operation is not supported by Nix, in this instance either use the libc bindings or + /// consult the module documentation to see if there is a more appropriate interface available. + UnsupportedOperation, } impl Error { @@ -116,14 +118,6 @@ impl Error { Error::Sys(errno::EINVAL) } - /// Get the errno associated with this error - pub fn errno(&self) -> errno::Errno { - match *self { - Error::InvalidPath => errno::Errno::EINVAL, - Error::InvalidUtf8 => errno::Errno::UnknownErrno, - Error::Sys(errno) => errno, - } - } } impl From<errno::Errno> for Error { @@ -139,6 +133,7 @@ impl error::Error for Error { match self { &Error::InvalidPath => "Invalid path", &Error::InvalidUtf8 => "Invalid UTF-8 string", + &Error::UnsupportedOperation => "Unsupported Operation", &Error::Sys(ref errno) => errno.desc(), } } @@ -149,21 +144,12 @@ impl fmt::Display for Error { match self { &Error::InvalidPath => write!(f, "Invalid path"), &Error::InvalidUtf8 => write!(f, "Invalid UTF-8 string"), + &Error::UnsupportedOperation => write!(f, "Unsupported Operation"), &Error::Sys(errno) => write!(f, "{:?}: {}", errno, errno.desc()), } } } -impl From<Error> for io::Error { - fn from(err: Error) -> Self { - match err { - Error::InvalidPath => io::Error::new(io::ErrorKind::InvalidInput, err), - Error::InvalidUtf8 => io::Error::new(io::ErrorKind::Other, err), - Error::Sys(errno) => io::Error::from_raw_os_error(errno as i32), - } - } -} - pub trait NixPath { fn len(&self) -> usize; |