src: Handle exception in main

This commit is contained in:
Tatsuhiro Tsujikawa 2015-10-17 11:52:33 +09:00
parent 5d002ff6ca
commit 5594e3df25
6 changed files with 83 additions and 19 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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 };