From 57085c892f9cc4cd36f9738109864a78ec7d7e3f Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 4 Nov 2019 16:42:58 +0200 Subject: [PATCH] exclude from compilation prevent_child_fd() if SPDLOG_PREVENT_CHILD_FD not defined --- include/spdlog/details/os-inl.h | 6 +++--- include/spdlog/details/os.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 6f5ee52b..a6714ce0 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -126,15 +126,13 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT return gmtime(now_t); } +#ifdef SPDLOG_PREVENT_CHILD_FD SPDLOG_INLINE void prevent_child_fd(FILE *f) { - #ifdef _WIN32 -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM) auto file_handle = reinterpret_cast(_get_osfhandle(::_fileno(f))); if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) SPDLOG_THROW(spdlog_ex("SetHandleInformation failed", errno)); -#endif #else auto fd = ::fileno(f); if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) @@ -143,6 +141,7 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f) } #endif } +#endif //SPDLOG_PREVENT_CHILD_FD // fopen_s on non windows for writing SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) @@ -158,6 +157,7 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename #endif #ifdef SPDLOG_PREVENT_CHILD_FD + // prevent child processes from inheriting log file descriptors if (*fp != nullptr) { prevent_child_fd(*fp); diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index e275a40f..0b1e6006 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -38,7 +38,9 @@ static const char folder_sep = '\\'; SPDLOG_CONSTEXPR static const char folder_sep = '/'; #endif +#ifdef SPDLOG_PREVENT_CHILD_FD void prevent_child_fd(FILE *f); +#endif // fopen_s on non windows for writing bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);