nix-rust / nix

Rust friendly bindings to *nix APIs
MIT License
2.57k stars 650 forks source link

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

Closed zopsicle closed 2 months ago

zopsicle commented 2 months ago

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
        // ...
    }
    // ...
}