Skip to content

Commit acc1513

Browse files
committed
fix all and update CHANGELOG.md
1 parent 2d6ffc3 commit acc1513

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3030
([#491](https://github.com/nix-rust/nix/pull/491))
3131

3232
### Changed
33+
- `epoll_ctl` now could accept None as argument `event`
34+
when op is `EpollOp::EpollCtlDel`.
35+
([#480](https://github.com/nix-rust/nix/pull/480))
3336
- Removed the `bad` keyword from the `ioctl!` macro
3437
([#478](https://github.com/nix-rust/nix/pull/478))
3538
- Changed `TimeVal` into an opaque Newtype

src/sys/epoll.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use libc::{self, c_int};
33
use std::os::unix::io::RawFd;
44
use std::ptr;
55
use std::mem;
6+
use ::Error;
67

78
bitflags!(
89
#[repr(C)]
@@ -25,7 +26,7 @@ bitflags!(
2526
}
2627
);
2728

28-
#[derive(Clone, Copy)]
29+
#[derive(Clone, Copy, Eq, PartialEq)]
2930
#[repr(C)]
3031
pub enum EpollOp {
3132
EpollCtlAdd = 1,
@@ -91,8 +92,13 @@ pub fn epoll_create1(flags: EpollCreateFlags) -> Result<RawFd> {
9192
pub fn epoll_ctl<'a, T>(epfd: RawFd, op: EpollOp, fd: RawFd, event: T) -> Result<()>
9293
where T: Into<&'a mut EpollEvent>
9394
{
94-
let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.into().event) };
95-
Errno::result(res).map(drop)
95+
let event: &mut EpollEvent = event.into();
96+
if event as *const EpollEvent == ptr::null() && op != EpollOp::EpollCtlDel {
97+
Err(Error::Sys(Errno::EINVAL))
98+
} else {
99+
let res = unsafe { libc::epoll_ctl(epfd, op as c_int, fd, &mut event.event) };
100+
Errno::result(res).map(drop)
101+
}
96102
}
97103

98104
#[inline]

test/sys/test_epoll.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ pub fn test_epoll_errno() {
99
let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None);
1010
assert!(result.is_err());
1111
assert_eq!(result.unwrap_err(), Error::Sys(Errno::ENOENT));
12+
13+
let result = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, None);
14+
assert!(result.is_err());
15+
assert_eq!(result.unwrap_err(), Error::Sys(Errno::EINVAL));
1216
}
1317

1418
#[test]

0 commit comments

Comments
 (0)