Skip to content

Instantly share code, notes, and snippets.

@asomers
Created July 19, 2017 05:39
Show Gist options
  • Save asomers/198774d364042e85ffcbdb7eaeaa256f to your computer and use it in GitHub Desktop.
Save asomers/198774d364042e85ffcbdb7eaeaa256f to your computer and use it in GitHub Desktop.
Diff that adds debugging info to illustrate test_epoll _ctl code generation bug in nix
diff --git a/src/sys/epoll.rs b/src/sys/epoll.rs
index df48b9a..ae848d2 100644
--- a/src/sys/epoll.rs
+++ b/src/sys/epoll.rs
@@ -98,7 +98,10 @@ pub fn epoll_ctl<'a, T>(epfd: RawFd, op: EpollOp, fd: RawFd, event: T) -> Result
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)
+ println!("libc::epoll_ctl returned {:?}", res);
+ let retval = Errno::result(res).map(drop);
+ println!("in epoll_ctl, retval is {:?}", retval);
+ retval
}
}
diff --git a/test/sys/test_epoll.rs b/test/sys/test_epoll.rs
index a73fea6..11ce875 100644
--- a/test/sys/test_epoll.rs
+++ b/test/sys/test_epoll.rs
@@ -1,11 +1,11 @@
use nix::sys::epoll::{EpollCreateFlags, EpollOp, EpollEvent};
use nix::sys::epoll::{EPOLLIN, EPOLLERR};
use nix::sys::epoll::{epoll_create1, epoll_ctl};
-use nix::{Error, Errno};
+use nix::{Error, Errno, Result};
#[test]
pub fn test_epoll_errno() {
- let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
+ let efd = epoll_create1(EpollCreateFlags::empty()).expect("epoll_create1 failed");
let result = epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None);
assert!(result.is_err());
assert_eq!(result.unwrap_err(), Error::Sys(Errno::ENOENT));
@@ -17,8 +17,14 @@ pub fn test_epoll_errno() {
#[test]
pub fn test_epoll_ctl() {
- let efd = epoll_create1(EpollCreateFlags::empty()).unwrap();
+ let ok : Result<()> = Ok(());
+ let notok: Result<()> = Err(Error::Sys(Errno::UnknownErrno));
+ println!("In test_epoll_ctl, ok is {:?}, notok is {:?}", ok, notok);
+
+ let efd = epoll_create1(EpollCreateFlags::empty()).expect("epoll_create1 failed");
let mut event = EpollEvent::new(EPOLLIN | EPOLLERR, 1);
- epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event).unwrap();
- epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).unwrap();
+ let epoll_ctl_res = epoll_ctl(efd, EpollOp::EpollCtlAdd, 1, &mut event);
+ println!("In test_epoll_ctl, result was {:?}", epoll_ctl_res);
+ epoll_ctl_res.expect("epoll_ctl 1 failed");
+ epoll_ctl(efd, EpollOp::EpollCtlDel, 1, None).expect("epoll_ctl 2 failed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment