Skip to content

Commit b7fcd97

Browse files
committed
Do not retry close() on EINTR
This would represent file descriptor corruption in a multi-threaded program (since the file descriptor number could be reused), but as Postgres has no such execution such a loop seems harmless for now: the second loop after EINTR would result in a prectable EBADF and then subsequently exit.
1 parent a039c5f commit b7fcd97

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

pg_logfebe.c

+10-16
Original file line numberDiff line numberDiff line change
@@ -293,22 +293,16 @@ closeSocket(int *fd)
293293
{
294294
const int save_errno = errno;
295295

296-
do
297-
{
298-
errno = 0;
299-
300-
/*
301-
* Ignore errors except EINTR: other than EINTR, there is no
302-
* obvious handling one can do from a failed close() that matters
303-
* in this case.
304-
*/
305-
close(*fd);
306-
307-
if (errno == EINTR)
308-
continue;
309-
310-
*fd = -1;
311-
} while (*fd >= 0);
296+
/*
297+
* Close *fd and ignore EINTR, on advice from libusual's
298+
* "safe_close" function:
299+
*
300+
* POSIX says close() can return EINTR but fd state is "undefined"
301+
* later. Seems Linux and BSDs close the fd anyway and EINTR is
302+
* simply informative. Thus retry is dangerous.
303+
*/
304+
close(*fd);
305+
*fd = -1;
312306

313307
errno = save_errno;
314308
}

0 commit comments

Comments
 (0)