nghttpx: Move original_argv, argv, argc, and cmdcfgs to StartupConfig
This commit is contained in:
parent
b9b648e0ed
commit
fb49182c29
63
src/shrpx.cc
63
src/shrpx.cc
|
@ -130,6 +130,25 @@ constexpr auto ENV_ACCEPT_PREFIX = StringRef::from_lit("NGHTTPX_ACCEPT_");
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// This configuration is fixed at the first startup of the main
|
||||||
|
// process, and does not change after subsequent reloadings.
|
||||||
|
struct StartupConfig {
|
||||||
|
// This contains all options given in command-line.
|
||||||
|
std::vector<std::pair<StringRef, StringRef>> cmdcfgs;
|
||||||
|
// The current working directory where this process started.
|
||||||
|
char *cwd;
|
||||||
|
// The pointer to original argv (not sure why we have this?)
|
||||||
|
char **original_argv;
|
||||||
|
// The pointer to argv, this is a deep copy of original argv.
|
||||||
|
char **argv;
|
||||||
|
// The number of elements in argv.
|
||||||
|
int argc;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
StartupConfig suconfig;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
struct InheritedAddr {
|
struct InheritedAddr {
|
||||||
// IP address if TCP socket. Otherwise, UNIX domain socket path.
|
// IP address if TCP socket. Otherwise, UNIX domain socket path.
|
||||||
ImmutableString host;
|
ImmutableString host;
|
||||||
|
@ -144,12 +163,6 @@ namespace {
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace {
|
|
||||||
// This contains all options given in command-line. Make it static so
|
|
||||||
// that we can use it in reloading.
|
|
||||||
std::vector<std::pair<StringRef, StringRef>> cmdcfgs;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void signal_cb(struct ev_loop *loop, ev_signal *w, int revents);
|
void signal_cb(struct ev_loop *loop, ev_signal *w, int revents);
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -388,21 +401,21 @@ void exec_binary(WorkerProcess *wp) {
|
||||||
_Exit(EXIT_FAILURE);
|
_Exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto exec_path = util::get_exec_path(get_config()->argc, get_config()->argv,
|
auto exec_path =
|
||||||
get_config()->cwd);
|
util::get_exec_path(suconfig.argc, suconfig.argv, suconfig.cwd);
|
||||||
|
|
||||||
if (!exec_path) {
|
if (!exec_path) {
|
||||||
LOG(ERROR) << "Could not resolve the executable path";
|
LOG(ERROR) << "Could not resolve the executable path";
|
||||||
_Exit(EXIT_FAILURE);
|
_Exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto argv = make_unique<char *[]>(get_config()->argc + 1);
|
auto argv = make_unique<char *[]>(suconfig.argc + 1);
|
||||||
|
|
||||||
argv[0] = exec_path;
|
argv[0] = exec_path;
|
||||||
for (int i = 1; i < get_config()->argc; ++i) {
|
for (int i = 1; i < suconfig.argc; ++i) {
|
||||||
argv[i] = get_config()->argv[i];
|
argv[i] = suconfig.argv[i];
|
||||||
}
|
}
|
||||||
argv[get_config()->argc] = nullptr;
|
argv[suconfig.argc] = nullptr;
|
||||||
|
|
||||||
size_t envlen = 0;
|
size_t envlen = 0;
|
||||||
for (char **p = environ; *p; ++p, ++envlen)
|
for (char **p = environ; *p; ++p, ++envlen)
|
||||||
|
@ -2504,19 +2517,15 @@ void reload_config(WorkerProcess *wp) {
|
||||||
fill_default_config(new_config.get());
|
fill_default_config(new_config.get());
|
||||||
|
|
||||||
new_config->conf_path = cur_config->conf_path;
|
new_config->conf_path = cur_config->conf_path;
|
||||||
new_config->argc = cur_config->argc;
|
// daemon option is ignored here.
|
||||||
new_config->argv = cur_config->argv;
|
new_config->daemon = cur_config->daemon;
|
||||||
new_config->original_argv = cur_config->original_argv;
|
|
||||||
new_config->cwd = cur_config->cwd;
|
|
||||||
|
|
||||||
rv = process_options(new_config.get(), cmdcfgs);
|
rv = process_options(new_config.get(), suconfig.cmdcfgs);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
LOG(ERROR) << "Failed to process new configuration";
|
LOG(ERROR) << "Failed to process new configuration";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// daemon option is ignored here.
|
|
||||||
|
|
||||||
auto iaddrs = get_inherited_addr_from_config(cur_config);
|
auto iaddrs = get_inherited_addr_from_config(cur_config);
|
||||||
|
|
||||||
if (create_acceptor_socket(new_config.get(), iaddrs) != 0) {
|
if (create_acceptor_socket(new_config.get(), iaddrs) != 0) {
|
||||||
|
@ -2582,28 +2591,30 @@ int main(int argc, char **argv) {
|
||||||
// log errors/warnings while reading configuration files.
|
// log errors/warnings while reading configuration files.
|
||||||
reopen_log_files();
|
reopen_log_files();
|
||||||
|
|
||||||
mod_config()->original_argv = argv;
|
suconfig.original_argv = argv;
|
||||||
|
|
||||||
// We have to copy argv, since getopt_long may change its content.
|
// We have to copy argv, since getopt_long may change its content.
|
||||||
mod_config()->argc = argc;
|
suconfig.argc = argc;
|
||||||
mod_config()->argv = new char *[argc];
|
suconfig.argv = new char *[argc];
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
mod_config()->argv[i] = strdup(argv[i]);
|
suconfig.argv[i] = strdup(argv[i]);
|
||||||
if (mod_config()->argv[i] == nullptr) {
|
if (suconfig.argv[i] == nullptr) {
|
||||||
auto error = errno;
|
auto error = errno;
|
||||||
LOG(FATAL) << "failed to copy argv: " << strerror(error);
|
LOG(FATAL) << "failed to copy argv: " << strerror(error);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mod_config()->cwd = getcwd(nullptr, 0);
|
suconfig.cwd = getcwd(nullptr, 0);
|
||||||
if (mod_config()->cwd == nullptr) {
|
if (suconfig.cwd == nullptr) {
|
||||||
auto error = errno;
|
auto error = errno;
|
||||||
LOG(FATAL) << "failed to get current working directory: errno=" << error;
|
LOG(FATAL) << "failed to get current working directory: errno=" << error;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto &cmdcfgs = suconfig.cmdcfgs;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
static int flag = 0;
|
static int flag = 0;
|
||||||
static option long_options[] = {
|
static option long_options[] = {
|
||||||
|
|
|
@ -717,13 +717,9 @@ struct Config {
|
||||||
ImmutableString conf_path;
|
ImmutableString conf_path;
|
||||||
ImmutableString user;
|
ImmutableString user;
|
||||||
ImmutableString mruby_file;
|
ImmutableString mruby_file;
|
||||||
char **original_argv;
|
|
||||||
char **argv;
|
|
||||||
char *cwd;
|
|
||||||
size_t num_worker;
|
size_t num_worker;
|
||||||
size_t padding;
|
size_t padding;
|
||||||
size_t rlimit_nofile;
|
size_t rlimit_nofile;
|
||||||
int argc;
|
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
gid_t gid;
|
gid_t gid;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
Loading…
Reference in New Issue