2002-07-22 10:34:06

by Ketil Froyn

[permalink] [raw]
Subject: EINTR on close() in Linux?

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


2002-07-22 11:18:48

by Alan

[permalink] [raw]
Subject: Re: EINTR on close() in Linux?

On Mon, 2002-07-22 at 11:38, Ketil Froyn wrote:
>
> If Linux returns EINTR and tears down the fd, this code is bad because

Linux doesn't return -EINTR from close(). It did for a brief while
during development by accident.

While the standard permits it, sanity suggests otherwise (see earlier
discussions)

2002-07-22 10:52:25

by Thunder from the hill

[permalink] [raw]
Subject: [OT] Re: EINTR on close() in Linux?

Hi,

> EINTR

BTW, I'd vote for errno==0 to be called EFINE.

Regards,
Thunder
--
(Use http://www.ebb.org/ungeek if you can't decode)
------BEGIN GEEK CODE BLOCK------
Version: 3.12
GCS/E/G/S/AT d- s++:-- a? C++$ ULAVHI++++$ P++$ L++++(+++++)$ E W-$
N--- o? K? w-- O- M V$ PS+ PE- Y- PGP+ t+ 5+ X+ R- !tv b++ DI? !D G
e++++ h* r--- y-
------END GEEK CODE BLOCK------