EINTR on close() in Linux?

Ketil Froyn (ketil-kernel@froyn.net)
Mon, 22 Jul 2002 12:38:18 +0200 (CEST)


Hi.

After looking at the discussion on errors during close(), I'd like a
clarification. Linus said that Linux ALWAYS tears down the fd when close()
is called, and it returns the error just to notify the application. What
happens if the close() call is interrupted by a signal? Does Linux say
EINTR and close the FD, or will Linux just never say EINTR? To close a fd
a portable program might do something like this:

while (1) {
if (close(fd) == -1) {
if (errno == EINTR) continue;
printf("Barf\n");
exit(1);
}
break;
}

If Linux returns EINTR and tears down the fd, this code is bad because
1) It will die with EBADF the second try, or
2) In a multithreaded app, it might close something it shouldn't

Thanks,
Ketil

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/