Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
nghttp2
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
nghttp2
Commits
97566ce4
Commit
97566ce4
authored
Aug 13, 2015
by
Tomasz Buchert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nghttpx: make early copy of stderr
parent
900dcf4c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
3 deletions
+31
-3
src/shrpx.cc
src/shrpx.cc
+6
-0
src/util.cc
src/util.cc
+17
-3
src/util.h
src/util.h
+8
-0
No files found.
src/shrpx.cc
View file @
97566ce4
...
...
@@ -564,6 +564,9 @@ void exec_binary_signal_cb(struct ev_loop *loop, ev_signal *w, int revents) {
}
}
// restores original stderr
util
::
restore_original_fds
();
if
(
execve
(
argv
[
0
],
argv
.
get
(),
envp
.
get
())
==
-
1
)
{
auto
error
=
errno
;
LOG
(
ERROR
)
<<
"execve failed: errno="
<<
error
;
...
...
@@ -1763,6 +1766,9 @@ int main(int argc, char **argv) {
create_config
();
fill_default_config
();
// make copy of stderr
util
::
store_original_fds
();
// First open log files with default configuration, so that we can
// log errors/warnings while reading configuration files.
reopen_log_files
();
...
...
src/util.cc
View file @
97566ce4
...
...
@@ -657,9 +657,23 @@ std::string numeric_name(const struct sockaddr *sa, socklen_t salen) {
return
host
.
data
();
}
static
int
STDERR_COPY
=
-
1
;
static
int
STDOUT_COPY
=
-
1
;
void
store_original_fds
()
{
// consider dup'ing stdout too
STDERR_COPY
=
dup
(
STDERR_FILENO
);
STDOUT_COPY
=
STDOUT_FILENO
;
// no race here, since it is called early
make_socket_closeonexec
(
STDERR_COPY
);
}
void
restore_original_fds
()
{
dup2
(
STDERR_COPY
,
STDERR_FILENO
);
}
void
close_log_file
(
int
&
fd
)
{
if
(
fd
!=
STDERR_
FILENO
&&
fd
!=
STDOUT_FILENO
&&
fd
!=
-
1
)
{
if
(
fd
!=
STDERR_
COPY
&&
fd
!=
STDOUT_COPY
&&
fd
!=
-
1
)
{
close
(
fd
);
}
fd
=
-
1
;
...
...
@@ -669,12 +683,12 @@ int open_log_file(const char *path) {
if
(
strcmp
(
path
,
"/dev/stdout"
)
==
0
||
strcmp
(
path
,
"/proc/self/fd/1"
)
==
0
)
{
return
STDOUT_
FILENO
;
return
STDOUT_
COPY
;
}
if
(
strcmp
(
path
,
"/dev/stderr"
)
==
0
||
strcmp
(
path
,
"/proc/self/fd/2"
)
==
0
)
{
return
STDERR_
FILENO
;
return
STDERR_
COPY
;
}
#if defined O_CLOEXEC
...
...
src/util.h
View file @
97566ce4
...
...
@@ -516,6 +516,14 @@ bool numeric_host(const char *hostname);
// failed, "unknown" is returned.
std
::
string
numeric_name
(
const
struct
sockaddr
*
sa
,
socklen_t
salen
);
// Makes internal copy of stderr (and possibly stdout in the future),
// which is then used as pointer to /dev/stderr or /proc/self/fd/2
void
store_original_fds
();
// Restores the original stderr that was stored with copy_original_fds
// Used just before execv
void
restore_original_fds
();
// Closes |fd| which was returned by open_log_file (see below)
// and sets it to -1. In the case that |fd| points to stdout or
// stderr, or is -1, the descriptor is not closed (but still set to -1).
...
...
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