From 9f701ccbd230aa9079dda8157258022de22bd4e0 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Sun, 11 Dec 2016 13:30:52 +0100 Subject: [PATCH] Moved set_close_on_exec to new file --- Makefile | 1 + src/httplib_set_close_on_exec.c | 56 +++++++++++++++++++++++++++++++++ src/libhttp.c | 22 ------------- 3 files changed, 57 insertions(+), 22 deletions(-) create mode 100644 src/httplib_set_close_on_exec.c diff --git a/Makefile b/Makefile index ad1b15e7..bb7d551a 100644 --- a/Makefile +++ b/Makefile @@ -146,6 +146,7 @@ LIB_SOURCES = src/libhttp.c \ src/httplib_send_websocket_handshake.c \ src/httplib_set_acl_option.c \ src/httplib_set_auth_handler.c \ + src/httplib_set_close_on_exec.c \ src/httplib_set_gpass_option.c \ src/httplib_set_handler_type.c \ src/httplib_set_non_blocking_mode.c \ diff --git a/src/httplib_set_close_on_exec.c b/src/httplib_set_close_on_exec.c new file mode 100644 index 00000000..f012eb4d --- /dev/null +++ b/src/httplib_set_close_on_exec.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2016 Lammert Bies + * Copyright (c) 2013-2016 the Civetweb developers + * Copyright (c) 2004-2013 Sergey Lyubka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + + +#include "libhttp-private.h" + + +#if defined(_WIN32) + +/* conn parameter may be NULL */ +void XX_httplib_set_close_on_exec( SOCKET sock, struct mg_connection *conn ) { + + (void)conn; /* Unused. */ +#if defined(_WIN32_WCE) + (void)sock; +#else + SetHandleInformation((HANDLE)(intptr_t)sock, HANDLE_FLAG_INHERIT, 0); +#endif + +} /* XX_httplib_set_close_on_exec */ + + +#else + +/* conn may be NULL */ +void XX_httplib_set_close_on_exec( SOCKET fd, struct mg_connection *conn ) { + + if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { + if (conn) { mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO)); } + } + +} /* XX_httplib_set_close_on_exec */ + +#endif /* _WIN32 */ diff --git a/src/libhttp.c b/src/libhttp.c index c1226db8..53138686 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -2156,19 +2156,6 @@ static int poll(struct pollfd *pfd, unsigned int n, int milliseconds) { #pragma GCC diagnostic pop #endif -/* conn parameter may be NULL */ -void XX_httplib_set_close_on_exec( SOCKET sock, struct mg_connection *conn ) { - - (void)conn; /* Unused. */ -#if defined(_WIN32_WCE) - (void)sock; -#else - SetHandleInformation((HANDLE)(intptr_t)sock, HANDLE_FLAG_INHERIT, 0); -#endif - -} /* XX_httplib_set_close_on_exec */ - - #else int XX_httplib_stat( struct mg_connection *conn, const char *path, struct file *filep ) { @@ -2191,13 +2178,4 @@ int XX_httplib_stat( struct mg_connection *conn, const char *path, struct file * } /* XX_httplib_stat */ -/* conn may be NULL */ -void XX_httplib_set_close_on_exec( SOCKET fd, struct mg_connection *conn ) { - - if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) { - if (conn) { mg_cry(conn, "%s: fcntl(F_SETFD FD_CLOEXEC) failed: %s", __func__, strerror(ERRNO)); } - } - -} /* XX_httplib_set_close_on_exec */ - #endif /* _WIN32 */