1

I have seen code like this:

again:
    if ((n = read(fd, buf, BUFFSIZE)) < 0) {
        if (errno == EINTR)
            goto again;     /* just an interrupted system call */
        /* handle other errors */
    }

The idea is to retry a system call if it fails because it was interrupted. But is it a good idea? When is it a good idea and when should I not do this? Is this specific to certain platforms, or can Windows or Unix have system calls fail with EINTR?

user16217248
  • 3,119
  • 19
  • 19
  • 37
  • 2
    It depends on the platform whether signals will cause the system call to automatically restart or fail with `EINTR`. See [this documentation](https://man7.org/linux/man-pages/man7/signal.7.html) for information specific to Linux. – Andreas Wenzel Jun 20 '21 at 22:02
  • @AndreasWenzel Is there a way to tell? If the system auto retries, then can a function never fail with EINTR because it will always retry until success? – user16217248 Jun 20 '21 at 22:06
  • 1
    The way to tell is to read the documentation. The signal doc link has already been provided for you and each API's doc also tells you whether it can fail with `EINTR`. – kaylum Jun 20 '21 at 22:09

0 Answers0