From c44587a70cbae0985c7e4cc5c231af88c0d20331 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 24 Sep 2015 23:57:24 +0900 Subject: [PATCH] nghttpx: Use _Exit when exiting from child process --- src/shrpx.cc | 14 ++++++++------ src/shrpx.h | 2 +- src/shrpx_connection_handler.cc | 6 +++--- src/shrpx_ssl.cc | 6 ++++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index 57d546e4..a4e64ccc 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -244,6 +244,8 @@ void exec_binary(SignalServer *ssv) { return; } + // child process + shrpx_signal_unset_master_proc_ign_handler(); rv = shrpx_signal_unblock_all(); @@ -251,7 +253,7 @@ void exec_binary(SignalServer *ssv) { auto error = errno; LOG(ERROR) << "Unblocking all signals failed: " << strerror(error); - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } auto exec_path = util::get_exec_path(get_config()->argc, get_config()->argv, @@ -259,7 +261,7 @@ void exec_binary(SignalServer *ssv) { if (!exec_path) { LOG(ERROR) << "Could not resolve the executable path"; - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } auto argv = make_unique(get_config()->argc + 1); @@ -336,7 +338,7 @@ void exec_binary(SignalServer *ssv) { if (execve(argv[0], argv.get(), envp.get()) == -1) { auto error = errno; LOG(ERROR) << "execve failed: errno=" << error; - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } } } // namespace @@ -699,7 +701,7 @@ pid_t fork_worker_process(SignalServer *ssv) { auto error = errno; LOG(FATAL) << "Unblocking all signals failed: " << strerror(error); - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } close(ssv->ipc_fd[1]); @@ -708,10 +710,10 @@ pid_t fork_worker_process(SignalServer *ssv) { if (rv != 0) { LOG(FATAL) << "Worker process returned error"; - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } - exit(EXIT_SUCCESS); + _Exit(EXIT_SUCCESS); } // parent process diff --git a/src/shrpx.h b/src/shrpx.h index e2a99b3d..dfc52701 100644 --- a/src/shrpx.h +++ b/src/shrpx.h @@ -42,6 +42,6 @@ #define _Exit(status) _exit(status) #endif // !HAVE__EXIT -#define DIE() exit(EXIT_FAILURE) +#define DIE() _Exit(EXIT_FAILURE) #endif // SHRPX_H diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 5610b06b..167ecc19 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -454,7 +454,7 @@ int ConnectionHandler::start_ocsp_update(const char *cert_file) { auto error = errno; LOG(FATAL) << "Unblocking all signals failed: " << strerror(error); - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } dup2(pfd[1], 1); @@ -465,7 +465,7 @@ int ConnectionHandler::start_ocsp_update(const char *cert_file) { auto error = errno; LOG(ERROR) << "Could not execute ocsp query command: " << argv[0] << ", execve() faild, errno=" << error; - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } // unreachable } @@ -482,7 +482,7 @@ int ConnectionHandler::start_ocsp_update(const char *cert_file) { auto error = errno; LOG(FATAL) << "Restoring all signals failed: " << strerror(error); - exit(EXIT_FAILURE); + _Exit(EXIT_FAILURE); } if (pid == -1) { diff --git a/src/shrpx_ssl.cc b/src/shrpx_ssl.cc index aa35d50c..dc85b43e 100644 --- a/src/shrpx_ssl.cc +++ b/src/shrpx_ssl.cc @@ -88,6 +88,8 @@ int verify_callback(int preverify_ok, X509_STORE_CTX *ctx) { } } // namespace +// This function is meant be called from master process, hence the +// call exit(3). std::vector set_alpn_prefs(const std::vector &protos) { size_t len = 0; @@ -95,7 +97,7 @@ set_alpn_prefs(const std::vector &protos) { for (const auto &proto : protos) { if (proto.size() > 255) { LOG(FATAL) << "Too long ALPN identifier: " << proto.size(); - DIE(); + exit(EXIT_FAILURE); } len += 1 + proto.size(); @@ -103,7 +105,7 @@ set_alpn_prefs(const std::vector &protos) { if (len > (1 << 16) - 1) { LOG(FATAL) << "Too long ALPN identifier list: " << len; - DIE(); + exit(EXIT_FAILURE); } auto out = std::vector(len);