From 309754749140d0ac59d4f504c6f86b4026cfa72f Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 12 Jul 2015 23:18:36 +0900 Subject: [PATCH] nghttpx: Add --include option to read additional configuration from given file --- src/shrpx.cc | 10 ++++++++++ src/shrpx_config.cc | 7 ++++++- src/shrpx_config.h | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index 7ce6aa2b..26326e2f 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -1502,6 +1502,11 @@ Misc: --conf= Load configuration from . Default: )" << get_config()->conf_path.get() << R"( + --include= + Load additional configurations from . File + is read when configuration parser encountered this + option. This option can be used multiple times, or even + recursively. -v, --version Print version and exit. -h, --help Print this help and exit. @@ -1648,6 +1653,7 @@ int main(int argc, char **argv) { {SHRPX_OPT_HEADER_FIELD_BUFFER, required_argument, &flag, 80}, {SHRPX_OPT_MAX_HEADER_FIELDS, required_argument, &flag, 81}, {SHRPX_OPT_ADD_REQUEST_HEADER, required_argument, &flag, 82}, + {SHRPX_OPT_INCLUDE, required_argument, &flag, 83}, {nullptr, 0, nullptr, 0}}; int option_index = 0; @@ -2010,6 +2016,10 @@ int main(int argc, char **argv) { // --add-request-header cmdcfgs.emplace_back(SHRPX_OPT_ADD_REQUEST_HEADER, optarg); break; + case 83: + // --include + cmdcfgs.emplace_back(SHRPX_OPT_INCLUDE, optarg); + break; default: break; } diff --git a/src/shrpx_config.cc b/src/shrpx_config.cc index ebaf2b23..49ad49a8 100644 --- a/src/shrpx_config.cc +++ b/src/shrpx_config.cc @@ -1219,6 +1219,10 @@ int parse_config(const char *opt, const char *optarg) { return parse_uint(&mod_config()->max_header_fields, opt, optarg); } + if (util::strieq(opt, SHRPX_OPT_INCLUDE)) { + return load_config(optarg); + } + if (util::strieq(opt, "conf")) { LOG(WARN) << "conf: ignored"; @@ -1248,7 +1252,8 @@ int load_config(const char *filename) { for (i = 0; i < size && line[i] != '='; ++i) ; if (i == size) { - LOG(ERROR) << "Bad configuration format at line " << linenum; + LOG(ERROR) << "Bad configuration format in " << filename << " at line " + << linenum; return -1; } line[i] = '\0'; diff --git a/src/shrpx_config.h b/src/shrpx_config.h index 3e5c869e..5f23c5b3 100644 --- a/src/shrpx_config.h +++ b/src/shrpx_config.h @@ -165,6 +165,7 @@ constexpr char SHRPX_OPT_OCSP_UPDATE_INTERVAL[] = "ocsp-update-interval"; constexpr char SHRPX_OPT_NO_OCSP[] = "no-ocsp"; constexpr char SHRPX_OPT_HEADER_FIELD_BUFFER[] = "header-field-buffer"; constexpr char SHRPX_OPT_MAX_HEADER_FIELDS[] = "max-header-fields"; +constexpr char SHRPX_OPT_INCLUDE[] = "include"; union sockaddr_union { sockaddr_storage storage;