Browse Source

Display configuration file information when -c option is passed and only when file exists on loading default config file.

nfactor-troky
Con Kolivas 13 years ago
parent
commit
d6edd07c4a
  1. 24
      cgminer.c

24
cgminer.c

@ -957,12 +957,17 @@ static char *parse_config(json_t *config, bool fileconf)
return NULL; return NULL;
} }
char *cnfbuf = NULL;
static char *load_config(const char *arg, void __maybe_unused *unused) static char *load_config(const char *arg, void __maybe_unused *unused)
{ {
json_error_t err; json_error_t err;
json_t *config; json_t *config;
char *json_error; char *json_error;
if (!cnfbuf)
cnfbuf = strdup(arg);
if (++include_count > JSON_MAX_DEPTH) if (++include_count > JSON_MAX_DEPTH)
return JSON_MAX_DEPTH_ERR; return JSON_MAX_DEPTH_ERR;
@ -981,15 +986,16 @@ static char *load_config(const char *arg, void __maybe_unused *unused)
} }
config_loaded = true; config_loaded = true;
/* Parse the config now, so we can override it. That can keep pointers /* Parse the config now, so we can override it. That can keep pointers
* so don't free config object. */ * so don't free config object. */
return parse_config(config, true); return parse_config(config, true);
} }
char cnfbuf[PATH_MAX];
static void load_default_config(void) static void load_default_config(void)
{ {
cnfbuf = malloc(PATH_MAX);
#if defined(unix) #if defined(unix)
if (getenv("HOME") && *getenv("HOME")) { if (getenv("HOME") && *getenv("HOME")) {
strcpy(cnfbuf, getenv("HOME")); strcpy(cnfbuf, getenv("HOME"));
@ -1004,6 +1010,10 @@ static void load_default_config(void)
strcat(cnfbuf, def_conf); strcat(cnfbuf, def_conf);
if (!access(cnfbuf, R_OK)) if (!access(cnfbuf, R_OK))
load_config(cnfbuf, NULL); load_config(cnfbuf, NULL);
else {
free(cnfbuf);
cnfbuf = NULL;
}
} }
extern const char *opt_argv0; extern const char *opt_argv0;
@ -4558,13 +4568,13 @@ int main(int argc, char *argv[])
opt_register_table(opt_cmdline_table, opt_register_table(opt_cmdline_table,
"Options for command line only"); "Options for command line only");
if (!config_loaded)
load_default_config();
opt_parse(&argc, argv, applog_and_exit); opt_parse(&argc, argv, applog_and_exit);
if (argc != 1) if (argc != 1)
quit(1, "Unexpected extra commandline arguments"); quit(1, "Unexpected extra commandline arguments");
if (!config_loaded)
load_default_config();
if (opt_benchmark) { if (opt_benchmark) {
struct pool *pool; struct pool *pool;
@ -4591,7 +4601,7 @@ int main(int argc, char *argv[])
#endif #endif
applog(LOG_WARNING, "Started %s", packagename); applog(LOG_WARNING, "Started %s", packagename);
if (strcmp(cnfbuf, "")) { if (cnfbuf) {
applog(LOG_NOTICE, "Loaded configuration file %s", cnfbuf); applog(LOG_NOTICE, "Loaded configuration file %s", cnfbuf);
switch (fileconf_load) { switch (fileconf_load) {
case 0: case 0:
@ -4605,6 +4615,8 @@ int main(int argc, char *argv[])
default: default:
break; break;
} }
free(cnfbuf);
cnfbuf = NULL;
} }
strcat(opt_kernel_path, "/"); strcat(opt_kernel_path, "/");

Loading…
Cancel
Save