From c3a73dde1e7d89a830f6d4ff66931f625098403e Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Sat, 2 Feb 2013 23:29:02 +0100 Subject: [PATCH] Gracefully deal with unknown command-line options. --- icinga-app/icinga.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/icinga-app/icinga.cpp b/icinga-app/icinga.cpp index 2b3ae47c7..b2d66235b 100644 --- a/icinga-app/icinga.cpp +++ b/icinga-app/icinga.cpp @@ -88,7 +88,16 @@ int main(int argc, char **argv) ; po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); + + try { + po::store(po::parse_command_line(argc, argv, desc), vm); + } catch (const po::unknown_option& ex) { + stringstream msgbuf; + msgbuf << "Error while parsing command-line options: " << ex.what(); + Logger::Write(LogCritical, "icinga-app", msgbuf.str()); + return EXIT_FAILURE; + } + po::notify(vm); if (vm.count("debug")) @@ -96,7 +105,6 @@ int main(int argc, char **argv) if (vm.count("help")) { std::cout << desc << "\n"; - return EXIT_SUCCESS; } -- 2.40.0