void Alert_EndBatching() { if (alert_batching) { P(alert_mutex); alert_batching = false; /* release the mutex too */ FlushAlerts(true); } }
void Alert_EndBatching() { if ( alert_batching ) { P( alert_mutex ); alert_batching = FALSE; /* release the mutex too */ FlushAlerts(TRUE); } }
static void Alert_Add(const char *title, const char *entry, const char *info) { alert_type_t *pcurr; bool found = false; unsigned int entrylen = strlen(entry); unsigned int infolen = strlen(info); /* look for an alert with the same title */ P(alert_mutex); for (pcurr = alert_list; pcurr != NULL; pcurr = pcurr->next) { if (!strcmp(pcurr->title, title)) { /* OK, found */ found = true; break; } } /* if not found: add new alert type */ if (!found) { pcurr = (alert_type_t *) malloc(sizeof(alert_type_t)); if (!pcurr) goto out_unlock; strcpy(pcurr->title, title); pcurr->estim_size = strlen(title); pcurr->count = 0; pcurr->entries = NULL; pcurr->info = NULL; pcurr->next = alert_list; alert_list = pcurr; } /* pcurr now points to the appropriate alert type */ pcurr->count++; /* total alert count */ alert_count++; /* realloc manual (3): if ptr is NULL, the call is equivalent to * malloc(size) */ pcurr->entries = (char **)realloc(pcurr->entries, pcurr->count * (sizeof(char *))); if (!pcurr->entries) { pcurr->count = 0; goto out_unlock; } pcurr->entries[pcurr->count - 1] = (char *)malloc(entrylen + 2); strcpy(pcurr->entries[pcurr->count - 1], entry); pcurr->estim_size += entrylen; pcurr->info = (char **)realloc(pcurr->info, pcurr->count * (sizeof(char *))); if (!pcurr->info) { pcurr->count = 0; goto out_unlock; } pcurr->info[pcurr->count - 1] = (char *)malloc(infolen + 2); strcpy(pcurr->info[pcurr->count - 1], info); pcurr->estim_size += infolen; if ((log_config.batch_alert_max > 1) && (alert_count >= log_config.batch_alert_max)) { /* this also unlocks the mutex as soon as it is possible */ FlushAlerts(true); return; } out_unlock: V(alert_mutex); }
static int log_cfg_reload(log_config_t *conf) { if (conf->debug_level != log_config.debug_level) { if (!log_config.force_debug_level) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::debug_level modified: '%d'->'%d'", log_config.debug_level, conf->debug_level); log_config.debug_level = conf->debug_level; } else { DisplayLog(LVL_EVENT, "LogConfig", "Log level is forced by command " "line. Not taking configuration parameter " RBH_LOG_CONFIG_BLOCK "::debug_level into account."); } } /* log files can be changed dynamically: this will just be considered as if * it was renamed */ if (strcmp(conf->log_file, log_config.log_file)) { if (!log_config.force_log_file) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_file modified: '%s'->'%s'", log_config.log_file, conf->log_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&log.f_lock); strcpy(log_config.log_file, conf->log_file); pthread_rwlock_wrlock(&log.f_lock); } else { DisplayLog(LVL_EVENT, "LogConfig", "Log file is forced by command " "line. Not taking configuration parameter " RBH_LOG_CONFIG_BLOCK "::log_file into account."); } } if (strcmp(conf->report_file, log_config.report_file)) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::report_file modified: '%s'->'%s'", log_config.report_file, conf->report_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&report.f_lock); strcpy(log_config.report_file, conf->report_file); pthread_rwlock_unlock(&report.f_lock); } if (strcmp(conf->alert_file, log_config.alert_file)) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_file modified: '%s'->'%s'", log_config.alert_file, conf->alert_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&alert.f_lock); strcpy(log_config.alert_file, conf->alert_file); pthread_rwlock_unlock(&alert.f_lock); } if (strcmp(conf->alert_mail, log_config.alert_mail)) DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_mail changed in config file, but cannot be modified dynamically"); #ifdef HAVE_CHANGELOGS if (strcmp(conf->changelogs_file, log_config.changelogs_file)) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::changelogs_file modified: '%s'->'%s'", log_config.changelogs_file, conf->changelogs_file); /* lock file name to avoid reading inconsistent filenames */ pthread_rwlock_wrlock(&chglogs.f_lock); strcpy(log_config.changelogs_file, conf->changelogs_file); pthread_rwlock_unlock(&chglogs.f_lock); } #endif if (conf->stats_interval != log_config.stats_interval) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::stats_interval modified: " "'%" PRI_TT "'->'%" PRI_TT "'", log_config.stats_interval, conf->stats_interval); log_config.stats_interval = conf->stats_interval; } if (conf->batch_alert_max != log_config.batch_alert_max) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::batch_alert_max modified: '%u'->'%u'", log_config.batch_alert_max, conf->batch_alert_max); /* flush batched alerts first */ P(alert_mutex); if (alert_batching) /* don't release mutex */ FlushAlerts(false); log_config.batch_alert_max = conf->batch_alert_max; V(alert_mutex); } if (conf->log_process != log_config.log_process) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_procname modified: '%s'->'%s'", bool2str(log_config.log_process), bool2str(conf->log_process)); log_config.log_process = conf->log_process; } if (conf->log_host != log_config.log_host) { DisplayLog(LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_hostname modified: '%s'->'%s'", bool2str(log_config.log_host), bool2str(conf->log_host)); log_config.log_host = conf->log_host; } rbh_adjust_log_level_external(); return 0; }
int ReloadLogConfig( void *module_config ) { log_config_t *conf = ( log_config_t * ) module_config; if ( conf->debug_level != log_config.debug_level ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::debug_level modified: '%d'->'%d'", log_config.debug_level, conf->debug_level ); log_config.debug_level = conf->debug_level; } /* log files can be changed dynamically : this will just be considered as if it was renamed */ if ( strcmp( conf->log_file, log_config.log_file ) ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::log_file modified: '%s'->'%s'", log_config.log_file, conf->log_file ); /* lock file name to avoid reading inconsistent filenames */ pthread_mutex_lock( &mutex_reopen ); strcpy( log_config.log_file, conf->log_file ); pthread_mutex_unlock( &mutex_reopen ); } if ( strcmp( conf->report_file, log_config.report_file ) ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::report_file modified: '%s'->'%s'", log_config.report_file, conf->report_file ); /* lock file name to avoid reading inconsistent filenames */ pthread_mutex_lock( &mutex_reopen ); strcpy( log_config.report_file, conf->report_file ); pthread_mutex_unlock( &mutex_reopen ); } if ( strcmp( conf->alert_file, log_config.alert_file ) ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_file modified: '%s'->'%s'", log_config.alert_file, conf->alert_file ); /* lock file name to avoid reading inconsistent filenames */ pthread_mutex_lock( &mutex_reopen ); strcpy( log_config.alert_file, conf->alert_file ); pthread_mutex_unlock( &mutex_reopen ); } if ( strcmp( conf->alert_mail, log_config.alert_mail ) ) DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_mail changed in config file, but cannot be modified dynamically" ); if ( conf->stats_interval != log_config.stats_interval ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::stats_interval modified: " "'%"PRI_TT"'->'%"PRI_TT"'", log_config.stats_interval, conf->stats_interval ); log_config.stats_interval = conf->stats_interval; } if ( conf->batch_alert_max != log_config.batch_alert_max ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::batch_alert_max modified: '%u'->'%u'", log_config.batch_alert_max, conf->batch_alert_max ); /* flush batched alerts first */ P( alert_mutex ); if ( alert_batching ) /* don't release mutex */ FlushAlerts(FALSE); log_config.batch_alert_max = conf->batch_alert_max; V( alert_mutex ); } if ( conf->alert_show_attrs != log_config.alert_show_attrs ) { DisplayLog( LVL_MAJOR, "LogConfig", RBH_LOG_CONFIG_BLOCK "::alert_show_attrs modified: '%s'->'%s'", bool2str(log_config.alert_show_attrs), bool2str(conf->alert_show_attrs) ); log_config.alert_show_attrs = conf->alert_show_attrs; } return 0; }