Test(wildcard_source, test_invalid_monitor_method) { start_grabbing_messages(); cr_assert(!_parse_config("monitor-method(\"something else\"")); stop_grabbing_messages(); cr_assert(assert_grabbed_messages_contain_non_fatal("Invalid monitor-method", NULL)); reset_grabbed_messages(); }
Test(wildcard_source, test_base_dir_required_options) { start_grabbing_messages(); cr_assert(_parse_config("filename-pattern(/tmp)")); cr_assert(!cfg_init(configuration), "Config initialization should be failed"); stop_grabbing_messages(); cr_assert(assert_grabbed_messages_contain_non_fatal("base-dir option is required", NULL)); reset_grabbed_messages(); }
static WildcardSourceDriver * _create_wildcard_filesource(const gchar *wildcard_config) { cr_assert(_parse_config(wildcard_config), "Parsing the given configuration failed"); cr_assert(cfg_init(configuration), "Config initialization failed"); LogExprNode *expr_node = cfg_tree_get_object(&configuration->tree, ENC_SOURCE, "s_test"); cr_assert(expr_node != NULL); WildcardSourceDriver *driver = (WildcardSourceDriver *)expr_node->children->children->object; cr_assert(driver != NULL); return driver; }
bool parse_config(t_configuration_options *options) { /* Collate configuration file errors here for friendlier reporting */ static ItemList config_errors = { NULL, NULL }; _parse_config(options, &config_errors); if (config_errors.head != NULL) { exit_with_errors(&config_errors); } return true; }
/** * Initialize the module. This should be called only once. */ static void _initalize_tacplus(void) { enum nss_status status = NSS_STATUS_SUCCESS; struct tacplus_conf_st *conf = &G_tacplus_conf; memset(&G_tacplus_conf, 0, sizeof(G_tacplus_conf)); memset(&G_tacplus_confbuf, 0, sizeof(G_tacplus_confbuf)); G_tacplus_started = time(NULL); syslog(LOG_DEBUG, "%s: started, uid=(%u:%u), gid=(%u:%u)", __FILE__, getuid(), geteuid(), getgid(), getegid()); status = _parse_config(G_tacplus_confbuf, sizeof(G_tacplus_confbuf)); conf->status = status; conf->errnum = errno; }
/* * reload_config() * * This is only called by repmgrd after receiving a SIGHUP or when a monitoring * loop is started up; it therefore only needs to reload options required * by repmgrd, which are as follows: * * changeable options: * - failover * - follow_command * - logfacility * - logfile * - loglevel * - master_response_timeout * - monitor_interval_secs * - priority * - promote_command * - reconnect_attempts * - reconnect_interval * - retry_promote_interval_secs * - witness_repl_nodes_sync_interval_secs * * non-changeable options: * - cluster_name * - conninfo * - node * - node_name * * extract with something like: * grep local_options\\. repmgrd.c | perl -n -e '/local_options\.([\w_]+)/ && print qq|$1\n|;' | sort | uniq */ bool reload_config(t_configuration_options *orig_options) { PGconn *conn; t_configuration_options new_options = T_CONFIGURATION_OPTIONS_INITIALIZER; bool config_changed = false; bool log_config_changed = false; static ItemList config_errors = { NULL, NULL }; /* * Re-read the configuration file: repmgr.conf */ log_info(_("reloading configuration file\n")); _parse_config(&new_options, &config_errors); if (config_errors.head != NULL) { /* XXX dump errors to log */ log_warning(_("unable to parse new configuration, retaining current configuration\n")); return false; } /* The following options cannot be changed */ if (strcmp(new_options.cluster_name, orig_options->cluster_name) != 0) { log_warning(_("cluster_name cannot be changed, retaining current configuration\n")); return false; } if (new_options.node != orig_options->node) { log_warning(_("node ID cannot be changed, retaining current configuration\n")); return false; } if (strcmp(new_options.node_name, orig_options->node_name) != 0) { log_warning(_("node_name cannot be changed, keeping current configuration\n")); return false; } if (strcmp(orig_options->conninfo, new_options.conninfo) != 0) { /* Test conninfo string works*/ conn = establish_db_connection(new_options.conninfo, false); if (!conn || (PQstatus(conn) != CONNECTION_OK)) { log_warning(_("'conninfo' string is not valid, retaining current configuration\n")); return false; } PQfinish(conn); } /* * No configuration problems detected - copy any changed values * * NB: keep these in the same order as in config.h to make it easier * to manage them */ /* failover */ if (orig_options->failover != new_options.failover) { orig_options->failover = new_options.failover; config_changed = true; } /* follow_command */ if (strcmp(orig_options->follow_command, new_options.follow_command) != 0) { strcpy(orig_options->follow_command, new_options.follow_command); config_changed = true; } /* master_response_timeout */ if (orig_options->master_response_timeout != new_options.master_response_timeout) { orig_options->master_response_timeout = new_options.master_response_timeout; config_changed = true; } /* monitor_interval_secs */ if (orig_options->monitor_interval_secs != new_options.monitor_interval_secs) { orig_options->monitor_interval_secs = new_options.monitor_interval_secs; config_changed = true; } /* priority */ if (orig_options->priority != new_options.priority) { orig_options->priority = new_options.priority; config_changed = true; } /* promote_command */ if (strcmp(orig_options->promote_command, new_options.promote_command) != 0) { strcpy(orig_options->promote_command, new_options.promote_command); config_changed = true; } /* reconnect_attempts */ if (orig_options->reconnect_attempts != new_options.reconnect_attempts) { orig_options->reconnect_attempts = new_options.reconnect_attempts; config_changed = true; } /* reconnect_interval */ if (orig_options->reconnect_interval != new_options.reconnect_interval) { orig_options->reconnect_interval = new_options.reconnect_interval; config_changed = true; } /* retry_promote_interval_secs */ if (orig_options->retry_promote_interval_secs != new_options.retry_promote_interval_secs) { orig_options->retry_promote_interval_secs = new_options.retry_promote_interval_secs; config_changed = true; } /* witness_repl_nodes_sync_interval_secs */ if (orig_options->witness_repl_nodes_sync_interval_secs != new_options.witness_repl_nodes_sync_interval_secs) { orig_options->witness_repl_nodes_sync_interval_secs = new_options.witness_repl_nodes_sync_interval_secs; config_changed = true; } /* * Handle changes to logging configuration */ if (strcmp(orig_options->logfacility, new_options.logfacility) != 0) { strcpy(orig_options->logfacility, new_options.logfacility); log_config_changed = true; } if (strcmp(orig_options->logfile, new_options.logfile) != 0) { strcpy(orig_options->logfile, new_options.logfile); log_config_changed = true; } if (strcmp(orig_options->loglevel, new_options.loglevel) != 0) { strcpy(orig_options->loglevel, new_options.loglevel); log_config_changed = true; } if (log_config_changed == true) { log_notice(_("restarting logging with changed parameters\n")); logger_shutdown(); logger_init(orig_options, progname()); } if (config_changed == true) { log_notice(_("configuration file reloaded with changed parameters\n")); } /* * if logging configuration changed, don't say the configuration didn't * change, as it clearly has. */ else if (log_config_changed == false) { log_info(_("configuration has not changed\n")); } return config_changed; }