nghttpx: Redirect stderr to errorlog file

This commit is contained in:
Tatsuhiro Tsujikawa 2015-04-08 16:59:58 +09:00
parent ff60cc6b71
commit dd435b51ab
3 changed files with 19 additions and 0 deletions

View File

@ -422,6 +422,7 @@ void reopen_log_signal_cb(struct ev_loop *loop, ev_signal *w, int revents) {
}
(void)reopen_log_files();
redirect_stderr_to_errorlog();
if (get_config()->num_worker > 1) {
conn_handler->worker_reopen_log_files();
@ -636,6 +637,10 @@ int event_loop() {
// We get new PID after successful daemon().
mod_config()->pid = getpid();
// daemon redirects stderr file descriptor to /dev/null, so we
// need this.
redirect_stderr_to_errorlog();
}
if (get_config()->pid_file) {
@ -1916,6 +1921,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE);
}
redirect_stderr_to_errorlog();
if (get_config()->uid != 0) {
if (log_config()->accesslog_fd != -1 &&
fchown(log_config()->accesslog_fd, get_config()->uid,

View File

@ -324,4 +324,14 @@ int reopen_log_files() {
return res;
}
void redirect_stderr_to_errorlog() {
auto lgconf = log_config();
if (get_config()->errorlog_syslog || lgconf->errorlog_fd == -1) {
return;
}
dup2(lgconf->errorlog_fd, STDERR_FILENO);
}
} // namespace shrpx

View File

@ -143,6 +143,8 @@ void upstream_accesslog(const std::vector<LogFragment> &lf, LogSpec *lgsp);
int reopen_log_files();
void redirect_stderr_to_errorlog();
} // namespace shrpx
#endif // SHRPX_LOG_H