From 0a85228ff762b77de2d47119d1379e7ca6f48eb8 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 11 Oct 2015 04:13:13 +0200 Subject: Whilst POSIX leaves it explicitly unspecify whether close(2) closes the fildes on interruption, Linux (and possibly some other kernels) specify that it does close. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsclient/comm.c | 7 +------ src/libmdsserver/macros.h | 24 ++++++++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/libmdsclient/comm.c b/src/libmdsclient/comm.c index 6c72e9f..7a3ba20 100644 --- a/src/libmdsclient/comm.c +++ b/src/libmdsclient/comm.c @@ -86,12 +86,7 @@ void libmds_connection_destroy(libmds_connection_t* restrict this) if (this->socket_fd >= 0) { - while (close(this->socket_fd)) - { - if (errno == EINTR) - continue; - break; /* errno may be EBADF or EIO. */ - } + close(this->socket_fd); /* TODO Linux closes the filedescriptor on EINTR, but POSIX does not require that. */ this->socket_fd = -1; } diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index c42ef21..71d26f1 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -396,12 +396,16 @@ * * @param fd:int The file descriptor */ -#ifdef MDS_LIBMDSSERVER_MACROS_DEFINED_TEMP_FAILURE_RETRY -# define xclose(fd) \ +#if 1 /* For kernels that ensure that close(2) always closes valid file descriptors. */ +# define xclose(fd) close(fd) +#else /* For kernels that ensure that close(2) never closes valid file descriptors on interruption. */ +# ifdef MDS_LIBMDSSERVER_MACROS_DEFINED_TEMP_FAILURE_RETRY +# define xclose(fd) \ TEMP_FAILURE_RETRY(close(fd)) -#else -# define xclose(fd) \ +# else +# define xclose(fd) \ (TEMP_FAILURE_RETRY(close(fd)) < 0 ? 0 : (errno = 0)) +# endif #endif @@ -411,12 +415,16 @@ * * @param f:FILE* The stream */ -#ifdef MDS_LIBMDSSERVER_MACROS_DEFINED_TEMP_FAILURE_RETRY -# define xfclose(f) \ +#if 1 /* For kernels that ensure that close(2) always closes valid file descriptors. */ +# define xfclose(f) fclose(f) +#else /* For kernels that ensure that close(2) never closes valid file descriptors on interruption. */ +# ifdef MDS_LIBMDSSERVER_MACROS_DEFINED_TEMP_FAILURE_RETRY +# define xfclose(f) \ TEMP_FAILURE_RETRY(fclose(f)) -#else -# define xfclose(f) \ +# else +# define xfclose(f) \ (TEMP_FAILURE_RETRY(fclose(f)) < 0 ? 0 : (errno = 0)) +# endif #endif -- cgit v1.2.3-70-g09d2