static void parse_global_config(const char *configfile, const char *configfile_data, int configfile_len) { long l; XLU_Config *config; int e; const char *buf; config = xlu_cfg_init(stderr, configfile); if (!config) { fprintf(stderr, "Failed to allocate for configuration\n"); exit(1); } e = xlu_cfg_readdata(config, configfile_data, configfile_len); if (e) { fprintf(stderr, "Failed to parse config file: %s\n", strerror(e)); exit(1); } if (!xlu_cfg_get_long (config, "autoballoon", &l, 0)) autoballoon = l; if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; if (!xlu_cfg_get_string (config, "lockfile", &buf, 0)) lockfile = strdup(buf); else { lockfile = strdup(XL_LOCK_FILE); } if (!lockfile < 0) { fprintf(stderr, "failed to allocate lockdir \n"); exit(1); } if (!xlu_cfg_get_string (config, "vifscript", &buf, 0)) default_vifscript = strdup(buf); if (!xlu_cfg_get_string (config, "defaultbridge", &buf, 0)) default_bridge = strdup(buf); if (!xlu_cfg_get_string (config, "output_format", &buf, 0)) { if (!strcmp(buf, "json")) default_output_format = OUTPUT_FORMAT_JSON; else if (!strcmp(buf, "sxp")) default_output_format = OUTPUT_FORMAT_SXP; else { fprintf(stderr, "invalid default output format \"%s\"\n", buf); } } if (!xlu_cfg_get_string (config, "blkdev_start", &buf, 0)) blkdev_start = strdup(buf); xlu_cfg_destroy(config); }
static void parse_global_config(const char *configfile, const char *configfile_data, int configfile_len) { long l; XLU_Config *config; int e; const char *buf; config = xlu_cfg_init(stderr, configfile); if (!config) { fprintf(stderr, "Failed to allocate for configuration\n"); exit(1); } e = xlu_cfg_readdata(config, configfile_data, configfile_len); if (e) { fprintf(stderr, "Failed to parse config file: %s\n", strerror(e)); exit(1); } if (!xlu_cfg_get_string(config, "autoballoon", &buf, 0)) { if (!strcmp(buf, "on") || !strcmp(buf, "1")) autoballoon = 1; else if (!strcmp(buf, "off") || !strcmp(buf, "0")) autoballoon = 0; else if (!strcmp(buf, "auto")) autoballoon = -1; else fprintf(stderr, "invalid autoballoon option"); } if (autoballoon == -1) autoballoon = auto_autoballoon(); if (!xlu_cfg_get_long (config, "run_hotplug_scripts", &l, 0)) run_hotplug_scripts = l; if (!xlu_cfg_get_string (config, "lockfile", &buf, 0)) lockfile = strdup(buf); else { lockfile = strdup(XL_LOCK_FILE); } if (!lockfile) { fprintf(stderr, "failed to allocate lockfile\n"); exit(1); } /* * For global options that are related to a specific type of device * we use the following nomenclature: * * <device type>.default.<option name> * * This allows us to keep the default options classified for the * different device kinds. */ if (!xlu_cfg_get_string (config, "vifscript", &buf, 0)) { fprintf(stderr, "the global config option vifscript is deprecated, " "please switch to vif.default.script\n"); free(default_vifscript); default_vifscript = strdup(buf); } if (!xlu_cfg_get_string (config, "vif.default.script", &buf, 0)) { free(default_vifscript); default_vifscript = strdup(buf); } if (!xlu_cfg_get_string (config, "defaultbridge", &buf, 0)) { fprintf(stderr, "the global config option defaultbridge is deprecated, " "please switch to vif.default.bridge\n"); free(default_bridge); default_bridge = strdup(buf); } if (!xlu_cfg_get_string (config, "vif.default.bridge", &buf, 0)) { free(default_bridge); default_bridge = strdup(buf); } if (!xlu_cfg_get_string (config, "vif.default.gatewaydev", &buf, 0)) default_gatewaydev = strdup(buf); if (!xlu_cfg_get_string (config, "vif.default.backend", &buf, 0)) default_vifbackend = strdup(buf); if (!xlu_cfg_get_string (config, "output_format", &buf, 0)) { if (!strcmp(buf, "json")) default_output_format = OUTPUT_FORMAT_JSON; else if (!strcmp(buf, "sxp")) default_output_format = OUTPUT_FORMAT_SXP; else { fprintf(stderr, "invalid default output format \"%s\"\n", buf); } } if (!xlu_cfg_get_string (config, "blkdev_start", &buf, 0)) blkdev_start = strdup(buf); if (!xlu_cfg_get_long (config, "claim_mode", &l, 0)) claim_mode = l; xlu_cfg_replace_string (config, "remus.default.netbufscript", &default_remus_netbufscript, 0); xlu_cfg_destroy(config); }