From e5b84fad098064cb57876a73b5a7f890de053190 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 16 Feb 2017 22:46:22 +0900 Subject: [PATCH] nghttpx: Fix bug that old config is used during reloading config --- src/shrpx-unittest.cc | 1 + src/shrpx.cc | 37 +++++++++---------- src/shrpx.h | 2 - src/shrpx_accept_handler.cc | 1 + src/shrpx_api_downstream_connection.cc | 1 + src/shrpx_client_handler.cc | 1 + src/shrpx_client_handler.h | 1 + src/shrpx_config_test.cc | 1 + src/shrpx_connect_blocker.cc | 1 + src/shrpx_connect_blocker.h | 1 + src/shrpx_connection.cc | 1 + src/shrpx_connection_handler.cc | 3 +- src/shrpx_dns_tracker.cc | 1 + src/shrpx_downstream.cc | 1 + src/shrpx_downstream.h | 1 + src/shrpx_downstream_connection.cc | 1 + src/shrpx_downstream_connection.h | 2 + src/shrpx_exec.cc | 1 + ...px_health_monitor_downstream_connection.cc | 2 +- src/shrpx_http.h | 2 + src/shrpx_http2_downstream_connection.cc | 1 + src/shrpx_http2_session.cc | 1 + src/shrpx_http2_session.h | 1 + src/shrpx_http2_upstream.cc | 1 + src/shrpx_http_downstream_connection.cc | 1 + src/shrpx_http_test.cc | 1 + src/shrpx_https_upstream.cc | 1 + src/shrpx_live_check.cc | 1 + src/shrpx_log.cc | 11 +++--- src/shrpx_log.h | 5 ++- src/shrpx_memcached_connection.cc | 1 + src/shrpx_memcached_dispatcher.cc | 1 + src/shrpx_memcached_dispatcher.h | 2 + src/shrpx_mruby.cc | 1 + src/shrpx_mruby.h | 2 + src/shrpx_mruby_module_env.cc | 1 + src/shrpx_mruby_module_env.h | 2 - src/shrpx_mruby_module_request.cc | 1 + src/shrpx_mruby_module_request.h | 2 - src/shrpx_mruby_module_response.cc | 1 + src/shrpx_mruby_module_response.h | 2 - src/shrpx_rate_limit.cc | 1 + src/shrpx_router.cc | 1 + src/shrpx_router.h | 2 + src/shrpx_signal.cc | 1 + src/shrpx_spdy_upstream.cc | 1 + src/shrpx_ssl.cc | 13 ++++--- src/shrpx_ssl.h | 3 +- src/shrpx_ssl_test.cc | 1 + src/shrpx_worker.cc | 8 ++-- src/shrpx_worker_process.cc | 18 +++++---- src/shrpx_worker_process.h | 2 - src/shrpx_worker_test.cc | 1 + 53 files changed, 98 insertions(+), 56 deletions(-) diff --git a/src/shrpx-unittest.cc b/src/shrpx-unittest.cc index 579c0326..4e9807d3 100644 --- a/src/shrpx-unittest.cc +++ b/src/shrpx-unittest.cc @@ -45,6 +45,7 @@ #include "shrpx_config.h" #include "ssl.h" #include "shrpx_router_test.h" +#include "shrpx_log.h" static int init_suite1(void) { return 0; } diff --git a/src/shrpx.cc b/src/shrpx.cc index 88e41d89..6fdd7d44 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -85,6 +85,7 @@ #include "shrpx_process.h" #include "shrpx_signal.h" #include "shrpx_connection.h" +#include "shrpx_log.h" #include "util.h" #include "app_helper.h" #include "ssl.h" @@ -299,13 +300,6 @@ int worker_process_last_pid() { } } // namespace -namespace { -int chown_to_running_user(const char *path) { - auto config = get_config(); - return chown(path, config->uid, config->gid); -} -} // namespace - namespace { int save_pid() { std::array errbuf; @@ -361,7 +355,7 @@ int save_pid() { } if (config->uid != 0) { - if (chown_to_running_user(pid_file.c_str()) == -1) { + if (chown(pid_file.c_str(), config->uid, config->gid) == -1) { auto error = errno; LOG(WARN) << "Changing owner of pid file " << pid_file << " failed: " << xsi_strerror(error, errbuf.data(), errbuf.size()); @@ -558,8 +552,11 @@ namespace { void reopen_log(WorkerProcess *wp) { LOG(NOTICE) << "Reopening log files: master process"; - (void)reopen_log_files(); - redirect_stderr_to_errorlog(); + auto config = get_config(); + auto &loggingconf = config->logging; + + (void)reopen_log_files(loggingconf); + redirect_stderr_to_errorlog(loggingconf); ipc_send(wp, SHRPX_IPC_REOPEN_LOG); } } // namespace @@ -1112,7 +1109,7 @@ int create_acceptor_socket(Config *config, std::vector &iaddrs) { if (config->uid != 0) { // fd is not associated to inode, so we cannot use fchown(2) // here. https://lkml.org/lkml/2004/11/1/84 - if (chown_to_running_user(addr.host.c_str()) == -1) { + if (chown(addr.host.c_str(), config->uid, config->gid) == -1) { auto error = errno; LOG(WARN) << "Changing owner of UNIX domain socket " << addr.host << " failed: " @@ -1297,7 +1294,7 @@ int event_loop() { // daemon redirects stderr file descriptor to /dev/null, so we // need this. - redirect_stderr_to_errorlog(); + redirect_stderr_to_errorlog(config->logging); } // update systemd PID tracking @@ -2646,7 +2643,7 @@ int process_options(Config *config, } // Reopen log files using configurations in file - reopen_log_files(); + reopen_log_files(config->logging); { std::set include_set; @@ -2668,12 +2665,12 @@ int process_options(Config *config, loggingconf.syslog_facility); } - if (reopen_log_files() != 0) { + if (reopen_log_files(config->logging) != 0) { LOG(FATAL) << "Failed to open log file"; return -1; } - redirect_stderr_to_errorlog(); + redirect_stderr_to_errorlog(loggingconf); if (config->uid != 0) { if (log_config()->accesslog_fd != -1 && @@ -2707,7 +2704,7 @@ int process_options(Config *config, dumpconf.request_header = f; if (config->uid != 0) { - if (chown_to_running_user(path) == -1) { + if (chown(path, config->uid, config->gid) == -1) { auto error = errno; LOG(WARN) << "Changing owner of http2 upstream request header file " << path << " failed: " @@ -2729,7 +2726,7 @@ int process_options(Config *config, dumpconf.response_header = f; if (config->uid != 0) { - if (chown_to_running_user(path) == -1) { + if (chown(path, config->uid, config->gid) == -1) { auto error = errno; LOG(WARN) << "Changing owner of http2 upstream response header file" << " " << path << " failed: " @@ -2781,14 +2778,14 @@ int process_options(Config *config, upstreamconf.worker_connections = std::numeric_limits::max(); } - if (ssl::upstream_tls_enabled() && + if (ssl::upstream_tls_enabled(config->conn) && (tlsconf.private_key_file.empty() || tlsconf.cert_file.empty())) { print_usage(std::cerr); LOG(FATAL) << "Too few arguments"; return -1; } - if (ssl::upstream_tls_enabled() && !tlsconf.ocsp.disabled) { + if (ssl::upstream_tls_enabled(config->conn) && !tlsconf.ocsp.disabled) { struct stat buf; if (stat(tlsconf.ocsp.fetch_ocsp_response_file.c_str(), &buf) != 0) { tlsconf.ocsp.disabled = true; @@ -3005,7 +3002,7 @@ int main(int argc, char **argv) { // First open log files with default configuration, so that we can // log errors/warnings while reading configuration files. - reopen_log_files(); + reopen_log_files(get_config()->logging); suconfig.original_argv = argv; diff --git a/src/shrpx.h b/src/shrpx.h index 15e66551..c12064b8 100644 --- a/src/shrpx.h +++ b/src/shrpx.h @@ -42,8 +42,6 @@ #define nghttp2_Exit(status) _Exit(status) #endif // HAVE__EXIT -#include "shrpx_log.h" - #define DIE() nghttp2_Exit(EXIT_FAILURE) #if defined(HAVE_DECL_INITGROUPS) && !HAVE_DECL_INITGROUPS diff --git a/src/shrpx_accept_handler.cc b/src/shrpx_accept_handler.cc index 02c59a14..f83b6ff9 100644 --- a/src/shrpx_accept_handler.cc +++ b/src/shrpx_accept_handler.cc @@ -32,6 +32,7 @@ #include "shrpx_connection_handler.h" #include "shrpx_config.h" +#include "shrpx_log.h" #include "util.h" using namespace nghttp2; diff --git a/src/shrpx_api_downstream_connection.cc b/src/shrpx_api_downstream_connection.cc index 09822067..a7e2e25d 100644 --- a/src/shrpx_api_downstream_connection.cc +++ b/src/shrpx_api_downstream_connection.cc @@ -29,6 +29,7 @@ #include "shrpx_downstream.h" #include "shrpx_worker.h" #include "shrpx_connection_handler.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_client_handler.cc b/src/shrpx_client_handler.cc index d29e783f..e43579c6 100644 --- a/src/shrpx_client_handler.cc +++ b/src/shrpx_client_handler.cc @@ -50,6 +50,7 @@ #include "shrpx_connect_blocker.h" #include "shrpx_api_downstream_connection.h" #include "shrpx_health_monitor_downstream_connection.h" +#include "shrpx_log.h" #ifdef HAVE_SPDYLAY #include "shrpx_spdy_upstream.h" #endif // HAVE_SPDYLAY diff --git a/src/shrpx_client_handler.h b/src/shrpx_client_handler.h index eb8cb388..1edbfeb7 100644 --- a/src/shrpx_client_handler.h +++ b/src/shrpx_client_handler.h @@ -49,6 +49,7 @@ class HttpsUpstream; class ConnectBlocker; class DownstreamConnectionPool; class Worker; +class Downstream; struct WorkerStat; struct DownstreamAddrGroup; struct DownstreamAddr; diff --git a/src/shrpx_config_test.cc b/src/shrpx_config_test.cc index 3ec166c8..bc168b40 100644 --- a/src/shrpx_config_test.cc +++ b/src/shrpx_config_test.cc @@ -33,6 +33,7 @@ #include #include "shrpx_config.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_connect_blocker.cc b/src/shrpx_connect_blocker.cc index 4ffe29ca..e261b815 100644 --- a/src/shrpx_connect_blocker.cc +++ b/src/shrpx_connect_blocker.cc @@ -24,6 +24,7 @@ */ #include "shrpx_connect_blocker.h" #include "shrpx_config.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_connect_blocker.h b/src/shrpx_connect_blocker.h index 1d845921..4ccd6a1f 100644 --- a/src/shrpx_connect_blocker.h +++ b/src/shrpx_connect_blocker.h @@ -28,6 +28,7 @@ #include "shrpx.h" #include +#include #include diff --git a/src/shrpx_connection.cc b/src/shrpx_connection.cc index 9f122a26..de74c1d7 100644 --- a/src/shrpx_connection.cc +++ b/src/shrpx_connection.cc @@ -35,6 +35,7 @@ #include "shrpx_ssl.h" #include "shrpx_memcached_request.h" +#include "shrpx_log.h" #include "memchunk.h" #include "util.h" #include "ssl_compat.h" diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 60861550..5ca02f5a 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -44,6 +44,7 @@ #include "shrpx_accept_handler.h" #include "shrpx_memcached_dispatcher.h" #include "shrpx_signal.h" +#include "shrpx_log.h" #include "util.h" #include "template.h" @@ -351,7 +352,7 @@ void ConnectionHandler::graceful_shutdown_worker() { ev_async_start(loop_, &thread_join_asyncev_); thread_join_fut_ = std::async(std::launch::async, [this]() { - (void)reopen_log_files(); + (void)reopen_log_files(get_config()->logging); join_worker(); ev_async_send(get_loop(), &thread_join_asyncev_); delete_log_config(); diff --git a/src/shrpx_dns_tracker.cc b/src/shrpx_dns_tracker.cc index 74ab83b0..9eeca5d8 100644 --- a/src/shrpx_dns_tracker.cc +++ b/src/shrpx_dns_tracker.cc @@ -24,6 +24,7 @@ */ #include "shrpx_dns_tracker.h" #include "shrpx_config.h" +#include "shrpx_log.h" #include "util.h" namespace shrpx { diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index a07ce1c2..afeee3e1 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -36,6 +36,7 @@ #include "shrpx_downstream_queue.h" #include "shrpx_worker.h" #include "shrpx_http2_session.h" +#include "shrpx_log.h" #ifdef HAVE_MRUBY #include "shrpx_mruby.h" #endif // HAVE_MRUBY diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index 68ec8d1a..28c177d4 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -38,6 +38,7 @@ #include #include "shrpx_io_control.h" +#include "shrpx_log_config.h" #include "http2.h" #include "memchunk.h" #include "allocator.h" diff --git a/src/shrpx_downstream_connection.cc b/src/shrpx_downstream_connection.cc index 2c6d2c27..16a2d6fd 100644 --- a/src/shrpx_downstream_connection.cc +++ b/src/shrpx_downstream_connection.cc @@ -26,6 +26,7 @@ #include "shrpx_client_handler.h" #include "shrpx_downstream.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_downstream_connection.h b/src/shrpx_downstream_connection.h index 03c4afe8..12bbbc5b 100644 --- a/src/shrpx_downstream_connection.h +++ b/src/shrpx_downstream_connection.h @@ -27,6 +27,8 @@ #include "shrpx.h" +#include + #include "shrpx_io_control.h" namespace shrpx { diff --git a/src/shrpx_exec.cc b/src/shrpx_exec.cc index 0ac1d6ea..a93ba3fb 100644 --- a/src/shrpx_exec.cc +++ b/src/shrpx_exec.cc @@ -27,6 +27,7 @@ #include #include "shrpx_signal.h" +#include "shrpx_log.h" #include "util.h" #include "template.h" diff --git a/src/shrpx_health_monitor_downstream_connection.cc b/src/shrpx_health_monitor_downstream_connection.cc index 01bdfb9a..ab590de2 100644 --- a/src/shrpx_health_monitor_downstream_connection.cc +++ b/src/shrpx_health_monitor_downstream_connection.cc @@ -27,7 +27,7 @@ #include "shrpx_client_handler.h" #include "shrpx_upstream.h" #include "shrpx_downstream.h" -//#include "shrpx_connection_handler.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_http.h b/src/shrpx_http.h index dfdd1ee8..2833f608 100644 --- a/src/shrpx_http.h +++ b/src/shrpx_http.h @@ -34,6 +34,8 @@ #include "util.h" #include "allocator.h" +using namespace nghttp2; + namespace shrpx { namespace http { diff --git a/src/shrpx_http2_downstream_connection.cc b/src/shrpx_http2_downstream_connection.cc index f0876bc4..82dd0695 100644 --- a/src/shrpx_http2_downstream_connection.cc +++ b/src/shrpx_http2_downstream_connection.cc @@ -38,6 +38,7 @@ #include "shrpx_http.h" #include "shrpx_http2_session.h" #include "shrpx_worker.h" +#include "shrpx_log.h" #include "http2.h" #include "util.h" diff --git a/src/shrpx_http2_session.cc b/src/shrpx_http2_session.cc index 440b4460..802b4157 100644 --- a/src/shrpx_http2_session.cc +++ b/src/shrpx_http2_session.cc @@ -43,6 +43,7 @@ #include "shrpx_http.h" #include "shrpx_worker.h" #include "shrpx_connect_blocker.h" +#include "shrpx_log.h" #include "http2.h" #include "util.h" #include "base64.h" diff --git a/src/shrpx_http2_session.h b/src/shrpx_http2_session.h index bcc4fa45..ef2c0aff 100644 --- a/src/shrpx_http2_session.h +++ b/src/shrpx_http2_session.h @@ -48,6 +48,7 @@ namespace shrpx { class Http2DownstreamConnection; class Worker; +class Downstream; struct DownstreamAddrGroup; struct DownstreamAddr; struct DNSQuery; diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index ce6287a6..c4521c90 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -37,6 +37,7 @@ #include "shrpx_http.h" #include "shrpx_worker.h" #include "shrpx_http2_session.h" +#include "shrpx_log.h" #ifdef HAVE_MRUBY #include "shrpx_mruby.h" #endif // HAVE_MRUBY diff --git a/src/shrpx_http_downstream_connection.cc b/src/shrpx_http_downstream_connection.cc index 38a099dd..57b1c8e7 100644 --- a/src/shrpx_http_downstream_connection.cc +++ b/src/shrpx_http_downstream_connection.cc @@ -36,6 +36,7 @@ #include "shrpx_worker.h" #include "shrpx_http2_session.h" #include "shrpx_ssl.h" +#include "shrpx_log.h" #include "http2.h" #include "util.h" diff --git a/src/shrpx_http_test.cc b/src/shrpx_http_test.cc index 455397a6..a93ab9e4 100644 --- a/src/shrpx_http_test.cc +++ b/src/shrpx_http_test.cc @@ -34,6 +34,7 @@ #include "shrpx_http.h" #include "shrpx_config.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_https_upstream.cc b/src/shrpx_https_upstream.cc index 55a9e70d..b2b6120d 100644 --- a/src/shrpx_https_upstream.cc +++ b/src/shrpx_https_upstream.cc @@ -37,6 +37,7 @@ #include "shrpx_log_config.h" #include "shrpx_worker.h" #include "shrpx_http2_session.h" +#include "shrpx_log.h" #ifdef HAVE_MRUBY #include "shrpx_mruby.h" #endif // HAVE_MRUBY diff --git a/src/shrpx_live_check.cc b/src/shrpx_live_check.cc index 1af88c4c..5241f059 100644 --- a/src/shrpx_live_check.cc +++ b/src/shrpx_live_check.cc @@ -26,6 +26,7 @@ #include "shrpx_worker.h" #include "shrpx_connect_blocker.h" #include "shrpx_ssl.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_log.cc b/src/shrpx_log.cc index 27180a39..f08ab6d8 100644 --- a/src/shrpx_log.cc +++ b/src/shrpx_log.cc @@ -456,15 +456,14 @@ void upstream_accesslog(const std::vector &lfv, ; } -int reopen_log_files() { +int reopen_log_files(const LoggingConfig &loggingconf) { int res = 0; int new_accesslog_fd = -1; int new_errorlog_fd = -1; auto lgconf = log_config(); - auto config = get_config(); - auto &accessconf = config->logging.access; - auto &errorconf = config->logging.error; + auto &accessconf = loggingconf.access; + auto &errorconf = loggingconf.error; if (!accessconf.syslog && !accessconf.file.empty()) { new_accesslog_fd = open_log_file(accessconf.file.c_str()); @@ -524,9 +523,9 @@ void log_chld(pid_t pid, int rstatus, const char *msg) { << (signalstr.empty() ? "" : signalstr.c_str()); } -void redirect_stderr_to_errorlog() { +void redirect_stderr_to_errorlog(const LoggingConfig &loggingconf) { auto lgconf = log_config(); - auto &errorconf = get_config()->logging.error; + auto &errorconf = loggingconf.error; if (errorconf.syslog || lgconf->errorlog_fd == -1) { return; diff --git a/src/shrpx_log.h b/src/shrpx_log.h index 8b0678fe..1afb6e1a 100644 --- a/src/shrpx_log.h +++ b/src/shrpx_log.h @@ -34,6 +34,7 @@ #include #include +#include "shrpx_config.h" #include "shrpx_log_config.h" #include "ssl.h" #include "template.h" @@ -157,13 +158,13 @@ struct LogSpec { void upstream_accesslog(const std::vector &lf, const LogSpec &lgsp); -int reopen_log_files(); +int reopen_log_files(const LoggingConfig &loggingconf); // Logs message when process whose pid is |pid| and exist status is // |rstatus| exited. The |msg| is prepended to the log message. void log_chld(pid_t pid, int rstatus, const char *msg); -void redirect_stderr_to_errorlog(); +void redirect_stderr_to_errorlog(const LoggingConfig &loggingconf); // 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 diff --git a/src/shrpx_memcached_connection.cc b/src/shrpx_memcached_connection.cc index 3f597b44..c7d3fa90 100644 --- a/src/shrpx_memcached_connection.cc +++ b/src/shrpx_memcached_connection.cc @@ -33,6 +33,7 @@ #include "shrpx_memcached_result.h" #include "shrpx_config.h" #include "shrpx_ssl.h" +#include "shrpx_log.h" #include "util.h" namespace shrpx { diff --git a/src/shrpx_memcached_dispatcher.cc b/src/shrpx_memcached_dispatcher.cc index a3f1357c..1b8c2c4f 100644 --- a/src/shrpx_memcached_dispatcher.cc +++ b/src/shrpx_memcached_dispatcher.cc @@ -27,6 +27,7 @@ #include "shrpx_memcached_request.h" #include "shrpx_memcached_connection.h" #include "shrpx_config.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_memcached_dispatcher.h b/src/shrpx_memcached_dispatcher.h index e7b78d27..de1af80b 100644 --- a/src/shrpx_memcached_dispatcher.h +++ b/src/shrpx_memcached_dispatcher.h @@ -37,6 +37,8 @@ #include "memchunk.h" #include "network.h" +using namespace nghttp2; + namespace shrpx { struct MemcachedRequest; diff --git a/src/shrpx_mruby.cc b/src/shrpx_mruby.cc index 507d13b9..ec08aabf 100644 --- a/src/shrpx_mruby.cc +++ b/src/shrpx_mruby.cc @@ -31,6 +31,7 @@ #include "shrpx_config.h" #include "shrpx_mruby_module.h" #include "shrpx_downstream_connection.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_mruby.h b/src/shrpx_mruby.h index 4466cf6f..518063d1 100644 --- a/src/shrpx_mruby.h +++ b/src/shrpx_mruby.h @@ -38,6 +38,8 @@ using namespace nghttp2; namespace shrpx { +class Downstream; + namespace mruby { class MRubyContext { diff --git a/src/shrpx_mruby_module_env.cc b/src/shrpx_mruby_module_env.cc index 7fabbedb..078a4751 100644 --- a/src/shrpx_mruby_module_env.cc +++ b/src/shrpx_mruby_module_env.cc @@ -33,6 +33,7 @@ #include "shrpx_client_handler.h" #include "shrpx_mruby.h" #include "shrpx_mruby_module.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_mruby_module_env.h b/src/shrpx_mruby_module_env.h index 7515e16e..08846788 100644 --- a/src/shrpx_mruby_module_env.h +++ b/src/shrpx_mruby_module_env.h @@ -29,8 +29,6 @@ #include -using namespace nghttp2; - namespace shrpx { namespace mruby { diff --git a/src/shrpx_mruby_module_request.cc b/src/shrpx_mruby_module_request.cc index b3392f26..dff99ce1 100644 --- a/src/shrpx_mruby_module_request.cc +++ b/src/shrpx_mruby_module_request.cc @@ -34,6 +34,7 @@ #include "shrpx_client_handler.h" #include "shrpx_mruby.h" #include "shrpx_mruby_module.h" +#include "shrpx_log.h" #include "util.h" #include "http2.h" diff --git a/src/shrpx_mruby_module_request.h b/src/shrpx_mruby_module_request.h index b27c569b..e74f3351 100644 --- a/src/shrpx_mruby_module_request.h +++ b/src/shrpx_mruby_module_request.h @@ -29,8 +29,6 @@ #include -using namespace nghttp2; - namespace shrpx { namespace mruby { diff --git a/src/shrpx_mruby_module_response.cc b/src/shrpx_mruby_module_response.cc index 3088dbb6..850d46e5 100644 --- a/src/shrpx_mruby_module_response.cc +++ b/src/shrpx_mruby_module_response.cc @@ -34,6 +34,7 @@ #include "shrpx_client_handler.h" #include "shrpx_mruby.h" #include "shrpx_mruby_module.h" +#include "shrpx_log.h" #include "util.h" #include "http2.h" diff --git a/src/shrpx_mruby_module_response.h b/src/shrpx_mruby_module_response.h index 32ed0d41..a35b42b1 100644 --- a/src/shrpx_mruby_module_response.h +++ b/src/shrpx_mruby_module_response.h @@ -29,8 +29,6 @@ #include -using namespace nghttp2; - namespace shrpx { namespace mruby { diff --git a/src/shrpx_rate_limit.cc b/src/shrpx_rate_limit.cc index 65b0f66c..77a1fe22 100644 --- a/src/shrpx_rate_limit.cc +++ b/src/shrpx_rate_limit.cc @@ -27,6 +27,7 @@ #include #include "shrpx_connection.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_router.cc b/src/shrpx_router.cc index 04f7fd74..92531f87 100644 --- a/src/shrpx_router.cc +++ b/src/shrpx_router.cc @@ -27,6 +27,7 @@ #include #include "shrpx_config.h" +#include "shrpx_log.h" namespace shrpx { diff --git a/src/shrpx_router.h b/src/shrpx_router.h index 677af986..8762cb33 100644 --- a/src/shrpx_router.h +++ b/src/shrpx_router.h @@ -32,6 +32,8 @@ #include "allocator.h" +using namespace nghttp2; + namespace shrpx { struct RNode { diff --git a/src/shrpx_signal.cc b/src/shrpx_signal.cc index 3030de38..fcce2dcc 100644 --- a/src/shrpx_signal.cc +++ b/src/shrpx_signal.cc @@ -26,6 +26,7 @@ #include +#include "shrpx_log.h" #include "template.h" using namespace nghttp2; diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index ce952298..3e401d9b 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -41,6 +41,7 @@ #endif // HAVE_MRUBY #include "shrpx_worker.h" #include "shrpx_http2_session.h" +#include "shrpx_log.h" #include "http2.h" #include "util.h" #include "template.h" diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index f648bda2..e992589c 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -1525,8 +1525,8 @@ bool in_proto_list(const std::vector &protos, return false; } -bool upstream_tls_enabled() { - const auto &faddrs = get_config()->conn.listener.addrs; +bool upstream_tls_enabled(const ConnectionConfig &connconf) { + const auto &faddrs = connconf.listener.addrs; return std::any_of(std::begin(faddrs), std::end(faddrs), [](const UpstreamAddr &faddr) { return faddr.tls; }); } @@ -1560,11 +1560,13 @@ setup_server_ssl_context(std::vector &all_ssl_ctx, neverbleed_t *nb #endif // HAVE_NEVERBLEED ) { - if (!upstream_tls_enabled()) { + auto config = get_config(); + + if (!upstream_tls_enabled(config->conn)) { return nullptr; } - auto &tlsconf = get_config()->tls; + auto &tlsconf = config->tls; auto ssl_ctx = ssl::create_ssl_context(tlsconf.private_key_file.c_str(), @@ -1644,7 +1646,8 @@ void setup_downstream_http1_alpn(SSL *ssl) { } std::unique_ptr create_cert_lookup_tree() { - if (!upstream_tls_enabled() || get_config()->tls.subcerts.empty()) { + auto config = get_config(); + if (!upstream_tls_enabled(config->conn) || config->tls.subcerts.empty()) { return nullptr; } return make_unique(); diff --git a/src/shrpx_ssl.h b/src/shrpx_ssl.h index db472f04..dcd15e8e 100644 --- a/src/shrpx_ssl.h +++ b/src/shrpx_ssl.h @@ -40,6 +40,7 @@ #endif // HAVE_NEVERBLEED #include "network.h" +#include "shrpx_config.h" #include "shrpx_router.h" namespace shrpx { @@ -235,7 +236,7 @@ std::unique_ptr create_cert_lookup_tree(); SSL *create_ssl(SSL_CTX *ssl_ctx); // Returns true if SSL/TLS is enabled on upstream -bool upstream_tls_enabled(); +bool upstream_tls_enabled(const ConnectionConfig &connconf); // Performs TLS hostname match. |pattern| can contain wildcard // character '*', which matches prefix of target hostname. There are diff --git a/src/shrpx_ssl_test.cc b/src/shrpx_ssl_test.cc index 1de5db67..551b13d9 100644 --- a/src/shrpx_ssl_test.cc +++ b/src/shrpx_ssl_test.cc @@ -27,6 +27,7 @@ #include #include "shrpx_ssl.h" +#include "shrpx_log.h" #include "util.h" #include "template.h" diff --git a/src/shrpx_worker.cc b/src/shrpx_worker.cc index 8b1a74fd..10a9990b 100644 --- a/src/shrpx_worker.cc +++ b/src/shrpx_worker.cc @@ -311,7 +311,7 @@ void Worker::wait() { void Worker::run_async() { #ifndef NOTHREADS fut_ = std::async(std::launch::async, [this] { - (void)reopen_log_files(); + (void)reopen_log_files(get_config()->logging); ev_run(loop_); delete_log_config(); }); @@ -349,7 +349,9 @@ void Worker::process_events() { ev_timer_start(loop_, &proc_wev_timer_); - auto worker_connections = get_config()->conn.upstream.worker_connections; + auto config = get_config(); + + auto worker_connections = config->conn.upstream.worker_connections; switch (wev.type) { case NEW_CONNECTION: { @@ -390,7 +392,7 @@ void Worker::process_events() { WLOG(NOTICE, this) << "Reopening log files: worker process (thread " << this << ")"; - reopen_log_files(); + reopen_log_files(config->logging); break; case GRACEFUL_SHUTDOWN: diff --git a/src/shrpx_worker_process.cc b/src/shrpx_worker_process.cc index 37256538..27ef784c 100644 --- a/src/shrpx_worker_process.cc +++ b/src/shrpx_worker_process.cc @@ -52,6 +52,7 @@ #include "shrpx_memcached_request.h" #include "shrpx_process.h" #include "shrpx_ssl.h" +#include "shrpx_log.h" #include "util.h" #include "app_helper.h" #include "template.h" @@ -137,8 +138,11 @@ namespace { void reopen_log(ConnectionHandler *conn_handler) { LOG(NOTICE) << "Reopening log files: worker process (thread main)"; - (void)reopen_log_files(); - redirect_stderr_to_errorlog(); + auto config = get_config(); + auto &loggingconf = config->logging; + + (void)reopen_log_files(loggingconf); + redirect_stderr_to_errorlog(loggingconf); if (get_config()->num_worker > 1) { conn_handler->worker_reopen_log_files(); @@ -399,7 +403,9 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { std::array errbuf; (void)errbuf; - if (reopen_log_files() != 0) { + auto config = get_config(); + + if (reopen_log_files(config->logging) != 0) { LOG(FATAL) << "Failed to open log file"; return -1; } @@ -416,8 +422,6 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { ConnectionHandler conn_handler(loop, gen); - auto config = get_config(); - for (auto &addr : config->conn.listener.addrs) { conn_handler.add_acceptor(make_unique(&addr, &conn_handler)); } @@ -450,7 +454,7 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { MemchunkPool mcpool; ev_timer renew_ticket_key_timer; - if (ssl::upstream_tls_enabled()) { + if (ssl::upstream_tls_enabled(config->conn)) { auto &ticketconf = config->tls.ticket; auto &memcachedconf = ticketconf.memcached; @@ -549,7 +553,7 @@ int worker_process_event_loop(WorkerProcessConfig *wpconf) { ipcev.data = &conn_handler; ev_io_start(loop, &ipcev); - if (ssl::upstream_tls_enabled() && !config->tls.ocsp.disabled) { + if (ssl::upstream_tls_enabled(config->conn) && !config->tls.ocsp.disabled) { conn_handler.proceed_next_cert_ocsp(); } diff --git a/src/shrpx_worker_process.h b/src/shrpx_worker_process.h index 77634f00..01e3e671 100644 --- a/src/shrpx_worker_process.h +++ b/src/shrpx_worker_process.h @@ -27,8 +27,6 @@ #include "shrpx.h" -using namespace nghttp2; - namespace shrpx { class ConnectionHandler; diff --git a/src/shrpx_worker_test.cc b/src/shrpx_worker_test.cc index 2e419416..ee6919ff 100644 --- a/src/shrpx_worker_test.cc +++ b/src/shrpx_worker_test.cc @@ -34,6 +34,7 @@ #include "shrpx_worker.h" #include "shrpx_connect_blocker.h" +#include "shrpx_log.h" namespace shrpx {