diff --git a/src/deflatehd.cc b/src/deflatehd.cc index 565a4790..29382da9 100644 --- a/src/deflatehd.cc +++ b/src/deflatehd.cc @@ -455,4 +455,15 @@ int main(int argc, char **argv) { } // namespace nghttp2 -int main(int argc, char **argv) { return nghttp2::main(argc, argv); } +int main(int argc, char **argv) { + try { + return nghttp2::main(argc, argv); + } catch (std::bad_alloc &) { + fputs("Out of memory\n", stderr); + } catch (std::exception &x) { + fputs("Exception caught: ", stderr); + fputs(x.what(), stderr); + fputs("\n", stderr); + } + return EXIT_FAILURE; +} diff --git a/src/inflatehd.cc b/src/inflatehd.cc index 98338bef..886c6189 100644 --- a/src/inflatehd.cc +++ b/src/inflatehd.cc @@ -49,6 +49,8 @@ extern "C" { #include "comp_helper.h" } +namespace nghttp2 { + typedef struct { int dump_header_table; } inflate_config; static inflate_config config; @@ -275,3 +277,18 @@ int main(int argc, char **argv) { perform(); return 0; } + +} // namespace nghttp2 + +int main(int argc, char **argv) { + try { + return nghttp2::main(argc, argv); + } catch (std::bad_alloc &) { + fputs("Out of memory\n", stderr); + } catch (std::exception &x) { + fputs("Exception caught: ", stderr); + fputs(x.what(), stderr); + fputs("\n", stderr); + } + return EXIT_FAILURE; +} diff --git a/src/nghttp.cc b/src/nghttp.cc index ff7db189..6582deac 100644 --- a/src/nghttp.cc +++ b/src/nghttp.cc @@ -2713,4 +2713,15 @@ int main(int argc, char **argv) { } // namespace nghttp2 -int main(int argc, char **argv) { return nghttp2::main(argc, argv); } +int main(int argc, char **argv) { + try { + return nghttp2::main(argc, argv); + } catch (std::bad_alloc &) { + fputs("Out of memory\n", stderr); + } catch (std::exception &x) { + fputs("Exception caught: ", stderr); + fputs(x.what(), stderr); + fputs("\n", stderr); + } + return EXIT_FAILURE; +} diff --git a/src/nghttpd.cc b/src/nghttpd.cc index 9c97f277..9a61509a 100644 --- a/src/nghttpd.cc +++ b/src/nghttpd.cc @@ -383,4 +383,15 @@ int main(int argc, char **argv) { } // namespace nghttp2 -int main(int argc, char **argv) { return nghttp2::main(argc, argv); } +int main(int argc, char **argv) { + try { + return nghttp2::main(argc, argv); + } catch (std::bad_alloc &) { + fputs("Out of memory\n", stderr); + } catch (std::exception &x) { + fputs("Exception caught: ", stderr); + fputs(x.what(), stderr); + fputs("\n", stderr); + } + return EXIT_FAILURE; +} diff --git a/src/shrpx.cc b/src/shrpx.cc index 831fc124..82d1a75b 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -2551,4 +2551,15 @@ int main(int argc, char **argv) { } // namespace shrpx -int main(int argc, char **argv) { return shrpx::main(argc, argv); } +int main(int argc, char **argv) { + try { + return shrpx::main(argc, argv); + } catch (std::bad_alloc &) { + fputs("Out of memory\n", stderr); + } catch (std::exception &x) { + fputs("Exception caught: ", stderr); + fputs(x.what(), stderr); + fputs("\n", stderr); + } + return EXIT_FAILURE; +} diff --git a/src/shrpx_log.h b/src/shrpx_log.h index 33336913..d08f1bec 100644 --- a/src/shrpx_log.h +++ b/src/shrpx_log.h @@ -37,48 +37,51 @@ #include "shrpx_log_config.h" #include "ssl.h" -namespace shrpx { - -class Downstream; - #define ENABLE_LOG 1 -#define LOG_ENABLED(SEVERITY) (ENABLE_LOG && Log::log_enabled(SEVERITY)) +#define LOG_ENABLED(SEVERITY) (ENABLE_LOG && shrpx::Log::log_enabled(SEVERITY)) -#define LOG(SEVERITY) Log(SEVERITY, __FILE__, __LINE__) +#define LOG(SEVERITY) shrpx::Log(SEVERITY, __FILE__, __LINE__) // Listener log #define LLOG(SEVERITY, LISTEN) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[LISTEN:" << LISTEN << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[LISTEN:" << LISTEN << "] ") // Worker log #define WLOG(SEVERITY, WORKER) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[WORKER:" << WORKER << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[WORKER:" << WORKER << "] ") // ClientHandler log #define CLOG(SEVERITY, CLIENT_HANDLER) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[CLIENT_HANDLER:" << CLIENT_HANDLER \ - << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) \ + << "[CLIENT_HANDLER:" << CLIENT_HANDLER << "] ") // Upstream log #define ULOG(SEVERITY, UPSTREAM) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[UPSTREAM:" << UPSTREAM << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[UPSTREAM:" << UPSTREAM \ + << "]" \ + " ") // Downstream log #define DLOG(SEVERITY, DOWNSTREAM) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[DOWNSTREAM:" << DOWNSTREAM << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DOWNSTREAM:" << DOWNSTREAM \ + << "] ") // Downstream connection log #define DCLOG(SEVERITY, DCONN) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[DCONN:" << DCONN << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DCONN:" << DCONN << "] ") // Downstream HTTP2 session log #define SSLOG(SEVERITY, HTTP2) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[DHTTP2:" << HTTP2 << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[DHTTP2:" << HTTP2 << "] ") // Memcached connection log #define MCLOG(SEVERITY, MCONN) \ - (Log(SEVERITY, __FILE__, __LINE__) << "[MCONN:" << MCONN << "] ") + (shrpx::Log(SEVERITY, __FILE__, __LINE__) << "[MCONN:" << MCONN << "] ") + +namespace shrpx { + +class Downstream; enum SeverityLevel { INFO, NOTICE, WARN, ERROR, FATAL };