From 4a4b2cf5380f8ef51ca0a3176d97006fd3bbd734 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 8 Oct 2016 15:26:13 +0900 Subject: [PATCH] nghttpx: Embed Process into OCSPUpdateContext --- src/shrpx_connection_handler.cc | 25 ++++++++++++------------- src/shrpx_connection_handler.h | 7 +++---- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/shrpx_connection_handler.cc b/src/shrpx_connection_handler.cc index 8d99e216..eadffd8e 100644 --- a/src/shrpx_connection_handler.cc +++ b/src/shrpx_connection_handler.cc @@ -44,7 +44,6 @@ #include "shrpx_accept_handler.h" #include "shrpx_memcached_dispatcher.h" #include "shrpx_signal.h" -#include "shrpx_exec.h" #include "util.h" #include "template.h" @@ -139,7 +138,7 @@ ConnectionHandler::ConnectionHandler(struct ev_loop *loop, std::mt19937 &gen) ocsp_.chldev.data = this; ocsp_.next = 0; - ocsp_.fd = -1; + ocsp_.proc.rfd = -1; reset_ocsp(); } @@ -496,11 +495,11 @@ bool ConnectionHandler::get_graceful_shutdown() const { } void ConnectionHandler::cancel_ocsp_update() { - if (ocsp_.pid == 0) { + if (ocsp_.proc.pid == 0) { return; } - kill(ocsp_.pid, SIGTERM); + kill(ocsp_.proc.pid, SIGTERM); } // inspired by h2o_read_command function from h2o project: @@ -526,13 +525,12 @@ int ConnectionHandler::start_ocsp_update(const char *cert_file) { return -1; } - ocsp_.pid = proc.pid; - ocsp_.fd = proc.rfd; + ocsp_.proc = proc; - ev_io_set(&ocsp_.rev, ocsp_.fd, EV_READ); + ev_io_set(&ocsp_.rev, ocsp_.proc.rfd, EV_READ); ev_io_start(loop_, &ocsp_.rev); - ev_child_set(&ocsp_.chldev, ocsp_.pid, 0); + ev_child_set(&ocsp_.chldev, ocsp_.proc.pid, 0); ev_child_start(loop_, &ocsp_.chldev); return 0; @@ -542,7 +540,8 @@ void ConnectionHandler::read_ocsp_chunk() { std::array buf; for (;;) { ssize_t n; - while ((n = read(ocsp_.fd, buf.data(), buf.size())) == -1 && errno == EINTR) + while ((n = read(ocsp_.proc.rfd, buf.data(), buf.size())) == -1 && + errno == EINTR) ; if (n == -1) { @@ -614,12 +613,12 @@ void ConnectionHandler::handle_ocsp_complete() { } void ConnectionHandler::reset_ocsp() { - if (ocsp_.fd != -1) { - close(ocsp_.fd); + if (ocsp_.proc.rfd != -1) { + close(ocsp_.proc.rfd); } - ocsp_.fd = -1; - ocsp_.pid = 0; + ocsp_.proc.rfd = -1; + ocsp_.proc.pid = 0; ocsp_.error = 0; ocsp_.resp = std::vector(); } diff --git a/src/shrpx_connection_handler.h b/src/shrpx_connection_handler.h index f798b73b..d4022401 100644 --- a/src/shrpx_connection_handler.h +++ b/src/shrpx_connection_handler.h @@ -50,6 +50,7 @@ #include "shrpx_downstream_connection_pool.h" #include "shrpx_config.h" +#include "shrpx_exec.h" namespace shrpx { @@ -71,17 +72,15 @@ class CertLookupTree; struct OCSPUpdateContext { // ocsp response buffer std::vector resp; + // Process running fetch-ocsp-response script + Process proc; // index to ConnectionHandler::all_ssl_ctx_, which points to next // SSL_CTX to update ocsp response cache. size_t next; ev_child chldev; ev_io rev; - // fd to read response from fetch-ocsp-response script - int fd; // errno encountered while processing response int error; - // pid of forked fetch-ocsp-response script process - pid_t pid; }; // SerialEvent is an event sent from Worker thread.