Permalink
Browse files

Allow a default json config in user folder

$APPDATA/cpuminer on windows, $HOME/.cpuminer/cpuminer-conf.json on linux

will use it only if -o and --benchmark are not set
  • Loading branch information...
1 parent a0c7376 commit 26192b50a1d9003eb7124388dc7c6968e5e2d83e @tpruvot committed Feb 7, 2015
Showing with 69 additions and 6 deletions.
  1. +6 −0 .gitignore
  2. +12 −0 compat.h
  3. +22 −6 cpu-miner.c
  4. 0 example-cfg.json → cpuminer-conf.json
  5. +29 −0 util.c
View
@@ -42,4 +42,10 @@ x64/Release/
x64/Debug/
*.pdb/
+installer/
+res/cpuminer.aps
+res/RC*
+sign/
+sign.sh
+
compat/curl-for-windows/
View
@@ -25,6 +25,18 @@ static __inline int setpriority(int which, int who, int prio)
#define __thread __delclspec(thread)
#define _ALIGN(x) __declspec(align(x))
typedef int ssize_t;
+
+#include <stdlib.h>
+static __inline char * dirname(char *file) {
+ char buffer[_MAX_PATH] = { 0 };
+ char drive[_MAX_DRIVE];
+ char dir[_MAX_DIR];
+ char fname[_MAX_FNAME];
+ char ext[_MAX_EXT];
+ _splitpath_s(file, drive, _MAX_DRIVE, dir, _MAX_DIR, fname, _MAX_FNAME, ext, _MAX_EXT);
+ sprintf(buffer, "%s%s", drive, dir);
+ return strdup(buffer);
+}
#endif
#endif /* WIN32 */
View
@@ -27,13 +27,11 @@
#include <jansson.h>
#include <openssl/sha.h>
-#ifdef WIN32
+#ifdef _MSC_VER
#include <windows.h>
#include <stdint.h>
-
#else
#include <errno.h>
-#include <sys/resource.h>
#if HAVE_SYS_SYSCTL_H
#include <sys/types.h>
#if HAVE_SYS_PARAM_H
@@ -43,6 +41,10 @@
#endif
#endif
+#ifndef WIN32
+#include <sys/resource.h>
+#endif
+
#include "miner.h"
#ifdef WIN32
@@ -2346,10 +2348,10 @@ static void parse_arg(int key, char *arg)
else
fprintf(stderr, "%s:%d: %s\n",
arg, err.line, err.text);
- exit(1);
+ } else {
+ parse_config(config, arg);
+ json_decref(config);
}
- parse_config(config, arg);
- json_decref(config);
break;
}
case 'C':
@@ -2663,6 +2665,8 @@ static void show_credits()
printf("BTC donation address: 1FhDPLPpw18X4srecguG3MxJYe4a1JsZnd\n\n");
}
+void get_defconfig_path(char *out, size_t bufsize, char *argv0);
+
int main(int argc, char *argv[]) {
struct thr_info *thr;
long flags;
@@ -2679,6 +2683,18 @@ int main(int argc, char *argv[]) {
/* parse command line */
parse_cmdline(argc, argv);
+ if (!opt_benchmark && !rpc_url) {
+ // try default config file in binary folder
+ char defconfig[MAX_PATH] = { 0 };
+ get_defconfig_path(defconfig, MAX_PATH, argv[0]);
+ if (strlen(defconfig)) {
+ if (opt_debug)
+ applog(LOG_DEBUG, "Using config %s", defconfig);
+ parse_arg('c', defconfig);
+ parse_cmdline(argc, argv);
+ }
+ }
+
if (opt_algo == ALGO_QUARK) {
init_quarkhash_contexts();
} else if(opt_algo == ALGO_CRYPTONIGHT) {
File renamed without changes.
View
@@ -25,6 +25,7 @@
#include <jansson.h>
#include <curl/curl.h>
#include <time.h>
+#include <sys/stat.h>
#if defined(WIN32)
#include <winsock2.h>
#include <mstcpip.h>
@@ -34,6 +35,12 @@
#include <netinet/in.h>
#include <netinet/tcp.h>
#endif
+
+#ifndef _MSC_VER
+/* dirname() linux/mingw, else in compat.h */
+#include <libgen.h>
+#endif
+
#include "miner.h"
#include "elist.h"
@@ -148,6 +155,28 @@ void applog(int prio, const char *fmt, ...)
va_end(ap);
}
+/* Get default config.json path (will be system specific) */
+void get_defconfig_path(char *out, size_t bufsize, char *argv0)
+{
+ char *dir = dirname(argv0);
+ const char *sep = strstr(dir, "\\") ? "\\" : "/";
+#ifdef WIN32
+ snprintf(out, bufsize, "%s\\cpuminer\\cpuminer-conf.json", getenv("APPDATA"));
+#else
+ snprintf(out, bufsize, "%s\\.cpuminer\\cpuminer-conf.json", getenv("HOME"));
+#endif
+ struct stat info;
+ if (stat(out, &info) != 0) {
+ snprintf(out, bufsize, "%s%scpuminer-conf.json", dir, sep);
+ }
+ if (stat(out, &info) != 0) {
+ out[0] = '\0';
+ return;
+ }
+ out[bufsize - 1] = '\0';
+ free(dir);
+}
+
/* Modify the representation of integer numbers which would cause an overflow
* so that they are treated as floating-point numbers.
* This is a hack to overcome the limitations of some versions of Jansson. */

0 comments on commit 26192b5

Please sign in to comment.