Commit 57085c89 authored by gabime's avatar gabime

exclude from compilation prevent_child_fd() if SPDLOG_PREVENT_CHILD_FD not defined

parent d67efb2c
...@@ -126,15 +126,13 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT ...@@ -126,15 +126,13 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT
return gmtime(now_t); return gmtime(now_t);
} }
#ifdef SPDLOG_PREVENT_CHILD_FD
SPDLOG_INLINE void prevent_child_fd(FILE *f) SPDLOG_INLINE void prevent_child_fd(FILE *f)
{ {
#ifdef _WIN32 #ifdef _WIN32
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)
auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(f))); auto file_handle = reinterpret_cast<HANDLE>(_get_osfhandle(::_fileno(f)));
if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0)) if (!::SetHandleInformation(file_handle, HANDLE_FLAG_INHERIT, 0))
SPDLOG_THROW(spdlog_ex("SetHandleInformation failed", errno)); SPDLOG_THROW(spdlog_ex("SetHandleInformation failed", errno));
#endif
#else #else
auto fd = ::fileno(f); auto fd = ::fileno(f);
if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) if (::fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
...@@ -143,6 +141,7 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f) ...@@ -143,6 +141,7 @@ SPDLOG_INLINE void prevent_child_fd(FILE *f)
} }
#endif #endif
} }
#endif //SPDLOG_PREVENT_CHILD_FD
// fopen_s on non windows for writing // fopen_s on non windows for writing
SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode) 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 ...@@ -158,6 +157,7 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
#endif #endif
#ifdef SPDLOG_PREVENT_CHILD_FD #ifdef SPDLOG_PREVENT_CHILD_FD
// prevent child processes from inheriting log file descriptors
if (*fp != nullptr) if (*fp != nullptr)
{ {
prevent_child_fd(*fp); prevent_child_fd(*fp);
......
...@@ -38,7 +38,9 @@ static const char folder_sep = '\\'; ...@@ -38,7 +38,9 @@ static const char folder_sep = '\\';
SPDLOG_CONSTEXPR static const char folder_sep = '/'; SPDLOG_CONSTEXPR static const char folder_sep = '/';
#endif #endif
#ifdef SPDLOG_PREVENT_CHILD_FD
void prevent_child_fd(FILE *f); void prevent_child_fd(FILE *f);
#endif
// fopen_s on non windows for writing // fopen_s on non windows for writing
bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode); bool fopen_s(FILE **fp, const filename_t &filename, const filename_t &mode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment