From 7f086605b5d23f42651dfbf430b3c25f14799c9f Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Fri, 15 Nov 2019 12:40:00 +0100 Subject: Throw, catch and exit on bad port value, rather than straight exit --- configd/src/apps/sentinel/config-handler.cpp | 6 +++--- configd/src/apps/sentinel/sentinel.cpp | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/configd/src/apps/sentinel/config-handler.cpp b/configd/src/apps/sentinel/config-handler.cpp index a73a5f01f33..7b68e6c8150 100644 --- a/configd/src/apps/sentinel/config-handler.cpp +++ b/configd/src/apps/sentinel/config-handler.cpp @@ -5,6 +5,8 @@ #include #include +#include +#include #include #include @@ -24,9 +26,7 @@ ConfigHandler::configure_port(int port) } } if (port <= 0 || port > 65535) { - LOG(error, "Fatal: bad port %d, expected range [1,65535]", port); - EV_STOPPING("config-sentinel", "bad port"); - exit(EXIT_FAILURE); + throw vespalib::FatalException("Bad port " + std::to_string(port) + ", expected range [1, 65535]", VESPA_STRLOC); } if (port != _boundPort) { LOG(debug, "Config-sentinel accepts connections on port %d", port); diff --git a/configd/src/apps/sentinel/sentinel.cpp b/configd/src/apps/sentinel/sentinel.cpp index 741eb5514bb..126c59d42f3 100644 --- a/configd/src/apps/sentinel/sentinel.cpp +++ b/configd/src/apps/sentinel/sentinel.cpp @@ -91,6 +91,10 @@ main(int argc, char **argv) LOG(error, "Fatal: %s", ex.getMessage().c_str()); EV_STOPPING("config-sentinel", ex.what()); exit(EXIT_FAILURE); + } catch (vespalib::FatalException& ex) { + LOG(error, "Fatal: %s", ex.getMessage().c_str()); + EV_STOPPING("config-sentinel", ex.what()); + exit(EXIT_FAILURE); } if (vespalib::SignalHandler::CHLD.check()) { continue; -- cgit v1.2.3