I am programming a user application for a embedded Linux system, and I am using the common functions such as open, close, read, ioctl, etc. for the devices. Now, I read about EINTR, indicates that the function was interrupted by a signal, but I am not sure about the implications. In all the example programs I have, sometimes it is done, e.g. ioctl(), sometimes it is not done, e.g. read(). So, I am a little bit confused.
When do I preferably check for EINTR and repeat the function call?
See sigaction : http://pubs.opengroup.org/onlinepubs/009695399/functions/sigaction.html
SA_RESTART This flag affects the behavior of interruptible functions; that is, those specified to fail with errno set to EINTR. If set, and a function specified as interruptible is interrupted by this signal, the function shall restart and shall not fail with EINTR unless otherwise specified. If the flag is not set, interruptible functions interrupted by this signal shall fail with errno set to EINTR.
By default, you have the SA_RESTART behavior, so you don't have to worry about EINTR, if you don't play with signals.
Is your application event driven? (Meaning its main loop include select()/epoll_wait()
call).
In an event driven application you can block all signals and only unblock them for the duration of pselect()/epoll_pwait()
call. This way the rest of your code never have to deal with EINTR.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With