Skip to content

Conversation

vilhelmbergsoe
Copy link

Attempt at handling EINTR in the case of a system call interrupt when polling for events.

Fixed an issue with a little program I wrote asciicam, which would panic with the error message "Error: Interrupted system call (os error 4)" when calling stream.next() after and upgrade from 0.13.0 -> 0.14.0.

I don't have a deep understanding of interruptible syscalls, but apparently the event polling from libv4l-rs is also connected to keyboard input in the terminal somehow?

While looking this up I came across a similar issue with crossterm here. They seem to have fixed it by continuing in the loop over polls, the PR is here.

This solution isn't as elegant as I just do a recursive call to poll and hope there isn't an interrupt next time, but it seems to work in my program.

Attempt at handling EINTR in the case of a system call interrupt when
polling for events.
@MarijnS95
Copy link
Collaborator

I think that makes sense, but a loop seems more clean than recursion IMO.

@MarijnS95 MarijnS95 changed the title fix: handle EINTR: device: Retry poll() on interrupts (EINTR) Dec 5, 2023
@vilhelmbergsoe
Copy link
Author

I think that makes sense, but a loop seems more clean than recursion IMO.

Something like this, seem good to you?

@raymanfx
Copy link
Owner

IMO the best way to handle this is at the call site (i.e. your application). The EINTR error will be propagated all the way up by dequeue(), e.g. here for mmap:

fn dequeue(&mut self) -> io::Result<usize> {
. If we do it anywhere in the library, it takes away the option for all users to interrupt the poll() call.

Perhaps I'm missing another aspect of this issue though; feel free to chime in in that case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants