Skip to content

Commit

Permalink
Allow a default json config in user folder
Browse files Browse the repository at this point in the history
$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
tpruvot committed Feb 8, 2015
1 parent a0c7376 commit 26192b5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,10 @@ x64/Release/
x64/Debug/
*.pdb/

installer/
res/cpuminer.aps
res/RC*
sign/
sign.sh

compat/curl-for-windows/
12 changes: 12 additions & 0 deletions compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
28 changes: 22 additions & 6 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,6 +41,10 @@
#endif
#endif

#ifndef WIN32
#include <sys/resource.h>
#endif

#include "miner.h"

#ifdef WIN32
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
File renamed without changes.
29 changes: 29 additions & 0 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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"

Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 26192b5

Please sign in to comment.