Use O_CLOEXEC instead of the non-atomic ioctl fioclex

This commit is contained in:
Corey Richardson 2017-04-27 20:13:32 -04:00
parent 60a7523d4b
commit 0c166f7726
No known key found for this signature in database
GPG key ID: A89E9F8FB71E9B8B

View file

@ -699,12 +699,11 @@ impl Device {
};
// FIXME: only need for writing is for setting LED values. re-evaluate always using RDWR
// later.
let fd = Fd(unsafe { libc::open(cstr.as_ptr(), libc::O_NONBLOCK | libc::O_RDWR, 0) });
let fd = Fd(unsafe { libc::open(cstr.as_ptr(), libc::O_NONBLOCK | libc::O_RDWR | libc::O_CLOEXEC, 0) });
if *fd == -1 {
std::mem::forget(fd);
return Err(Error::LibcError(errno::errno()))
}
do_ioctl!(fioclex(*fd)); // non-atomic :( but no O_CLOEXEC yet.
let mut dev = Device {
fd: *fd,