diff options
-rw-r--r-- | CHANGELOG.md | 3 | ||||
-rw-r--r-- | src/sys/epoll.rs | 12 | ||||
-rw-r--r-- | test/sys/test_epoll.rs | 4 |
3 files changed, 16 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ff9cf7a..43f33569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#491](https://github.com/nix-rust/nix/pull/491)) ### Changed +- `epoll_ctl` now could accept None as argument `event` + when op is `EpollOp::EpollCtlDel`. + ([#480](https://github.com/nix-rust/nix/pull/480)) - Removed the `bad` keyword from the `ioctl!` macro ([#478](https://github.com/nix-rust/nix/pull/478)) - Changed `TimeVal` into an opaque Newtype diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs index 1f2054a1..eb28ffb9 100644 --- a/src/sys/epoll.rs +++ b/src/sys/epoll.rs @@ -3,6 +3,7 @@ use libc::{self, c_int}; use std::os::unix::io::RawFd; use std::ptr; use std::mem; +use ::Error; bitflags!( #[repr(C)] @@ -25,7 +26,7 @@ bitflags!( } ); -#[derive(Clone, Copy)] +#[derive(Clone, Copy, Eq, PartialEq)] #[repr(C)] pub enum EpollOp { EpollCtlAdd = 1, @@ -91,8 +92,13 @@ pub fn epoll_create1(flags: EpollCreateFlags) -> Result<RawFd> { pub fn epoll_ctl<'a, T>(epfd: RawFd, op: EpollOp, fd: RawFd, event: T) -> Result<()> where T: Into<&'a mut EpollEvent> { - let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.into().event) }; - Errno::result(res).map(drop) + let event: &mut EpollEvent = event.into(); + if event as *const EpollEvent == ptr::null() && op != EpollOp::EpollCtlDel { + Err(Error::Sys(Errno::EINVAL)) + } else { + let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event) }; + Errno::result(res).map(drop) + } } #[inline] diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs index f31d874f..a73fea6d 100644 --- a/test/sys/test_epoll.rs +++ b/test/sys/test_epoll.rs @@ -9,6 +9,10 @@ pub fn test_epoll_errno() { let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None); assert!(result.is_err()); assert_eq!(result.unwrap_err(), Error::Sys(Errno::ENOENT)); + + let result = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, None); + assert!(result.is_err()); + assert_eq!(result.unwrap_err(), Error::Sys(Errno::EINVAL)); } #[test] |