Display configuration file information when -c option is passed and only when file exists on loading default config file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/cgminer.c b/cgminer.c
index 9f2e6ba..36b3bec 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -957,12 +957,17 @@ static char *parse_config(json_t *config, bool fileconf)
return NULL;
}
+char *cnfbuf = NULL;
+
static char *load_config(const char *arg, void __maybe_unused *unused)
{
json_error_t err;
json_t *config;
char *json_error;
+ if (!cnfbuf)
+ cnfbuf = strdup(arg);
+
if (++include_count > JSON_MAX_DEPTH)
return JSON_MAX_DEPTH_ERR;
@@ -981,15 +986,16 @@ static char *load_config(const char *arg, void __maybe_unused *unused)
}
config_loaded = true;
+
/* Parse the config now, so we can override it. That can keep pointers
* so don't free config object. */
return parse_config(config, true);
}
-char cnfbuf[PATH_MAX];
-
static void load_default_config(void)
{
+ cnfbuf = malloc(PATH_MAX);
+
#if defined(unix)
if (getenv("HOME") && *getenv("HOME")) {
strcpy(cnfbuf, getenv("HOME"));
@@ -1004,6 +1010,10 @@ static void load_default_config(void)
strcat(cnfbuf, def_conf);
if (!access(cnfbuf, R_OK))
load_config(cnfbuf, NULL);
+ else {
+ free(cnfbuf);
+ cnfbuf = NULL;
+ }
}
extern const char *opt_argv0;
@@ -4558,13 +4568,13 @@ int main(int argc, char *argv[])
opt_register_table(opt_cmdline_table,
"Options for command line only");
- if (!config_loaded)
- load_default_config();
-
opt_parse(&argc, argv, applog_and_exit);
if (argc != 1)
quit(1, "Unexpected extra commandline arguments");
+ if (!config_loaded)
+ load_default_config();
+
if (opt_benchmark) {
struct pool *pool;
@@ -4591,7 +4601,7 @@ int main(int argc, char *argv[])
#endif
applog(LOG_WARNING, "Started %s", packagename);
- if (strcmp(cnfbuf, "")) {
+ if (cnfbuf) {
applog(LOG_NOTICE, "Loaded configuration file %s", cnfbuf);
switch (fileconf_load) {
case 0:
@@ -4605,6 +4615,8 @@ int main(int argc, char *argv[])
default:
break;
}
+ free(cnfbuf);
+ cnfbuf = NULL;
}
strcat(opt_kernel_path, "/");