From 0fd358ca8e2ca12ffd1d7bb5bbe30a60cdb627b4 Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Mon, 12 Jan 2015 15:33:48 +0100 Subject: [PATCH] Clean up output, whitespace, * there were several cases of GlobalLogger.error() << "Error: ..." which is redundant * there was one instance of streaming to cerr instead of GlobalLogger.error * remove trailing whitespace --- src/config/configurationcommandline.cpp | 6 ---- src/config/option/ratiorandomhostsoption.h | 2 +- src/dns/dnsresolver.cpp | 6 ++-- src/host/messagepayload.cpp | 2 +- src/host/networkinterface.hpp | 2 +- src/host/networkinterfacelist.cpp | 2 +- src/host/pingerfactory.cpp | 5 +++- src/host/pingscheduler.cpp | 2 +- src/icmp/icmppacketfactory.cpp | 2 - src/icmp/icmpv4packet.cpp | 2 +- src/icmp/icmpv6packet.cpp | 2 +- src/ip/ipv4header.cpp | 4 +- src/main.cpp | 35 +++++++++++++++++++-------- src/tcp/tcppinger.cpp | 12 ++++---- src/tcp/tcpsegmentfactory.cpp | 2 +- 15 files changed, 47 insertions(+), 39 deletions(-) diff --git a/src/config/configurationcommandline.cpp b/src/config/configurationcommandline.cpp index 2acd73a..cf5381c 100644 --- a/src/config/configurationcommandline.cpp +++ b/src/config/configurationcommandline.cpp @@ -121,12 +121,6 @@ bool ConfigurationCommandLine::process( variables_map *vm ) catch ( const std::exception &ex ) { GlobalLogger.error() << "Error parsing command line options: " << ex.what() << endl; - - if (true) // TODO: if GlobalLogger is not logging to console - { // ensure that error about command line options shows on command line - cerr << "Error parsing command line options: " << ex.what() << endl; - } - return false; } diff --git a/src/config/option/ratiorandomhostsoption.h b/src/config/option/ratiorandomhostsoption.h index 793e4c8..479caa2 100644 --- a/src/config/option/ratiorandomhostsoption.h +++ b/src/config/option/ratiorandomhostsoption.h @@ -30,7 +30,7 @@ //----------------------------------------------------------------------------- /** - * @brief This class represents the ""Ratio in (0,1] of hosts to use, picking + * @brief This class represents the ""Ratio in (0,1] of hosts to use, picking * them at random from host list" configuration option. */ class RatioRandomHostsOption : public ConfigurationOption diff --git a/src/dns/dnsresolver.cpp b/src/dns/dnsresolver.cpp index 83615d6..cf997b1 100644 --- a/src/dns/dnsresolver.cpp +++ b/src/dns/dnsresolver.cpp @@ -103,7 +103,7 @@ bool DnsResolver::resolve() size_t resolved_ip_count = answers_list.size(); if ( resolved_ip_count < 1 ) { - GlobalLogger.error() << "Error: IP host " << HostDnsAddress << " could not be resolved." << endl; + GlobalLogger.error() << "IP host " << HostDnsAddress << " could not be resolved." << endl; return false; } @@ -113,7 +113,7 @@ bool DnsResolver::resolve() } catch ( const std::exception &ex ) { - GlobalLogger.error() << "Error: host " << HostDnsAddress << " could not be resolved. " + GlobalLogger.error() << "Host " << HostDnsAddress << " could not be resolved. " << ex.what() << endl; return false; } @@ -237,7 +237,7 @@ rr_list_t DnsResolver::get_answers_list( } catch ( const std::exception &ex ) { - GlobalLogger.error() << "Error: name server " << name_server << " does not seem to be an IP address. "; + GlobalLogger.error() << "Name server " << name_server << " does not seem to be an IP address. "; throw; // forward exception to next handler } boost::net::dns::resolve resolver; diff --git a/src/host/messagepayload.cpp b/src/host/messagepayload.cpp index 4021004..ef11eac 100644 --- a/src/host/messagepayload.cpp +++ b/src/host/messagepayload.cpp @@ -409,7 +409,7 @@ istream& MessagePayload::read( istream &is ) size_t data_received_in_bytes = static_cast( is.gcount() ); if ( data_received_in_bytes != PayloadSizeInBytes ) { - GlobalLogger.error() << "Error: expecting " << PayloadSizeInBytes + GlobalLogger.error() << "Expecting " << PayloadSizeInBytes << " bytes, but received " << is.gcount() << " bytes." << endl; } diff --git a/src/host/networkinterface.hpp b/src/host/networkinterface.hpp index 8f40122..364376c 100644 --- a/src/host/networkinterface.hpp +++ b/src/host/networkinterface.hpp @@ -118,7 +118,7 @@ bool NetworkInterface::bind() if ( ret == -1 ) { I2n::Logger::GlobalLogger.error() - << "Error: could not bind pinger to interface " << Name << std::endl; + << "Could not bind pinger to interface " << Name << std::endl; return false; } diff --git a/src/host/networkinterfacelist.cpp b/src/host/networkinterfacelist.cpp index 8e30fcd..823f3ce 100644 --- a/src/host/networkinterfacelist.cpp +++ b/src/host/networkinterfacelist.cpp @@ -55,7 +55,7 @@ NetworkInterfaceList::~NetworkInterfaceList() } catch ( ... ) { - GlobalLogger.error() << "Error: could not destroy network interface list." + GlobalLogger.error() << "Could not destroy network interface list." << endl; //lint !e1551 } } //lint !e1579 diff --git a/src/host/pingerfactory.cpp b/src/host/pingerfactory.cpp index 7df5039..57d0b44 100644 --- a/src/host/pingerfactory.cpp +++ b/src/host/pingerfactory.cpp @@ -27,6 +27,8 @@ #include #include +#include + #include "boost_assert_handler.h" #include "icmp/icmppinger.h" #include "tcp/tcppinger.h" @@ -36,6 +38,7 @@ using boost::shared_ptr; using boost::asio::ip::icmp; using boost::asio::ip::tcp_raw_protocol; using boost::system::system_error; +using I2n::Logger::GlobalLogger; //----------------------------------------------------------------------------- // PingerFactory @@ -103,7 +106,7 @@ PingerItem PingerFactory::createPinger( { // Raw sockets are locked down by Unix operating systems to prevent // malware and security holes, thus it requires root access to use it. - cerr << "Error: pingcheck must run as root (" << ex.what() << ")" << endl; + GlobalLogger.error() << "Pingcheck must run as root (" << ex.what() << ")" << endl; exit( EXIT_FAILURE ); } diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index e7b9e3e..b11cbf1 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -148,7 +148,7 @@ void PingScheduler::resolve_and_ping() // determine if address resolution is required if ( !ips_up_to_date ) { - ips_up_to_date = Ping->resolve_ping_address(); // try to resolve + ips_up_to_date = Ping->resolve_ping_address(); // try to resolve if ( ips_up_to_date ) { EverHadAnyIP = true; diff --git a/src/icmp/icmppacketfactory.cpp b/src/icmp/icmppacketfactory.cpp index 6fe8f8c..c9042bd 100644 --- a/src/icmp/icmppacketfactory.cpp +++ b/src/icmp/icmppacketfactory.cpp @@ -77,8 +77,6 @@ IcmpPacketItem IcmpPacketFactory::create_icmp_packet( << IcmpPacket::return_code_to_string(return_code) << endl; icmp_packet.reset(); // --> (!icmp_packet) is true // --> icmp_pinger will not try to continue working with this packet - - // TODO why good packets are reports as bad? The read() has problems! } else if ( !is.good() ) { diff --git a/src/icmp/icmpv4packet.cpp b/src/icmp/icmpv4packet.cpp index 20433dc..4918aa5 100644 --- a/src/icmp/icmpv4packet.cpp +++ b/src/icmp/icmpv4packet.cpp @@ -248,7 +248,7 @@ IcmpPacket::ReadReturnCode Icmpv4Packet::read( istream &is ) // try to read that amount of data if ( data_length < 0 ) { - GlobalLogger.error() << "Error: invalid size for optional ICMP data: " + GlobalLogger.error() << "Invalid size for optional ICMP data: " << data_length << endl; is.setstate( ios::failbit ); return IcmpPacket::ReadReturnCode_INVALID_SIZE; diff --git a/src/icmp/icmpv6packet.cpp b/src/icmp/icmpv6packet.cpp index 5545add..38910cb 100644 --- a/src/icmp/icmpv6packet.cpp +++ b/src/icmp/icmpv6packet.cpp @@ -263,7 +263,7 @@ IcmpPacket::ReadReturnCode Icmpv6Packet::read( istream &is ) // try to read that amount of data if ( data_length < 0 ) { - GlobalLogger.error() << "Error: invalid size for optional ICMP data: " + GlobalLogger.error() << "Invalid size for optional ICMP data: " << data_length << endl; is.setstate( ios::failbit ); return IcmpPacket::ReadReturnCode_INVALID_SIZE; diff --git a/src/ip/ipv4header.cpp b/src/ip/ipv4header.cpp index 1235f7b..821f0e7 100644 --- a/src/ip/ipv4header.cpp +++ b/src/ip/ipv4header.cpp @@ -220,7 +220,7 @@ istream &operator>>( uint8_t header_version = header.get_version(); if ( header_version != 4 ) { - GlobalLogger.error() << "Error: invalid IP header version: " << static_cast(header_version) << endl; + GlobalLogger.error() << "Invalid IP header version: " << static_cast(header_version) << endl; is.setstate( ios::failbit ); return is; @@ -232,7 +232,7 @@ istream &operator>>( static_cast( Ipv4HeaderSizeInBytes ); if ( ( options_length < 0 ) || ( 40 < options_length ) ) { - GlobalLogger.error() << "Error: invalid IP options length value:" << options_length << endl; + GlobalLogger.error() << "Invalid IP options length value:" << options_length << endl; is.setstate( ios::failbit ); } else if ( ( 0 < options_length ) && ( options_length <= 40 ) ) diff --git a/src/main.cpp b/src/main.cpp index 09881b9..2e2d9e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,7 +65,7 @@ LinkStatusItem get_status_notifier(const ConfigurationItem&); void init_logger(); void set_log_output(const ConfigurationItem &); DelayMap calc_pinger_delays(const HostList &hosts); -void init_pingers(const IoServiceItem, const ConfigurationItem&, +void init_pingers(const IoServiceItem, const ConfigurationItem&, const LinkStatusItem&, PingSchedulerList*); void start_pingers(const PingSchedulerList&); void stop_pingers(const PingSchedulerList&); @@ -141,12 +141,11 @@ LinkStatusItem get_status_notifier( void init_logger() { - // set default: log at level NOTICE to syslog - const int default_log_level = I2n::Logger::LogLevel::Notice; - + // set default: log at level NOTICE to syslog and stderr + // to ensure that in case of faulty config, the error is noticed I2n::Logger::enable_syslog( I2n::Logger::Facility::User ); I2n::Logger::enable_stderr_log( true ); - I2n::Logger::set_log_level( default_log_level ); + I2n::Logger::set_log_level( I2n::Logger::LogLevel::Notice ); } void set_log_output( @@ -182,7 +181,7 @@ void set_log_output( * * If there are many pingers with same interval, will get bursts of pings * and none in-between. This function calculates delays for large numbers - * of hosts with same ping intervals, to distribute them as evenly as + * of hosts with same ping intervals, to distribute them as evenly as * possible, right from the start (might diverge over time, anyway). * * Will not do much good for pingers with many different intervals, but @@ -303,12 +302,25 @@ void stop_pingers( // the one instance of signal_data_struct signal_data_struct signal_data; + +/// registered as signal handler; mainly sets signal_data.signaled_flag void signal_handler(int param) { - GlobalLogger.info() << "signal handler called with param " << param << endl; + if (param == SIGUSR1) + GlobalLogger.debug() << "signal handler called with SIGUSR1." << endl; + else if (param == SIGUSR2) + GlobalLogger.debug() << "signal handler called with SIGUSR2." << endl; + else if (param == SIGTERM) + GlobalLogger.debug() << "signal handler called with SIGTERM." << endl; + else if (param == SIGINT) + GlobalLogger.debug() << "signal handler called with SIGINT." << endl; + else + GlobalLogger.warning() << "signal handler called with unexpected signal " << param << endl; signal_data.signaled_flag = param; } + +/// called regularly from io_service; checks signal_data.signal_flag void signal_checker( const boost::system::error_code &error ) { bool want_stop = false; @@ -322,7 +334,8 @@ void signal_checker( const boost::system::error_code &error ) } else { - GlobalLogger.error() << "not implemented yet! Stopping io_service" << endl; + GlobalLogger.error() << "Signal check timer handler received error code " << error + << "! Stopping io_service" << endl; want_stop = true; } } @@ -337,18 +350,18 @@ void signal_checker( const boost::system::error_code &error ) { int new_log_level = I2n::Logger::get_log_level()+1; I2n::Logger::set_log_level( new_log_level ); - GlobalLogger.info() << "Increased log level to " + GlobalLogger.debug() << "Increased log level to " << I2n::Logger::get_log_level_string(); } else if ( signaled_flag == SIGUSR2 ) { I2n::Logger::set_log_level( signal_data.config_log_level ); - GlobalLogger.info() << "Reset log level to normal (" + GlobalLogger.debug() << "Reset log level to normal (" << I2n::Logger::get_log_level_string() << ")"; } else if ( ( signaled_flag == SIGTERM ) || ( signaled_flag == SIGINT )) { - GlobalLogger.info() << "Received signal SIGINT/SIGTERM --> will stop" << endl; + GlobalLogger.debug() << "Received signal SIGINT/SIGTERM --> will stop" << endl; want_stop = true; } } diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index fa99849..22ddf1a 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -87,7 +87,7 @@ TcpPinger::TcpPinger( { if ( !NetInterface.bind() ) { - GlobalLogger.error() << "Error: could not bind the socket with the local interface. " + GlobalLogger.error() << "Could not bind the socket with the local interface. " << ::strerror( errno ) << endl; } @@ -192,7 +192,7 @@ void TcpPinger::send_ack_request( const TcpSegmentItem tcp_segment ) ostream os( &request_buffer ); if ( !tcp_segment->write( os ) ) { - GlobalLogger.error() << "Error: fail writing ping data." << endl; + GlobalLogger.error() << "Fail writing ping data." << endl; } TimeSent = microsec_clock::universal_time(); @@ -209,13 +209,13 @@ void TcpPinger::send_ack_request( const TcpSegmentItem tcp_segment ) size_t bytes_sent = Socket.send_to( data, DestinationEndpoint ); if ( bytes_sent != buffer_size( data ) ) { - GlobalLogger.error() << "Error: fail sending ping data." + GlobalLogger.error() << "Fail sending ping data." << "Amount of bytes sent differs from the buffer." << endl; } } catch ( const exception &ex ) { - GlobalLogger.error() << "Error: fail sending ping data. " << ex.what() << endl; + GlobalLogger.error() << "Fail sending ping data. " << ex.what() << endl; } // Tell how long to wait for the reply @@ -278,7 +278,7 @@ void TcpPinger::handle_receive_tcp_segment( const size_t &bytes_transferred ) istream is( &ReplyBuffer ); if ( !is ) { - GlobalLogger.error() << "Error: can't handle ReplyBuffer" << endl; + GlobalLogger.error() << "Can't handle ReplyBuffer" << endl; return; } @@ -319,7 +319,7 @@ void TcpPinger::handle_receive_tcp_segment( const size_t &bytes_transferred ) } catch ( ... ) { - GlobalLogger.notice() << "Warning: exception during ICMP parse. " + GlobalLogger.notice() << "Exception during ICMP parse. " << "Starting another receive till timeout." << endl; start_receive(); } diff --git a/src/tcp/tcpsegmentfactory.cpp b/src/tcp/tcpsegmentfactory.cpp index 5d6bcde..226725a 100644 --- a/src/tcp/tcpsegmentfactory.cpp +++ b/src/tcp/tcpsegmentfactory.cpp @@ -70,7 +70,7 @@ TcpSegmentItem TcpSegmentFactory::create_tcp_segment( if ( !tcp_segment->read( is ) ) { - GlobalLogger.error() << "Error: could not read TCP Segment." << endl; + GlobalLogger.error() << "Could not read TCP Segment." << endl; } return tcp_segment; -- 1.7.1