nghttpx: Use pointer for worker_config
This commit is contained in:
parent
345121975a
commit
fb62a5ed4f
14
src/shrpx.cc
14
src/shrpx.cc
|
@ -335,7 +335,7 @@ void reopen_log_signal_cb(evutil_socket_t sig, short events, void *arg)
|
||||||
auto listener_handler = static_cast<ListenHandler*>(arg);
|
auto listener_handler = static_cast<ListenHandler*>(arg);
|
||||||
|
|
||||||
if(LOG_ENABLED(INFO)) {
|
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();
|
(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();
|
listener_handler->accept_pending_connection();
|
||||||
|
|
||||||
worker_config.graceful_shutdown = true;
|
worker_config->graceful_shutdown = true;
|
||||||
|
|
||||||
listener_handler->graceful_shutdown_worker();
|
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
|
// In multi threaded mode (get_config()->num_worker > 1), we have to
|
||||||
// wait for event notification to workers to finish.
|
// wait for event notification to workers to finish.
|
||||||
if(get_config()->num_worker == 1 &&
|
if(get_config()->num_worker == 1 &&
|
||||||
worker_config.graceful_shutdown &&
|
worker_config->graceful_shutdown &&
|
||||||
(!worker_stat || worker_stat->num_connections == 0)) {
|
(!worker_stat || worker_stat->num_connections == 0)) {
|
||||||
event_base_loopbreak(listener_handler->get_evbase());
|
event_base_loopbreak(listener_handler->get_evbase());
|
||||||
}
|
}
|
||||||
|
@ -1642,15 +1642,15 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_config()->uid != 0) {
|
if(get_config()->uid != 0) {
|
||||||
if(worker_config.accesslog_fd != -1 &&
|
if(worker_config->accesslog_fd != -1 &&
|
||||||
fchown(worker_config.accesslog_fd,
|
fchown(worker_config->accesslog_fd,
|
||||||
get_config()->uid, get_config()->gid) == -1) {
|
get_config()->uid, get_config()->gid) == -1) {
|
||||||
auto error = errno;
|
auto error = errno;
|
||||||
LOG(WARNING) << "Changing owner of access log file failed: "
|
LOG(WARNING) << "Changing owner of access log file failed: "
|
||||||
<< strerror(error);
|
<< strerror(error);
|
||||||
}
|
}
|
||||||
if(worker_config.errorlog_fd != -1 &&
|
if(worker_config->errorlog_fd != -1 &&
|
||||||
fchown(worker_config.errorlog_fd,
|
fchown(worker_config->errorlog_fd,
|
||||||
get_config()->uid, get_config()->gid) == -1) {
|
get_config()->uid, get_config()->gid) == -1) {
|
||||||
auto error = errno;
|
auto error = errno;
|
||||||
LOG(WARNING) << "Changing owner of error log file failed: "
|
LOG(WARNING) << "Changing owner of error log file failed: "
|
||||||
|
|
|
@ -274,7 +274,7 @@ ClientHandler::~ClientHandler()
|
||||||
|
|
||||||
// TODO If backend is http/2, and it is in CONNECTED state, signal
|
// TODO If backend is http/2, and it is in CONNECTED state, signal
|
||||||
// it and make it loopbreak when output is zero.
|
// 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());
|
event_base_loopbreak(get_evbase());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -255,7 +255,7 @@ int HttpDownstreamConnection::push_request_headers()
|
||||||
if(LOG_ENABLED(INFO)) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
const char *hdrp;
|
const char *hdrp;
|
||||||
std::string nhdrs;
|
std::string nhdrs;
|
||||||
if(worker_config.errorlog_tty) {
|
if(worker_config->errorlog_tty) {
|
||||||
nhdrs = http::colorizeHeaders(hdrs.c_str());
|
nhdrs = http::colorizeHeaders(hdrs.c_str());
|
||||||
hdrp = nhdrs.c_str();
|
hdrp = nhdrs.c_str();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -940,7 +940,7 @@ void HttpsUpstream::log_response_headers(const std::string& hdrs) const
|
||||||
{
|
{
|
||||||
const char *hdrp;
|
const char *hdrp;
|
||||||
std::string nhdrs;
|
std::string nhdrs;
|
||||||
if(worker_config.errorlog_tty) {
|
if(worker_config->errorlog_tty) {
|
||||||
nhdrs = http::colorizeHeaders(hdrs.c_str());
|
nhdrs = http::colorizeHeaders(hdrs.c_str());
|
||||||
hdrp = nhdrs.c_str();
|
hdrp = nhdrs.c_str();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -82,7 +82,7 @@ void worker_writecb(bufferevent *bev, void *ptr)
|
||||||
auto listener_handler = static_cast<ListenHandler*>(ptr);
|
auto listener_handler = static_cast<ListenHandler*>(ptr);
|
||||||
auto output = bufferevent_get_output(bev);
|
auto output = bufferevent_get_output(bev);
|
||||||
|
|
||||||
if(!worker_config.graceful_shutdown ||
|
if(!worker_config->graceful_shutdown ||
|
||||||
evbuffer_get_length(output) != 0) {
|
evbuffer_get_length(output) != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,10 @@ Log::~Log()
|
||||||
{
|
{
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
|
auto wconf = worker_config;
|
||||||
|
|
||||||
if(!log_enabled(severity_) ||
|
if(!log_enabled(severity_) ||
|
||||||
(worker_config.errorlog_fd == -1 && !get_config()->errorlog_syslog)) {
|
(wconf->errorlog_fd == -1 && !get_config()->errorlog_syslog)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +118,7 @@ Log::~Log()
|
||||||
}
|
}
|
||||||
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
auto tty = worker_config.errorlog_tty;
|
auto tty = wconf->errorlog_tty;
|
||||||
|
|
||||||
auto cached_time = get_config()->cached_time;
|
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);
|
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,
|
void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
|
||||||
Downstream *downstream)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,25 +213,26 @@ void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
while(write(worker_config.accesslog_fd, buf, nwrite) == -1 &&
|
while(write(wconf->accesslog_fd, buf, nwrite) == -1 && errno == EINTR);
|
||||||
errno == EINTR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int reopen_log_files()
|
int reopen_log_files()
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
if(worker_config.accesslog_fd != -1) {
|
auto wconf = worker_config;
|
||||||
close(worker_config.accesslog_fd);
|
|
||||||
worker_config.accesslog_fd = -1;
|
if(wconf->accesslog_fd != -1) {
|
||||||
|
close(wconf->accesslog_fd);
|
||||||
|
wconf->accesslog_fd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!get_config()->accesslog_syslog && get_config()->accesslog_file) {
|
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());
|
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 "
|
LOG(ERROR) << "Failed to open accesslog file "
|
||||||
<< get_config()->accesslog_file.get();
|
<< get_config()->accesslog_file.get();
|
||||||
res = -1;
|
res = -1;
|
||||||
|
@ -241,7 +246,7 @@ int reopen_log_files()
|
||||||
new_errorlog_fd = util::reopen_log_file(get_config()->errorlog_file.get());
|
new_errorlog_fd = util::reopen_log_file(get_config()->errorlog_file.get());
|
||||||
|
|
||||||
if(new_errorlog_fd == -1) {
|
if(new_errorlog_fd == -1) {
|
||||||
if(worker_config.errorlog_fd != -1) {
|
if(wconf->errorlog_fd != -1) {
|
||||||
LOG(ERROR) << "Failed to open errorlog file "
|
LOG(ERROR) << "Failed to open errorlog file "
|
||||||
<< get_config()->errorlog_file.get();
|
<< get_config()->errorlog_file.get();
|
||||||
} else {
|
} else {
|
||||||
|
@ -254,15 +259,15 @@ int reopen_log_files()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(worker_config.errorlog_fd != -1) {
|
if(wconf->errorlog_fd != -1) {
|
||||||
close(worker_config.errorlog_fd);
|
close(wconf->errorlog_fd);
|
||||||
worker_config.errorlog_fd = -1;
|
wconf->errorlog_fd = -1;
|
||||||
worker_config.errorlog_tty = false;
|
wconf->errorlog_tty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(new_errorlog_fd != -1) {
|
if(new_errorlog_fd != -1) {
|
||||||
worker_config.errorlog_fd = new_errorlog_fd;
|
wconf->errorlog_fd = new_errorlog_fd;
|
||||||
worker_config.errorlog_tty = isatty(worker_config.errorlog_fd);
|
wconf->errorlog_tty = isatty(wconf->errorlog_fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -97,8 +97,8 @@ private:
|
||||||
static int severity_thres_;
|
static int severity_thres_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TTY_HTTP_HD (worker_config.errorlog_tty ? "\033[1;34m" : "")
|
#define TTY_HTTP_HD (worker_config->errorlog_tty ? "\033[1;34m" : "")
|
||||||
#define TTY_RST (worker_config.errorlog_tty ? "\033[0m" : "")
|
#define TTY_RST (worker_config->errorlog_tty ? "\033[0m" : "")
|
||||||
|
|
||||||
void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
|
void upstream_accesslog(const std::string& client_ip, unsigned int status_code,
|
||||||
Downstream *downstream);
|
Downstream *downstream);
|
||||||
|
|
|
@ -73,7 +73,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
|
||||||
if(wev.type == REOPEN_LOG) {
|
if(wev.type == REOPEN_LOG) {
|
||||||
if(LOG_ENABLED(INFO)) {
|
if(LOG_ENABLED(INFO)) {
|
||||||
LOG(INFO) << "Reopening log files: worker_info("
|
LOG(INFO) << "Reopening log files: worker_info("
|
||||||
<< &worker_config << ")";
|
<< worker_config << ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
reopen_log_files();
|
reopen_log_files();
|
||||||
|
@ -86,7 +86,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
|
||||||
LOG(INFO) << "Graceful shutdown commencing";
|
LOG(INFO) << "Graceful shutdown commencing";
|
||||||
}
|
}
|
||||||
|
|
||||||
worker_config.graceful_shutdown = true;
|
worker_config->graceful_shutdown = true;
|
||||||
|
|
||||||
if(worker_stat_->num_connections == 0) {
|
if(worker_stat_->num_connections == 0) {
|
||||||
event_base_loopbreak(evbase_);
|
event_base_loopbreak(evbase_);
|
||||||
|
|
|
@ -36,7 +36,7 @@ WorkerConfig::WorkerConfig()
|
||||||
#ifndef NOTHREADS
|
#ifndef NOTHREADS
|
||||||
thread_local
|
thread_local
|
||||||
#endif // NOTHREADS
|
#endif // NOTHREADS
|
||||||
WorkerConfig worker_config;
|
WorkerConfig *worker_config = new WorkerConfig();
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ extern
|
||||||
#ifndef NOTHREADS
|
#ifndef NOTHREADS
|
||||||
thread_local
|
thread_local
|
||||||
#endif // NOTHREADS
|
#endif // NOTHREADS
|
||||||
WorkerConfig worker_config;
|
WorkerConfig *worker_config;
|
||||||
|
|
||||||
} // namespace shrpx
|
} // namespace shrpx
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue