nix-rust / nix

Rust friendly bindings to *nix APIs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SignalFd::read_signal should take &self, not &mut self

zopsicle opened this issue · comments

Currently it is not possible to read a signal while the SignalFd is borrowed, but there is no reason why this shouldn't be allowed. Compare with impl Read for &std::fs::File.

Real-world example:

// immutable borrow occurs here (through BorrowedFd)
let mut fds = [PollFd::new(signalfd.as_fd(), PollFlags::POLLIN), /* ... */];
loop {
    poll(&mut fds, PollTimeout::NONE)?;
    if fds[0].revents().unwrap().contains(PollFlags::POLLIN) {
        signalfd.read_signal()?;  // mutable borrow occurs here
		// ...
    }
	// ...
}