4

I'm writing a web server in C and I often use system calls that on error return -1 and set "errno" variable an appropriate value. Some system calls can return EINTR and/or EAGAIN. I have two wrappers HANDLE_EINTR, HANDLE_EAGAIN that use both these error values and retry the system call.

The man pages usually refer if a system call returns EINTR and/or EAGAIN but for some system calls it really does not. Also some system calls may return EINTR / EAGAIN not directly but through the failure of other system calls that might be used in it.

I would like to ask if I could use HANDLE_EINTR and/or HANDLE_EAGAIN regardless of what the API declares (which is not always complete).

Also, I know from Google people that using HANDLE_EINTR with "close" system call (although the API refer to use it) is not a good idea, so I do not use it. Are there any other system calls that have this behavior?

Thank you.

1 Answers1

0

The semantics of EINTR and EAGAIN are well defined. If a particular system call is not documented as potentially returning a particular errno, there's no harm in having a handler for it.

It is quite common for large applications to implement a single error handler that takes appropriate action for a wide range of errnos, and use that same error handler to appropriately handle error conditions from many different syscalls, even though a particular system call might not be documented as potentially returning a particular errno.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148
  • 1
    "The semantics of EINTR and EAGAIN are well defined." Well then, please quote or paraphrase this definition. – Kijewski Sep 07 '14 at 14:32
  • So, it could be nice to use the HANDLE_EINTR and HANDLE_EAGAIN macros in any system call that returns -1 with a errno code when an error happens as a catholic practice right? – Efstathios Chatzikyriakidis Sep 07 '14 at 17:39
  • 2
    @EfstathiosChatzikyriakidis, as a rule of thumb: if key-parts of your questions are not solved, then don't mark as solved, but do upvote. Solved questions do not attracts passers-by, who could maybe answer your sub-questions, too. – Kijewski Sep 07 '14 at 20:18