Merge pull request #209 from kanoi/977aecc4a60928d05719e3b0b534335b1f82effa API save default config file if none specified
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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
diff --git a/API-README b/API-README
index 706ffb0..0782457 100644
--- a/API-README
+++ b/API-README
@@ -200,6 +200,8 @@ The list of requests - a (*) means it requires privileged access - and replies a
none There is no reply section just the STATUS section
stating success or failure saving the cgminer config
to filename
+ The filename is optional and will use the cgminer
+ default if not specified
quit (*) none There is no status section but just a single "BYE"
reply before cgminer quits
@@ -283,7 +285,17 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
-API V1.10
+API V1.11
+
+Modified API commands:
+ 'save' no longer requires a filename (use default if not specified)
+
+'save' incorrectly returned status E (error) on success before.
+It now correctly returns S (success)
+
+----------
+
+API V1.10 (cgminer v2.4.1)
Added API commands:
'stats'
diff --git a/api.c b/api.c
index 731c4e1..b644149 100644
--- a/api.c
+++ b/api.c
@@ -161,7 +161,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.10";
+static const char *APIVERSION = "1.11";
static const char *DEAD = "Dead";
static const char *SICK = "Sick";
static const char *NOSTART = "NoStart";
@@ -465,7 +465,7 @@ struct CODES {
{ SEVERITY_SUCC, MSG_GPUFAN, PARAM_BOTH, "Setting GPU %d fan to (%s) reported succeess" },
{ SEVERITY_ERR, MSG_MISFN, PARAM_NONE, "Missing save filename parameter" },
{ SEVERITY_ERR, MSG_BADFN, PARAM_STR, "Can't open or create save file '%s'" },
- { SEVERITY_ERR, MSG_SAVED, PARAM_STR, "Configuration saved to file '%s'" },
+ { SEVERITY_SUCC, MSG_SAVED, PARAM_STR, "Configuration saved to file '%s'" },
{ SEVERITY_ERR, MSG_ACCDENY, PARAM_STR, "Access denied to '%s' command" },
{ SEVERITY_SUCC, MSG_ACCOK, PARAM_NONE, "Privileged access OK" },
{ SEVERITY_SUCC, MSG_ENAPOOL, PARAM_POOL, "Enabling pool %d:'%s'" },
@@ -1979,12 +1979,13 @@ static void devdetails(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
{
+ char filename[PATH_MAX];
FILE *fcfg;
char *ptr;
if (param == NULL || *param == '\0') {
- strcpy(io_buffer, message(MSG_MISFN, 0, NULL, isjson));
- return;
+ default_save_file(filename);
+ param = filename;
}
fcfg = fopen(param, "w");
diff --git a/cgminer.c b/cgminer.c
index 9565fc1..cb4f6f2 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3006,6 +3006,23 @@ retry:
}
#endif
+void default_save_file(char *filename)
+{
+#if defined(unix)
+ if (getenv("HOME") && *getenv("HOME")) {
+ strcpy(filename, getenv("HOME"));
+ strcat(filename, "/");
+ }
+ else
+ strcpy(filename, "");
+ strcat(filename, ".cgminer/");
+ mkdir(filename, 0777);
+#else
+ strcpy(filename, "");
+#endif
+ strcat(filename, def_conf);
+}
+
#ifdef HAVE_CURSES
static void set_options(void)
{
@@ -3066,19 +3083,7 @@ retry:
FILE *fcfg;
char *str, filename[PATH_MAX], prompt[PATH_MAX + 50];
-#if defined(unix)
- if (getenv("HOME") && *getenv("HOME")) {
- strcpy(filename, getenv("HOME"));
- strcat(filename, "/");
- }
- else
- strcpy(filename, "");
- strcat(filename, ".cgminer/");
- mkdir(filename, 0777);
-#else
- strcpy(filename, "");
-#endif
- strcat(filename, def_conf);
+ default_save_file(filename);
sprintf(prompt, "Config filename to write (Enter for default) [%s]", filename);
str = curses_input(prompt);
if (strcmp(str, "-1")) {
diff --git a/miner.h b/miner.h
index 4e2f752..ec9d725 100644
--- a/miner.h
+++ b/miner.h
@@ -742,6 +742,7 @@ extern void kill_work(void);
extern void switch_pools(struct pool *selected);
extern void remove_pool(struct pool *pool);
extern void write_config(FILE *fcfg);
+extern void default_save_file(char *filename);
extern void log_curses(int prio, const char *f, va_list ap);
extern void clear_logwin(void);
extern bool pool_tclear(struct pool *pool, bool *var);