external.append("\"");
external.append(msg);
external.append("\"");
- int ret_val = system(external.c_str());
- // TODO: parse return code and error handling
+ if ( system(external.c_str()) != 0 )
+ {
+ print_error_external_logging(external);
+ }
}
}
void Logger::print_usage(const Options_descriptionPtr opt_desc) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Usage: bpdyndnsd [Command line options]" << "\n" << endl;
void Logger::print_version() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Bullet proof dynamic dns daemon.\nbpdyndnsd " << VERSION << "." << REVISION << "." << RELEASE << endl;
void Logger::print_cmd_parsed() const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Command line options successfully parsed.",level);
}
void Logger::print_conf_files_parsed() const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Config files successfully parsed.",level);
}
void Logger::print_conf_loaded(const string& config_path) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Config files successfully loaded in: " << config_path << endl;
void Logger::print_conf_not_loaded(const string& config_path) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Config files couldn't be loaded in: " << config_path << endl;
void Logger::print_error_opening_r(const string& filename) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Error opening file for reading: " << filename << endl;
void Logger::print_error_opening_rw(const string& filename) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Error opening file for writing: " << filename << endl;
void Logger::print_destructor_call(const string& _class) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Destructor call: " << _class << endl;
void Logger::print_constructor_call(const string& _class) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Constructor call: " << _class << endl;
void Logger::print_update_service(const string& service) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Running update for service: " << service << endl;
void Logger::print_unknown_cmd_option(const string& unknown_option) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Unknown option on command line detected: " << unknown_option << endl;
void Logger::print_unknown_protocol(const string& protocol) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Unknown protocol defined: " << protocol << endl;
void Logger::print_load_service_conf(const string& filename) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Loading service config file: " << filename << endl;
void Logger::print_load_main_conf(const string& filename) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Loading main config file: " << filename << endl;
void Logger::print_unknown_service_conf_option(const string& service_conf_file, const string& unknown_option) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Unknown option in service config file detected: " << service_conf_file << " Unknown option: " << unknown_option << endl;
void Logger::print_unknown_main_conf_option(const string& unknown_option) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Unknown option in main config file detected: " << unknown_option << endl;
void Logger::print_error_config_path(const string& config_path) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Config path doesn't exists or is not a diretory: " << config_path << endl;
void Logger::print_missing_cmd_service_option() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_error("Missing option to initialize service. Protocol, host, login and password must be specified.",level);
}
void Logger::print_missing_service_conf_option(const string& service_conf_file) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Missing option in service config file " << service_conf_file << " to initialize service. Protocol, host, login and password must be specified." << endl;
void Logger::print_runnig_as_daemon(const int pid) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Runnig as daemon: " << pid << endl;
void Logger::print_daemon_mode(const bool daemon_mode) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
string mode = "disabled";
if (daemon_mode == true)
void Logger::print_error_fork() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
- log_notice("Error while trying to fork.",level);
+ log_error("Error while trying to fork.",level);
}
}
void Logger::print_pid_found(const int pid) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Pidfile found: " << pid << ". Checking if process is still runnig..." << endl;
void Logger::print_process_already_running(const int pid) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Another bpdyndnsd process with PID " << pid << " is already running!" << endl;
void Logger::print_caught_sigterm() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Caught SIGTERM. Exiting...",level);
}
void Logger::print_caught_siguser1() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Caught SIGUSR1. Switching to offline mode...",level);
}
void Logger::print_caught_sighup() const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Caught SIGHUP. Reloading config and switching to online mode...",level);
}
void Logger::print_error_setting_signal(const string& signal) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Error while setting signal handler for: " << signal << endl;
void Logger::print_init_log_facility() const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Initialized logging facility." << " Loglevel: " << Loglevel << " Syslog: " << Syslog << endl;
void Logger::print_offline_mode() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Offline mode...",level);
}
void Logger::print_serialized_objects_success() const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Serialized objects successfully.",level);
}
void Logger::print_deserialized_objects_success() const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("De-serialized objects successfully.",level);
}
void Logger::print_service_object(const string& message, const string& protocol, const string& hostname, const string& login, const string& password, const int update_interval, const int max_updates_within_interval, const int dns_cache_ttl , const string& actual_ip, list<int>* lastupdated) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << message << endl;
void Logger::print_exception_serialize(const string& exception) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Error while trying to serialize Serviceholder object: " << exception << endl;
void Logger::print_exception_deserialize(const string& exception) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Error while trying to de-serialize Serviceholder object: " << exception << endl;
void Logger::print_error_kill_child(const int pid) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Could not kill child process with PID: " << pid << endl;
void Logger::print_child_killed(const int pid) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Killed child process with PID: " << pid << endl;
void Logger::print_hostname(const string& hostname) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Detected following hostname of localhost: " << hostname << endl;
void Logger::print_own_ipv4(const string& ip_addr_v4, const string& hostname) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Detected following IPv4-Address of host: " << hostname << " : " << ip_addr_v4 << endl;
void Logger::print_own_ipv6(const string& ip_addr_v6, const string& hostname) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Detected following IPv6-Address of host: " << hostname << " : " << ip_addr_v6 << endl;
void Logger::print_error_hostname_to_ip(const string& exception, const string& hostname) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Could not resolve the hostname: " << hostname << " to an IP-Address: " << exception << endl;
void Logger::print_update_service_successful(const string& service) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Updated service successful: " << service << endl;
void Logger::print_webcheck_error(const char * curl_err_buff, const string& url) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "There was an error while trying to connect to following URL: " << url << " CURL error: " << curl_err_buff << endl;
void Logger::print_received_curl_data(const string& curl_data) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Received CURL data: " << curl_data << endl;
void Logger::print_regex_found_ip(const string& ip) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Found IP-Address via regex: " << ip << endl;
void Logger::print_multiple_cmd_option(const string& message) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "The same option is only allowed once: " << message << endl;
void Logger::print_starting_shutdown() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Shutting down ...",level);
}
void Logger::print_shutdown_succeeded() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Shutting down complete ...",level);
}
void Logger::print_shutdown_parent_succeeded() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Shutting down parent process completed ...",level);
}
void Logger::print_starting_shutdown_parent() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_notice("Shutting down parent process ...",level);
}
void Logger::print_recheck_dns_entry(const string& hostname, const int lastupdated, const int dns_cache_ttl, const int current_time) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "DNS cache record for host <" << hostname << "> expired or host will be updated for the first time: Lastupdated: " << lastupdated << " DNS cache ttl: " << dns_cache_ttl << " Current time: " << current_time << " Checking current DNS cache status." << endl;
void Logger::print_cached_dns_entry(const string& hostname, const string& cached_dns_entry, const string& lastupdated_ip) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Cached DNS record for host <" << hostname << "> : " << cached_dns_entry << " Last updated IP: " << lastupdated_ip << endl;
void Logger::print_missing_cmd_proxy_option() const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
log_error("Missing option to initialize proxy. http_proxy and http_proxy_port must be specified.",level);
}
void Logger::print_multiple_service_conf_option(const string& service_conf_file, const string& message) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Multiple occurrences of the same option in service config file detected: " << service_conf_file << " " << message << endl;
void Logger::print_multiple_main_conf_option(const string& main_conf_file, const string& message) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Multiple occurrences of the same option in main config file detected: " << main_conf_file << " " << message << endl;
void Logger::print_missing_conf_proxy_option(const string& main_conf_filename) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Missing option to initialize proxy in main config file: " << main_conf_filename << " http_proxy and http_proxy_port must be specified." << endl;
void Logger::print_no_domain_part(const string& hostname) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "There is no domain part in the given hostname: " << hostname << endl;
void Logger::print_curl_data(const string& curl_writedata_buff) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Data received by curl: " << curl_writedata_buff << endl;
void Logger::print_http_status_code(const std::string& url, const long http_code) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Requested URL: " << url << " Received HTTP status code: " << http_code << endl;
void Logger::print_regex_match(const string& regex, const string& matching_string) const
{
int level = 1;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "Regex: " << regex << " is matching in: " << matching_string << endl;
void Logger::print_exception_md5_sum(const std::string& what) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "An exception occured while computing a md5 sum: " << what << endl;
void Logger::print_network_error(const std::string& what) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "An netowrk exception occured: " << what << endl;
void Logger::print_undefined_protocol_error(const std::string& protocol, const std::string& error) const
{
int level = 0;
- if ( (level <= Loglevel) || ((level <= ExternalWarningLevel) && (!ExternalWarningLog.empty())) )
+ if ( level <= Loglevel )
{
ostringstream msg;
msg << "An undefined protocol error occured. Protocol: " << protocol << " Error: " << error << endl;
log_error(msg.str(),level);
}
}
+
+/**
+ * Error while trying to log through external program.
+ * @param external_prog The external program called.
+ */
+void Logger::print_error_external_logging(const std::string& external_prog) const
+{
+ int level = 0;
+ if ( level <= Loglevel )
+ {
+ ostringstream msg;
+ msg << "Error while trying to log through external program: " << external_prog << endl;
+ log_notice(msg.str(),level);
+ }
+}