Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
d4ce9386
Unverified
Commit
d4ce9386
authored
Feb 08, 2020
by
Gabi Melman
Committed by
GitHub
Feb 08, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1423 from dominicpoeschko/patch-1
Properly handling SPDLOG_PREVENT_CHILD_FD
parents
f3d99f41
033fe9f1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
28 deletions
+25
-28
include/spdlog/details/os-inl.h
include/spdlog/details/os-inl.h
+25
-24
include/spdlog/details/os.h
include/spdlog/details/os.h
+0
-4
No files found.
include/spdlog/details/os-inl.h
View file @
d4ce9386
...
@@ -126,23 +126,6 @@ SPDLOG_INLINE std::tm gmtime() SPDLOG_NOEXCEPT
...
@@ -126,23 +126,6 @@ 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
)
{
#ifdef _WIN32
auto
file_handle
=
reinterpret_cast
<
HANDLE
>
(
_get_osfhandle
(
::
_fileno
(
f
)));
if
(
!::
SetHandleInformation
(
file_handle
,
HANDLE_FLAG_INHERIT
,
0
))
SPDLOG_THROW
(
spdlog_ex
(
"SetHandleInformation failed"
,
errno
));
#else
auto
fd
=
::
fileno
(
f
);
if
(
::
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
)
==
-
1
)
{
SPDLOG_THROW
(
spdlog_ex
(
"fcntl with FD_CLOEXEC failed"
,
errno
));
}
#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
)
{
{
...
@@ -152,17 +135,35 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
...
@@ -152,17 +135,35 @@ SPDLOG_INLINE bool fopen_s(FILE **fp, const filename_t &filename, const filename
#else
#else
*
fp
=
::
_fsopen
((
filename
.
c_str
()),
mode
.
c_str
(),
_SH_DENYNO
);
*
fp
=
::
_fsopen
((
filename
.
c_str
()),
mode
.
c_str
(),
_SH_DENYNO
);
#endif
#endif
#else // unix
#if defined(SPDLOG_PREVENT_CHILD_FD)
*
fp
=
::
fopen
((
filename
.
c_str
()),
mode
.
c_str
());
#endif
#ifdef SPDLOG_PREVENT_CHILD_FD
// prevent child processes from inheriting log file descriptors
if
(
*
fp
!=
nullptr
)
if
(
*
fp
!=
nullptr
)
{
{
prevent_child_fd
(
*
fp
);
auto
file_handle
=
reinterpret_cast
<
HANDLE
>
(
_get_osfhandle
(
::
_fileno
(
*
fp
)));
if
(
!::
SetHandleInformation
(
file_handle
,
HANDLE_FLAG_INHERIT
,
0
))
{
:
fclose
(
*
fp
);
*
fp
=
nullptr
;
}
}
#endif
#else // unix
#if defined(SPDLOG_PREVENT_CHILD_FD)
const
int
mode_flag
=
mode
==
SPDLOG_FILENAME_T
(
"ab"
)
?
O_APPEND
:
O_TRUNC
;
const
int
fd
=
::
open
((
filename
.
c_str
()),
O_CREAT
|
O_WRONLY
|
O_CLOEXEC
|
mode_flag
,
mode_t
(
0644
));
if
(
fd
==
-
1
)
{
return
false
;
}
}
*
fp
=
::
fdopen
(
fd
,
mode
.
c_str
());
if
(
*
fp
==
nullptr
)
{
::
close
(
fd
);
}
#else
*
fp
=
::
fopen
((
filename
.
c_str
()),
mode
.
c_str
());
#endif
#endif
#endif
return
*
fp
==
nullptr
;
return
*
fp
==
nullptr
;
}
}
...
...
include/spdlog/details/os.h
View file @
d4ce9386
...
@@ -38,10 +38,6 @@ static const char folder_sep = '\\';
...
@@ -38,10 +38,6 @@ 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
);
#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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment