init_logger();
GlobalLogger.notice() << "started";
- ConfigurationItem configuration = get_configuration( argc, argv );
- if ( configuration.get() != NULL )
+ PingSchedulerList scheduler_list;
+ int ret_code = 0;
+ try
{
- int log_level = configuration->get_log_level();
- I2n::Logger::set_log_level( log_level ); //lint !e534
- GlobalLogger.info() << "Set LogLevel to " << I2n::Logger::get_log_level_string() << endl;
+ ConfigurationItem configuration = get_configuration( argc, argv );
+ if ( configuration.get() != NULL )
+ {
+ int log_level = configuration->get_log_level();
+ I2n::Logger::set_log_level( log_level ); //lint !e534
+ GlobalLogger.info() << "Set LogLevel to " << I2n::Logger::get_log_level_string() << endl;
- set_log_output( configuration );
+ set_log_output( configuration );
- bool daemon_mode = configuration->get_daemon();
- if ( daemon_mode )
- {
- I2n::Daemon::daemonize();
- }
+ bool daemon_mode = configuration->get_daemon();
+ if ( daemon_mode )
+ {
+ I2n::Daemon::daemonize();
+ }
- LinkStatusItem status_notifier = get_status_notifier( configuration );
+ LinkStatusItem status_notifier = get_status_notifier( configuration );
- PingSchedulerList scheduler_list;
- init_pingers( configuration, status_notifier, &scheduler_list );
+ init_pingers( configuration, status_notifier, &scheduler_list );
- start_pingers( scheduler_list );
+ start_pingers( scheduler_list );
- // React to signals (main thread will sleep)
- handle_signals( log_level );
+ // React to signals (main thread will sleep)
+ handle_signals( log_level );
+ }
+ }
+ catch ( const exception &ex )
+ {
+ GlobalLogger.error() << "Error: uncaught exception. " << ex.what() << endl;
+ ret_code = 1;
+ }
+ catch (...) {
+ GlobalLogger.error() << "Error: caught unknown exception!" << endl;
+ ret_code = 2;
+ }
+ // clean up
+ try
+ {
+ GlobalLogger.info() << "Cleaning up" << endl;
stop_pingers( scheduler_list );
-
GlobalLogger.notice() << "exiting";
}
+ catch ( const exception &ex )
+ {
+ GlobalLogger.error() << "Error: uncaught exception while cleaning up " << ex.what() << endl;
+ ret_code += 4;
+ }
+ catch (...) {
+ GlobalLogger.error() << "Error: caught unknown exception while cleaning up!" << endl;
+ ret_code += 8;
+ }
- return 0;
+ return ret_code;
}