nghttpx: Use pointer for worker_config

This commit is contained in:
Tatsuhiro Tsujikawa 2014-08-19 21:33:54 +09:00
parent 345121975a
commit fb62a5ed4f
10 changed files with 40 additions and 35 deletions

View File

@ -335,7 +335,7 @@ void reopen_log_signal_cb(evutil_socket_t sig, short events, void *arg)
auto listener_handler = static_cast<ListenHandler*>(arg);
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Reopening log files: worker_info(" << &worker_config << ")";
LOG(INFO) << "Reopening log files: worker_info(" << worker_config << ")";
}
(void)reopen_log_files();
@ -456,7 +456,7 @@ void graceful_shutdown_signal_cb(evutil_socket_t sig, short events, void *arg)
listener_handler->accept_pending_connection();
worker_config.graceful_shutdown = true;
worker_config->graceful_shutdown = true;
listener_handler->graceful_shutdown_worker();
}
@ -495,7 +495,7 @@ void refresh_cb(evutil_socket_t sig, short events, void *arg)
// In multi threaded mode (get_config()->num_worker > 1), we have to
// wait for event notification to workers to finish.
if(get_config()->num_worker == 1 &&
worker_config.graceful_shutdown &&
worker_config->graceful_shutdown &&
(!worker_stat || worker_stat->num_connections == 0)) {
event_base_loopbreak(listener_handler->get_evbase());
}
@ -1642,15 +1642,15 @@ int main(int argc, char **argv)
}
if(get_config()->uid != 0) {
if(worker_config.accesslog_fd != -1 &&
fchown(worker_config.accesslog_fd,
if(worker_config->accesslog_fd != -1 &&
fchown(worker_config->accesslog_fd,
get_config()->uid, get_config()->gid) == -1) {
auto error = errno;
LOG(WARNING) << "Changing owner of access log file failed: "
<< strerror(error);
}
if(worker_config.errorlog_fd != -1 &&
fchown(worker_config.errorlog_fd,
if(worker_config->errorlog_fd != -1 &&
fchown(worker_config->errorlog_fd,
get_config()->uid, get_config()->gid) == -1) {
auto error = errno;
LOG(WARNING) << "Changing owner of error log file failed: "

View File

@ -274,7 +274,7 @@ ClientHandler::~ClientHandler()
// TODO If backend is http/2, and it is in CONNECTED state, signal
// it and make it loopbreak when output is zero.
if(worker_config.graceful_shutdown && worker_stat_->num_connections == 0) {
if(worker_config->graceful_shutdown && worker_stat_->num_connections == 0) {
event_base_loopbreak(get_evbase());
}

View File

@ -255,7 +255,7 @@ int HttpDownstreamConnection::push_request_headers()
if(LOG_ENABLED(INFO)) {
const char *hdrp;
std::string nhdrs;
if(worker_config.errorlog_tty) {
if(worker_config->errorlog_tty) {
nhdrs = http::colorizeHeaders(hdrs.c_str());
hdrp = nhdrs.c_str();
} else {

View File

@ -940,7 +940,7 @@ void HttpsUpstream::log_response_headers(const std::string& hdrs) const
{
const char *hdrp;
std::string nhdrs;
if(worker_config.errorlog_tty) {
if(worker_config->errorlog_tty) {
nhdrs = http::colorizeHeaders(hdrs.c_str());
hdrp = nhdrs.c_str();
} else {

View File

@ -82,7 +82,7 @@ void worker_writecb(bufferevent *bev, void *ptr)
auto listener_handler = static_cast<ListenHandler*>(ptr);
auto output = bufferevent_get_output(bev);
if(!worker_config.graceful_shutdown ||
if(!worker_config->graceful_shutdown ||
evbuffer_get_length(output) != 0) {
return;
}

View File

@ -102,8 +102,10 @@ Log::~Log()
{
int rv;
auto wconf = worker_config;
if(!log_enabled(severity_) ||
(worker_config.errorlog_fd == -1 && !get_config()->errorlog_syslog)) {
(wconf->errorlog_fd == -1 && !get_config()->errorlog_syslog)) {
return;
}
@ -116,7 +118,7 @@ Log::~Log()
}
char buf[4096];
auto tty = worker_config.errorlog_tty;
auto tty = wconf->errorlog_tty;
auto cached_time = get_config()->cached_time;
@ -138,13 +140,15 @@ Log::~Log()
auto nwrite = std::min(static_cast<size_t>(rv), sizeof(buf) - 1);
while(write(worker_config.errorlog_fd, buf, nwrite) == -1 && errno == EINTR);
while(write(wconf->errorlog_fd, buf, nwrite) == -1 && errno == EINTR);
}
void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
Downstream *downstream)
{
if(worker_config.accesslog_fd == -1 && !get_config()->accesslog_syslog) {
auto wconf = worker_config;
if(wconf->accesslog_fd == -1 && !get_config()->accesslog_syslog) {
return;
}
@ -209,25 +213,26 @@ void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
return;
}
while(write(worker_config.accesslog_fd, buf, nwrite) == -1 &&
errno == EINTR);
while(write(wconf->accesslog_fd, buf, nwrite) == -1 && errno == EINTR);
}
int reopen_log_files()
{
int res = 0;
if(worker_config.accesslog_fd != -1) {
close(worker_config.accesslog_fd);
worker_config.accesslog_fd = -1;
auto wconf = worker_config;
if(wconf->accesslog_fd != -1) {
close(wconf->accesslog_fd);
wconf->accesslog_fd = -1;
}
if(!get_config()->accesslog_syslog && get_config()->accesslog_file) {
worker_config.accesslog_fd =
wconf->accesslog_fd =
util::reopen_log_file(get_config()->accesslog_file.get());
if(worker_config.accesslog_fd == -1) {
if(wconf->accesslog_fd == -1) {
LOG(ERROR) << "Failed to open accesslog file "
<< get_config()->accesslog_file.get();
res = -1;
@ -241,7 +246,7 @@ int reopen_log_files()
new_errorlog_fd = util::reopen_log_file(get_config()->errorlog_file.get());
if(new_errorlog_fd == -1) {
if(worker_config.errorlog_fd != -1) {
if(wconf->errorlog_fd != -1) {
LOG(ERROR) << "Failed to open errorlog file "
<< get_config()->errorlog_file.get();
} else {
@ -254,15 +259,15 @@ int reopen_log_files()
}
}
if(worker_config.errorlog_fd != -1) {
close(worker_config.errorlog_fd);
worker_config.errorlog_fd = -1;
worker_config.errorlog_tty = false;
if(wconf->errorlog_fd != -1) {
close(wconf->errorlog_fd);
wconf->errorlog_fd = -1;
wconf->errorlog_tty = false;
}
if(new_errorlog_fd != -1) {
worker_config.errorlog_fd = new_errorlog_fd;
worker_config.errorlog_tty = isatty(worker_config.errorlog_fd);
wconf->errorlog_fd = new_errorlog_fd;
wconf->errorlog_tty = isatty(wconf->errorlog_fd);
}
return res;

View File

@ -97,8 +97,8 @@ private:
static int severity_thres_;
};
#define TTY_HTTP_HD (worker_config.errorlog_tty ? "\033[1;34m" : "")
#define TTY_RST (worker_config.errorlog_tty ? "\033[0m" : "")
#define TTY_HTTP_HD (worker_config->errorlog_tty ? "\033[1;34m" : "")
#define TTY_RST (worker_config->errorlog_tty ? "\033[0m" : "")
void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
Downstream *downstream);

View File

@ -73,7 +73,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
if(wev.type == REOPEN_LOG) {
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Reopening log files: worker_info("
<< &worker_config << ")";
<< worker_config << ")";
}
reopen_log_files();
@ -86,7 +86,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
LOG(INFO) << "Graceful shutdown commencing";
}
worker_config.graceful_shutdown = true;
worker_config->graceful_shutdown = true;
if(worker_stat_->num_connections == 0) {
event_base_loopbreak(evbase_);

View File

@ -36,7 +36,7 @@ WorkerConfig::WorkerConfig()
#ifndef NOTHREADS
thread_local
#endif // NOTHREADS
WorkerConfig worker_config;
WorkerConfig *worker_config = new WorkerConfig();
} // namespace shrpx

View File

@ -44,7 +44,7 @@ extern
#ifndef NOTHREADS
thread_local
#endif // NOTHREADS
WorkerConfig worker_config;
WorkerConfig *worker_config;
} // namespace shrpx