--default-config - allow command line to define the default configuration file for loading and saving
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
diff --git a/cgminer.c b/cgminer.c
index e1a37a1..8adc882 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -226,6 +226,7 @@ static struct block *blocks = NULL;
char *opt_socks_proxy = NULL;
static const char def_conf[] = "cgminer.conf";
+static char *default_config;
static bool config_loaded;
static int include_count;
#define JSON_INCLUDE_CONF "include"
@@ -1175,21 +1176,21 @@ static char *load_config(const char *arg, void __maybe_unused *unused)
return parse_config(config, true);
}
+static char *set_default_config(const char *arg)
+{
+ opt_set_charp(arg, &default_config);
+
+ return NULL;
+}
+
+void default_save_file(char *filename);
+
static void load_default_config(void)
{
cnfbuf = malloc(PATH_MAX);
-#if defined(unix)
- if (getenv("HOME") && *getenv("HOME")) {
- strcpy(cnfbuf, getenv("HOME"));
- strcat(cnfbuf, "/");
- } else
- strcpy(cnfbuf, "");
- strcat(cnfbuf, ".cgminer/");
-#else
- strcpy(cnfbuf, "");
-#endif
- strcat(cnfbuf, def_conf);
+ default_save_file(cnfbuf);
+
if (!access(cnfbuf, R_OK))
load_config(cnfbuf, NULL);
else {
@@ -1237,6 +1238,10 @@ static struct opt_table opt_cmdline_table[] = {
load_config, NULL, NULL,
"Load a JSON-format configuration file\n"
"See example.conf for an example configuration."),
+ OPT_WITH_ARG("--default-config",
+ set_default_config, NULL, NULL,
+ "Specify the filename of the default config file\n"
+ "Loaded at start and used when saving without a name."),
OPT_WITHOUT_ARG("--help|-h",
opt_verusage_and_exit, NULL,
"Print this message"),
@@ -3484,6 +3489,11 @@ retry:
void default_save_file(char *filename)
{
+ if (default_config && *default_config) {
+ strcpy(filename, default_config);
+ return;
+ }
+
#if defined(unix)
if (getenv("HOME") && *getenv("HOME")) {
strcpy(filename, getenv("HOME"));