From b9b648e0ed9a2a68478bda366f6b3fde520b4c67 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 31 Jul 2016 16:20:00 +0900 Subject: [PATCH] nghttpx: Remove last_worker_pid from Config The last_worker_pid is known by inspecting the last entry of worker_processes. --- src/shrpx.cc | 19 +++++++++++++------ src/shrpx_config.h | 3 --- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index ab427804..77fb9814 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -262,6 +262,18 @@ void worker_process_kill(int signum) { } } // namespace +namespace { +// Returns the last PID of worker process. Returns -1 if there is no +// worker process at the moment. +int worker_process_last_pid() { + if (worker_processes.empty()) { + return -1; + } + + return worker_processes.back()->worker_pid; +} +} // namespace + namespace { int chown_to_running_user(const char *path) { return chown(path, get_config()->uid, get_config()->gid); @@ -528,7 +540,7 @@ void worker_process_child_cb(struct ev_loop *loop, ev_child *w, int revents) { worker_process_remove(wp); - if (get_config()->last_worker_pid == pid) { + if (worker_process_last_pid() == pid) { ev_break(loop); } } @@ -1195,8 +1207,6 @@ int event_loop() { worker_process_add(make_unique(loop, pid, ipc_fd)); - mod_config()->last_worker_pid = pid; - // Write PID file when we are ready to accept connection from peer. // This makes easier to write restart script for nghttpx. Because // when we know that PID file is recreated, it means we can send @@ -1246,7 +1256,6 @@ void fill_default_config(Config *config) { config->num_worker = 1; config->conf_path = "/etc/nghttpx/nghttpx.conf"; config->pid = getpid(); - config->last_worker_pid = -1; if (ev_supported_backends() & ~ev_recommended_backends() & EVBACKEND_KQUEUE) { config->ev_loop_flags = ev_recommended_backends() | EVBACKEND_KQUEUE; @@ -2539,8 +2548,6 @@ void reload_config(WorkerProcess *wp) { worker_process_add(make_unique(loop, pid, ipc_fd)); - new_config->last_worker_pid = pid; - auto old_config = replace_config(new_config.release()); assert(cur_config == old_config); diff --git a/src/shrpx_config.h b/src/shrpx_config.h index c9d9815d..d3c664ac 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -727,9 +727,6 @@ struct Config { uid_t uid; gid_t gid; pid_t pid; - // With reloading feature, we may have multiple worker PIDs at the - // given moment. This field tracks the last worker PID. - pid_t last_worker_pid; bool verbose; bool daemon; bool http2_proxy;