static int polrun_read_triggers(config_file_t config, const char *policy_name, policy_run_config_t *conf, char *msg_out) { int rc; unsigned int blk_index; char block_name[1024]; /* get TRIGGER blocks */ snprintf(block_name, sizeof(block_name), "%s" TRIGGER_SUFFIX, policy_name); for (blk_index = 0; blk_index < rh_config_GetNbBlocks(config); blk_index++) { char *curr_bname; config_item_t curr_item = rh_config_GetBlockByIndex(config, blk_index); critical_err_check(curr_item, "root"); if (rh_config_ItemType(curr_item) != CONFIG_ITEM_BLOCK) continue; curr_bname = rh_config_GetBlockName(curr_item); critical_err_check(curr_bname, "root"); if (!strcasecmp(curr_bname, block_name)) { conf->trigger_count++; /* realloc behaves as malloc when trigger_list is NULL */ conf->trigger_list = (trigger_item_t *) realloc(conf->trigger_list, conf-> trigger_count * sizeof (trigger_item_t)); if (conf->trigger_list == NULL) return ENOMEM; /* analyze trigger block */ rc = parse_trigger_block(curr_item, curr_bname, &conf->trigger_list[conf->trigger_count - 1], msg_out); if (rc) return rc; } } return 0; }
int Read_ResourceMon_Config( config_file_t config, void *module_config, char *msg_out, int for_reload ) { int rc; int intval; resource_monitor_config_t *conf = ( resource_monitor_config_t * ) module_config; unsigned int blc_index; static const char *purge_allowed[] = { "nb_threads_purge", "post_purge_df_latency", "purge_queue_size", "db_result_size_max", #ifdef ATTR_INDEX_status "check_purge_status_on_startup", #endif "recheck_ignored_classes", #ifdef _TMP_FS_MGR "purge_command", #endif NULL }; /* get PURGE_PARAM block */ config_item_t param_block = rh_config_FindItemByName( config, PURGE_PARAM_BLOCK ); if ( param_block != NULL ) { /* no error, because no parameter is mandatory */ /* check this is a block... */ if ( rh_config_ItemType( param_block ) != CONFIG_ITEM_BLOCK ) { strcpy( msg_out, "A block is expected for '" PURGE_PARAM_BLOCK "' item" ); return EINVAL; } /* parse parameters */ rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "nb_threads_purge", INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->nb_threads_purge, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; rc = GetDurationParam( param_block, PURGE_PARAM_BLOCK, "post_purge_df_latency", INT_PARAM_POSITIVE, /* 0 is authorized: no delay */ &intval, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc != ENOENT ) conf->post_purge_df_latency = intval; rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "purge_queue_size", INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->purge_queue_size, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "db_result_size_max", INT_PARAM_POSITIVE, ( int * ) &conf->db_request_limit, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; #ifdef ATTR_INDEX_status rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "check_purge_status_on_startup", 0, &intval, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc != ENOENT ) conf->check_purge_status_on_startup = intval; #endif rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "recheck_ignored_classes", 0, &intval, NULL, NULL, msg_out ); if ( ( rc != 0 ) && ( rc != ENOENT ) ) return rc; else if ( rc != ENOENT ) conf->recheck_ignored_classes = intval; rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "simulation_mode", 0, &intval, NULL, NULL, msg_out ); if ( rc == 0 ) { DisplayLog( LVL_CRIT, RESMONCFG_TAG, "WARNING: 'simulation_mode' parameter is deprecated. Use '--dry-run' option instead."); } #ifdef _TMP_FS_MGR rc = GetStringParam(param_block, PURGE_PARAM_BLOCK, "purge_command", STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {path}, {fid}, {fsname} */ conf->purge_command, RBH_PATH_MAX, NULL, NULL, msg_out); if ((rc != 0) && (rc != ENOENT)) return rc; #endif CheckUnknownParameters( param_block, PURGE_PARAM_BLOCK, purge_allowed ); } /* end of purge parameters */ /* get PURGE_TRIGGER blocks */ for ( blc_index = 0; blc_index < rh_config_GetNbBlocks( config ); blc_index++ ) { char *block_name; config_item_t curr_item = rh_config_GetBlockByIndex( config, blc_index ); critical_err_check( curr_item, "root" ); if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK ) continue; block_name = rh_config_GetBlockName( curr_item ); critical_err_check( block_name, "root" ); if ( !strcasecmp( block_name, TRIGGER_BLOCK ) ) { if ( conf->trigger_count == 0 ) conf->trigger_list = ( trigger_item_t * ) malloc( sizeof( trigger_item_t ) ); else conf->trigger_list = ( trigger_item_t * ) realloc( conf->trigger_list, ( conf->trigger_count + 1 ) * sizeof( trigger_item_t ) ); conf->trigger_count++; /* analyze trigger block */ rc = parse_trigger_block( curr_item, block_name, &conf->trigger_list[conf->trigger_count - 1], msg_out ); if ( rc ) return rc; } } return 0; }