eintr

When to check for EINTR and repeat the function call?

不羁岁月 提交于 2019-12-28 05:37:06
问题 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? 回答1:

Handling EINTR (with goto?)

不想你离开。 提交于 2019-12-23 16:13:30
问题 Background: This is a follow-up question to this thread about handling EINTR for system calls in C++ (Linux/GCC). Regardless of whether or not I intend to profile my application, it seems like I should be handling system calls setting errno to EINTR as a special case. There are many, many, many opinions about the use of goto . My question: is a system call setting errno to EINTR a case where goto is considered nominal? If not, then how would you suggest converting the following code to handle

Unit testing error conditions - EINTR

丶灬走出姿态 提交于 2019-12-22 04:45:09
问题 In short, how do you unit test an error condition such as EINTR on a system call. One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose: // Given an open FILE *fp while (fclose(fp)==EOF && errno==EINTR) { errno = 0; } This call can be unsafe if fp freed when EINTR occurs. How can I test the error handling for when (errno==EINTR)?

Unit testing error conditions - EINTR

点点圈 提交于 2019-12-05 05:30:12
In short, how do you unit test an error condition such as EINTR on a system call. One particular example I'm working on, which could be a case all by itself, is whether it's necessary to call fclose again when it returns EOF with (errno==EINTR). The behavior depends on the implementation of fclose: // Given an open FILE *fp while (fclose(fp)==EOF && errno==EINTR) { errno = 0; } This call can be unsafe if fp freed when EINTR occurs. How can I test the error handling for when (errno==EINTR)? In this particular case, it's not safe to call fclose() again, as the C standard says the stream is

System call interrupted by a signal still has to be completed

烈酒焚心 提交于 2019-12-01 03:05:02
A lot of system calls like close( fd ) Can be interrupted by a signal. In this case usually -1 is returned and errno is set EINTR . The question is what is the right thing to do? Say, I still want this fd to be closed. What I can come up with is: while( close( fd ) == -1 ) if( errno != EINTR ) { ReportError(); break; } Can anybody suggest a better/more elegant/standard way to handle this situation? UPDATE: As noticed by mux, SA_ RESTART flag can be used when installing the signal handler. Can somebody tell me which functions are guaranteed to be restartable on all POSIX systems(not only Linux

System call interrupted by a signal still has to be completed

允我心安 提交于 2019-11-30 23:15:01
问题 A lot of system calls like close( fd ) Can be interrupted by a signal. In this case usually -1 is returned and errno is set EINTR . The question is what is the right thing to do? Say, I still want this fd to be closed. What I can come up with is: while( close( fd ) == -1 ) if( errno != EINTR ) { ReportError(); break; } Can anybody suggest a better/more elegant/standard way to handle this situation? UPDATE: As noticed by mux, SA_ RESTART flag can be used when installing the signal handler. Can

When to check for EINTR and repeat the function call?

守給你的承諾、 提交于 2019-11-27 20:00:53
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? Yann Droneaud See sigaction : http://pubs.opengroup.org/onlinepubs/009695399/functions/sigaction.html SA