|
|
|
@ -7,7 +7,7 @@
@@ -7,7 +7,7 @@
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it |
|
|
|
|
* under the terms of the GNU General Public License as published by the Free |
|
|
|
|
* Software Foundation; either version 3 of the License, or (at your option) |
|
|
|
|
* any later version. See COPYING for more details. |
|
|
|
|
* any later version. See COPYING for more details. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
@ -43,20 +43,20 @@
@@ -43,20 +43,20 @@
|
|
|
|
|
#include "pool.h" |
|
|
|
|
|
|
|
|
|
#if defined(unix) || defined(__APPLE__) |
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <fcntl.h> |
|
|
|
|
#include <sys/wait.h> |
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <fcntl.h> |
|
|
|
|
#include <sys/wait.h> |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
char *cnfbuf = NULL; //config file loaded
|
|
|
|
|
int fileconf_load; //config file load status
|
|
|
|
|
int fileconf_load; //config file load status
|
|
|
|
|
const char def_conf[] = "sgminer.conf"; |
|
|
|
|
char *default_config; |
|
|
|
|
bool config_loaded; |
|
|
|
|
//static int include_count;
|
|
|
|
|
|
|
|
|
|
int json_array_index = -1; //current array index being parsed
|
|
|
|
|
char *last_json_error = NULL; //last json_error
|
|
|
|
|
int json_array_index = -1; //current array index being parsed
|
|
|
|
|
char *last_json_error = NULL; //last json_error
|
|
|
|
|
//#define JSON_INCLUDE_CONF "include"
|
|
|
|
|
#define JSON_LOAD_ERROR "JSON decode of file '%s' failed\n %s" |
|
|
|
|
#define JSON_LOAD_ERROR_LEN strlen(JSON_LOAD_ERROR) |
|
|
|
@ -72,37 +72,37 @@ int total_profiles;
@@ -72,37 +72,37 @@ int total_profiles;
|
|
|
|
|
|
|
|
|
|
static struct profile *add_profile() |
|
|
|
|
{ |
|
|
|
|
struct profile *profile; |
|
|
|
|
char buf[32]; |
|
|
|
|
struct profile *profile; |
|
|
|
|
char buf[32]; |
|
|
|
|
|
|
|
|
|
if(!(profile = (struct profile *)calloc(sizeof(struct profile), 1))) |
|
|
|
|
quit(1, "Failed to calloc profile in add_profile"); |
|
|
|
|
profile->profile_no = total_profiles; |
|
|
|
|
if(!(profile = (struct profile *)calloc(sizeof(struct profile), 1))) |
|
|
|
|
quit(1, "Failed to calloc profile in add_profile"); |
|
|
|
|
profile->profile_no = total_profiles; |
|
|
|
|
|
|
|
|
|
//default profile name is the profile index
|
|
|
|
|
sprintf(buf, "%d", profile->profile_no); |
|
|
|
|
profile->name = strdup(buf); |
|
|
|
|
//default profile name is the profile index
|
|
|
|
|
sprintf(buf, "%d", profile->profile_no); |
|
|
|
|
profile->name = strdup(buf); |
|
|
|
|
|
|
|
|
|
profiles = (struct profile **)realloc(profiles, sizeof(struct profile *) * (total_profiles + 2)); |
|
|
|
|
profiles[total_profiles++] = profile; |
|
|
|
|
profiles = (struct profile **)realloc(profiles, sizeof(struct profile *) * (total_profiles + 2)); |
|
|
|
|
profiles[total_profiles++] = profile; |
|
|
|
|
|
|
|
|
|
return profile; |
|
|
|
|
return profile; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//only used while loading config
|
|
|
|
|
static struct profile *get_current_profile() |
|
|
|
|
{ |
|
|
|
|
while ((json_array_index + 1) > total_profiles) |
|
|
|
|
add_profile(); |
|
|
|
|
while ((json_array_index + 1) > total_profiles) |
|
|
|
|
add_profile(); |
|
|
|
|
|
|
|
|
|
if (json_array_index < 0) |
|
|
|
|
{ |
|
|
|
|
if (!total_profiles) |
|
|
|
|
add_profile(); |
|
|
|
|
return profiles[total_profiles - 1]; |
|
|
|
|
} |
|
|
|
|
if (json_array_index < 0) |
|
|
|
|
{ |
|
|
|
|
if (!total_profiles) |
|
|
|
|
add_profile(); |
|
|
|
|
return profiles[total_profiles - 1]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return profiles[json_array_index]; |
|
|
|
|
return profiles[json_array_index]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//find a profile by name
|
|
|
|
@ -122,53 +122,53 @@ static struct profile *get_profile(char *name)
@@ -122,53 +122,53 @@ static struct profile *get_profile(char *name)
|
|
|
|
|
/******* Default profile functions used during config parsing *****/ |
|
|
|
|
char *set_default_intensity(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.intensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
default_profile.intensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_xintensity(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.xintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
default_profile.xintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_rawintensity(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.rawintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
default_profile.rawintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_thread_concurrency(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.thread_concurrency = arg; |
|
|
|
|
return NULL; |
|
|
|
|
default_profile.thread_concurrency = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ADL |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_engine(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_engine = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_memclock(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_memclock = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_threads(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_threads = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_fan(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_fan = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
char *set_default_gpu_engine(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_engine = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_memclock(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_memclock = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_threads(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_threads = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_gpu_fan(const char *arg) |
|
|
|
|
{ |
|
|
|
|
default_profile.gpu_fan = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
@ -181,92 +181,92 @@ char *set_default_profile(char *arg)
@@ -181,92 +181,92 @@ char *set_default_profile(char *arg)
|
|
|
|
|
/****** Profile functions used in during config parsing ********/ |
|
|
|
|
char *set_profile_name(char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "Setting profile %i name to %s", profile->profile_no, arg); |
|
|
|
|
opt_set_charp(arg, &profile->name); |
|
|
|
|
applog(LOG_DEBUG, "Setting profile %i name to %s", profile->profile_no, arg); |
|
|
|
|
opt_set_charp(arg, &profile->name); |
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_algorithm(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
|
|
|
|
|
//applog(LOG_DEBUG, "Setting profile %s algorithm to %s", profile->name, arg);
|
|
|
|
|
set_algorithm(&profile->algorithm, arg); |
|
|
|
|
//applog(LOG_DEBUG, "Setting profile %s algorithm to %s", profile->name, arg);
|
|
|
|
|
set_algorithm(&profile->algorithm, arg); |
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_intensity(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->intensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->intensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_xintensity(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->xintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->xintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_rawintensity(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->rawintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->rawintensity = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_thread_concurrency(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->thread_concurrency = arg; |
|
|
|
|
return NULL; |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->thread_concurrency = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ADL |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_engine(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_engine = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_memclock(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_memclock = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_threads(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_threads = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_fan(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_fan = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
char *set_profile_gpu_engine(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_engine = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_memclock(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_memclock = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_threads(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_threads = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_profile_gpu_fan(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
profile->gpu_fan = arg; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
char *set_profile_nfactor(const char *arg) |
|
|
|
|
{ |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
struct profile *profile = get_current_profile(); |
|
|
|
|
|
|
|
|
|
applog(LOG_DEBUG, "Setting profile %s N-factor to %s", profile->name, arg); |
|
|
|
|
set_algorithm_nfactor(&profile->algorithm, (const uint8_t) atoi(arg)); |
|
|
|
|
applog(LOG_DEBUG, "Setting profile %s N-factor to %s", profile->name, arg); |
|
|
|
|
set_algorithm_nfactor(&profile->algorithm, (const uint8_t) atoi(arg)); |
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/***************************************
|
|
|
|
@ -276,28 +276,28 @@ char *set_profile_nfactor(const char *arg)
@@ -276,28 +276,28 @@ char *set_profile_nfactor(const char *arg)
|
|
|
|
|
void set_last_json_error(const char *fmt, ...) |
|
|
|
|
{ |
|
|
|
|
va_list args; |
|
|
|
|
size_t bufsize; |
|
|
|
|
size_t bufsize; |
|
|
|
|
|
|
|
|
|
//build args
|
|
|
|
|
//build args
|
|
|
|
|
va_start(args, fmt); |
|
|
|
|
//get final string buffer size
|
|
|
|
|
//get final string buffer size
|
|
|
|
|
bufsize = vsnprintf(NULL, 0, JSON_LOAD_ERROR, args); |
|
|
|
|
va_end(args); |
|
|
|
|
|
|
|
|
|
//if NULL allocate memory... otherwise reallocate
|
|
|
|
|
if(!last_json_error) |
|
|
|
|
{ |
|
|
|
|
if(!(last_json_error = (char *)malloc(bufsize+1))) |
|
|
|
|
quit(1, "Malloc failure in json error"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if(!(last_json_error = (char *)realloc(last_json_error, bufsize+1))) |
|
|
|
|
quit(1, "Realloc failure in json error"); |
|
|
|
|
} |
|
|
|
|
//if NULL allocate memory... otherwise reallocate
|
|
|
|
|
if(!last_json_error) |
|
|
|
|
{ |
|
|
|
|
if(!(last_json_error = (char *)malloc(bufsize+1))) |
|
|
|
|
quit(1, "Malloc failure in json error"); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
if(!(last_json_error = (char *)realloc(last_json_error, bufsize+1))) |
|
|
|
|
quit(1, "Realloc failure in json error"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//zero out buffer
|
|
|
|
|
memset(last_json_error, '\0', bufsize+1); |
|
|
|
|
memset(last_json_error, '\0', bufsize+1); |
|
|
|
|
|
|
|
|
|
//get args again
|
|
|
|
|
va_start(args, fmt); |
|
|
|
@ -308,34 +308,34 @@ void set_last_json_error(const char *fmt, ...)
@@ -308,34 +308,34 @@ void set_last_json_error(const char *fmt, ...)
|
|
|
|
|
//find opt by name in an opt table
|
|
|
|
|
static struct opt_table *opt_find(struct opt_table *tbl, char *optname) |
|
|
|
|
{ |
|
|
|
|
struct opt_table *opt; |
|
|
|
|
struct opt_table *opt; |
|
|
|
|
char *p, *name; |
|
|
|
|
|
|
|
|
|
for(opt = tbl;opt->type != OPT_END;opt++) |
|
|
|
|
{ |
|
|
|
|
/* We don't handle subtables. */ |
|
|
|
|
assert(!(opt->type & OPT_SUBTABLE)); |
|
|
|
|
|
|
|
|
|
if(!opt->names) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
/* Pull apart the option name(s). */ |
|
|
|
|
name = strdup(opt->names); |
|
|
|
|
for(p = strtok(name, "|");p;p = strtok(NULL, "|")) |
|
|
|
|
{ |
|
|
|
|
/* Ignore short options. */ |
|
|
|
|
if(p[1] != '-') |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
//if this is the opt we're looking for, return it...
|
|
|
|
|
if(!strcasecmp(optname, p)) |
|
|
|
|
{ |
|
|
|
|
free(name); |
|
|
|
|
return opt; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
free(name); |
|
|
|
|
} |
|
|
|
|
for(opt = tbl;opt->type != OPT_END;opt++) |
|
|
|
|
{ |
|
|
|
|
/* We don't handle subtables. */ |
|
|
|
|
assert(!(opt->type & OPT_SUBTABLE)); |
|
|
|
|
|
|
|
|
|
if(!opt->names) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
/* Pull apart the option name(s). */ |
|
|
|
|
name = strdup(opt->names); |
|
|
|
|
for(p = strtok(name, "|");p;p = strtok(NULL, "|")) |
|
|
|
|
{ |
|
|
|
|
/* Ignore short options. */ |
|
|
|
|
if(p[1] != '-') |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
//if this is the opt we're looking for, return it...
|
|
|
|
|
if(!strcasecmp(optname, p)) |
|
|
|
|
{ |
|
|
|
|
free(name); |
|
|
|
|
return opt; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
free(name); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
@ -347,47 +347,47 @@ static struct opt_table *opt_find(struct opt_table *tbl, char *optname)
@@ -347,47 +347,47 @@ static struct opt_table *opt_find(struct opt_table *tbl, char *optname)
|
|
|
|
|
//Handle parsing JSON objects
|
|
|
|
|
void parse_config_object(json_t *obj, const char *parentkey, bool fileconf, int parent_iteration) |
|
|
|
|
{ |
|
|
|
|
//char *err = NULL;
|
|
|
|
|
const char *key; |
|
|
|
|
json_t *val; |
|
|
|
|
|
|
|
|
|
json_object_foreach(obj, key, val) |
|
|
|
|
{ |
|
|
|
|
//process include
|
|
|
|
|
if(!strcasecmp(key, "include")) |
|
|
|
|
{ |
|
|
|
|
if(val && json_is_string(val)) |
|
|
|
|
load_config(json_string_value(val), parentkey, NULL); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
parse_config(val, key, parentkey, fileconf, parent_iteration); |
|
|
|
|
/*
|
|
|
|
|
{ |
|
|
|
|
if((err = parse_config(val, key, parentkey, fileconf, parent_iteration))) |
|
|
|
|
return err; |
|
|
|
|
}*/ |
|
|
|
|
} |
|
|
|
|
//char *err = NULL;
|
|
|
|
|
const char *key; |
|
|
|
|
json_t *val; |
|
|
|
|
|
|
|
|
|
json_object_foreach(obj, key, val) |
|
|
|
|
{ |
|
|
|
|
//process include
|
|
|
|
|
if(!strcasecmp(key, "include")) |
|
|
|
|
{ |
|
|
|
|
if(val && json_is_string(val)) |
|
|
|
|
load_config(json_string_value(val), parentkey, NULL); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
parse_config(val, key, parentkey, fileconf, parent_iteration); |
|
|
|
|
/*
|
|
|
|
|
{ |
|
|
|
|
if((err = parse_config(val, key, parentkey, fileconf, parent_iteration))) |
|
|
|
|
return err; |
|
|
|
|
}*/ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Handle parsing JSON arrays
|
|
|
|
|
static char *parse_config_array(json_t *obj, char *parentkey, bool fileconf) |
|
|
|
|
{ |
|
|
|
|
char *err = NULL; |
|
|
|
|
size_t idx; |
|
|
|
|
json_t *val; |
|
|
|
|
|
|
|
|
|
//fix parent key - remove extra "s" to match opt names (e.g. --pool-gpu-memclock not --pools-gpu-memclock)
|
|
|
|
|
if(!strcasecmp(parentkey, "pools") || !strcasecmp(parentkey, "profiles")) |
|
|
|
|
parentkey[(strlen(parentkey) - 1)] = '\0'; |
|
|
|
|
|
|
|
|
|
json_array_foreach(obj, idx, val) |
|
|
|
|
{ |
|
|
|
|
//abort on error
|
|
|
|
|
if((err = parse_config(val, "", parentkey, fileconf, idx))) |
|
|
|
|
return err; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
char *err = NULL; |
|
|
|
|
size_t idx; |
|
|
|
|
json_t *val; |
|
|
|
|
|
|
|
|
|
//fix parent key - remove extra "s" to match opt names (e.g. --pool-gpu-memclock not --pools-gpu-memclock)
|
|
|
|
|
if(!strcasecmp(parentkey, "pools") || !strcasecmp(parentkey, "profiles")) |
|
|
|
|
parentkey[(strlen(parentkey) - 1)] = '\0'; |
|
|
|
|
|
|
|
|
|
json_array_foreach(obj, idx, val) |
|
|
|
|
{ |
|
|
|
|
//abort on error
|
|
|
|
|
if((err = parse_config(val, "", parentkey, fileconf, idx))) |
|
|
|
|
return err; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//Parse JSON values from config file
|
|
|
|
@ -467,56 +467,56 @@ char *parse_config(json_t *val, const char *key, const char *parentkey, bool fil
@@ -467,56 +467,56 @@ char *parse_config(json_t *val, const char *key, const char *parentkey, bool fil
|
|
|
|
|
|
|
|
|
|
char *load_config(const char *arg, const char *parentkey, void __maybe_unused *unused) |
|
|
|
|
{ |
|
|
|
|
json_error_t err; |
|
|
|
|
json_t *config; |
|
|
|
|
json_error_t err; |
|
|
|
|
json_t *config; |
|
|
|
|
|
|
|
|
|
//most likely useless but leaving it here for now...
|
|
|
|
|
if(!cnfbuf) |
|
|
|
|
cnfbuf = strdup(arg); |
|
|
|
|
//most likely useless but leaving it here for now...
|
|
|
|
|
if(!cnfbuf) |
|
|
|
|
cnfbuf = strdup(arg); |
|
|
|
|
|
|
|
|
|
//no need to restrict the number of includes... if it causes problems, restore it later
|
|
|
|
|
/*if(++include_count > JSON_MAX_DEPTH)
|
|
|
|
|
return JSON_MAX_DEPTH_ERR; |
|
|
|
|
*/ |
|
|
|
|
//no need to restrict the number of includes... if it causes problems, restore it later
|
|
|
|
|
/*if(++include_count > JSON_MAX_DEPTH)
|
|
|
|
|
return JSON_MAX_DEPTH_ERR; |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#if JANSSON_MAJOR_VERSION > 1 |
|
|
|
|
config = json_load_file(arg, 0, &err); |
|
|
|
|
config = json_load_file(arg, 0, &err); |
|
|
|
|
#else |
|
|
|
|
config = json_load_file(arg, &err); |
|
|
|
|
config = json_load_file(arg, &err); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
//if json root is not an object, error out
|
|
|
|
|
if(!json_is_object(config)) |
|
|
|
|
{ |
|
|
|
|
set_last_json_error(JSON_LOAD_ERROR, arg, err.text); |
|
|
|
|
return last_json_error; |
|
|
|
|
} |
|
|
|
|
//if json root is not an object, error out
|
|
|
|
|
if(!json_is_object(config)) |
|
|
|
|
{ |
|
|
|
|
set_last_json_error(JSON_LOAD_ERROR, arg, err.text); |
|
|
|
|
return last_json_error; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
config_loaded = true; |
|
|
|
|
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, "", parentkey, true, -1); |
|
|
|
|
/* Parse the config now, so we can override it. That can keep pointers
|
|
|
|
|
* so don't free config object. */ |
|
|
|
|
return parse_config(config, "", parentkey, true, -1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
char *set_default_config(const char *arg) |
|
|
|
|
{ |
|
|
|
|
opt_set_charp(arg, &default_config); |
|
|
|
|
return NULL; |
|
|
|
|
opt_set_charp(arg, &default_config); |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void load_default_config(void) |
|
|
|
|
{ |
|
|
|
|
cnfbuf = (char *)malloc(PATH_MAX); |
|
|
|
|
cnfbuf = (char *)malloc(PATH_MAX); |
|
|
|
|
|
|
|
|
|
default_save_file(cnfbuf); |
|
|
|
|
default_save_file(cnfbuf); |
|
|
|
|
|
|
|
|
|
if (!access(cnfbuf, R_OK)) |
|
|
|
|
if (!access(cnfbuf, R_OK)) |
|
|
|
|
load_config(cnfbuf, "", NULL); |
|
|
|
|
else { |
|
|
|
|
else { |
|
|
|
|
free(cnfbuf); |
|
|
|
|
cnfbuf = NULL; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*******************************************
|
|
|
|
@ -526,36 +526,36 @@ void load_default_config(void)
@@ -526,36 +526,36 @@ void load_default_config(void)
|
|
|
|
|
//assign default settings from default profile if set
|
|
|
|
|
void load_default_profile() |
|
|
|
|
{ |
|
|
|
|
struct profile *profile; |
|
|
|
|
|
|
|
|
|
//if a default profile name is set
|
|
|
|
|
if(!empty_string(default_profile.name)) |
|
|
|
|
{ |
|
|
|
|
//find profile and copy settings
|
|
|
|
|
if((profile = get_profile(default_profile.name))) |
|
|
|
|
{ |
|
|
|
|
default_profile.algorithm = profile->algorithm; |
|
|
|
|
default_profile.intensity = profile->intensity; |
|
|
|
|
default_profile.xintensity = profile->xintensity; |
|
|
|
|
default_profile.rawintensity = profile->rawintensity; |
|
|
|
|
default_profile.thread_concurrency = profile->thread_concurrency; |
|
|
|
|
struct profile *profile; |
|
|
|
|
|
|
|
|
|
//if a default profile name is set
|
|
|
|
|
if(!empty_string(default_profile.name)) |
|
|
|
|
{ |
|
|
|
|
//find profile and copy settings
|
|
|
|
|
if((profile = get_profile(default_profile.name))) |
|
|
|
|
{ |
|
|
|
|
default_profile.algorithm = profile->algorithm; |
|
|
|
|
default_profile.intensity = profile->intensity; |
|
|
|
|
default_profile.xintensity = profile->xintensity; |
|
|
|
|
default_profile.rawintensity = profile->rawintensity; |
|
|
|
|
default_profile.thread_concurrency = profile->thread_concurrency; |
|
|
|
|
#ifdef HAVE_ADL |
|
|
|
|
default_profile.gpu_engine = profile->gpu_engine; |
|
|
|
|
default_profile.gpu_memclock = profile->gpu_memclock; |
|
|
|
|
default_profile.gpu_threads = profile->gpu_threads; |
|
|
|
|
default_profile.gpu_fan = profile->gpu_fan; |
|
|
|
|
default_profile.gpu_engine = profile->gpu_engine; |
|
|
|
|
default_profile.gpu_memclock = profile->gpu_memclock; |
|
|
|
|
default_profile.gpu_threads = profile->gpu_threads; |
|
|
|
|
default_profile.gpu_fan = profile->gpu_fan; |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//apply default settings
|
|
|
|
|
void apply_defaults() |
|
|
|
|
{ |
|
|
|
|
set_algorithm(opt_algorithm, default_profile.algorithm.name); |
|
|
|
|
set_algorithm(opt_algorithm, default_profile.algorithm.name); |
|
|
|
|
|
|
|
|
|
if(!empty_string(default_profile.intensity)) |
|
|
|
|
set_intensity(default_profile.intensity); |
|
|
|
|
if(!empty_string(default_profile.intensity)) |
|
|
|
|
set_intensity(default_profile.intensity); |
|
|
|
|
|
|
|
|
|
if(!empty_string(default_profile.xintensity)) |
|
|
|
|
set_xintensity(default_profile.xintensity); |
|
|
|
@ -584,74 +584,74 @@ void apply_defaults()
@@ -584,74 +584,74 @@ void apply_defaults()
|
|
|
|
|
//apply profile settings to pools
|
|
|
|
|
void apply_pool_profiles() |
|
|
|
|
{ |
|
|
|
|
struct profile *profile; |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
for(i=total_pools;i--;) |
|
|
|
|
{ |
|
|
|
|
//if the pool has a profile set
|
|
|
|
|
if(!empty_string(pools[i]->profile)) |
|
|
|
|
{ |
|
|
|
|
applog(LOG_DEBUG, "Loading settings from profile \"%s\" for pool %i", pools[i]->profile, pools[i]->pool_no); |
|
|
|
|
|
|
|
|
|
//find profile and apply settings to the pool
|
|
|
|
|
if((profile = get_profile(pools[i]->profile))) |
|
|
|
|
{ |
|
|
|
|
pools[i]->algorithm = profile->algorithm; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Algorithm set to \"%s\"", pools[i]->pool_no, pools[i]->algorithm.name); |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->intensity)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->intensity = profile->intensity; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Intensity set to \"%s\"", pools[i]->pool_no, pools[i]->intensity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->xintensity)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->xintensity = profile->xintensity; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i XIntensity set to \"%s\"", pools[i]->pool_no, pools[i]->xintensity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->rawintensity)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->rawintensity = profile->rawintensity; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Raw Intensity set to \"%s\"", pools[i]->pool_no, pools[i]->rawintensity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->thread_concurrency)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->thread_concurrency = profile->thread_concurrency; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Thread Concurrency set to \"%s\"", pools[i]->pool_no, pools[i]->thread_concurrency); |
|
|
|
|
} |
|
|
|
|
struct profile *profile; |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
for(i=total_pools;i--;) |
|
|
|
|
{ |
|
|
|
|
//if the pool has a profile set
|
|
|
|
|
if(!empty_string(pools[i]->profile)) |
|
|
|
|
{ |
|
|
|
|
applog(LOG_DEBUG, "Loading settings from profile \"%s\" for pool %i", pools[i]->profile, pools[i]->pool_no); |
|
|
|
|
|
|
|
|
|
//find profile and apply settings to the pool
|
|
|
|
|
if((profile = get_profile(pools[i]->profile))) |
|
|
|
|
{ |
|
|
|
|
pools[i]->algorithm = profile->algorithm; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Algorithm set to \"%s\"", pools[i]->pool_no, pools[i]->algorithm.name); |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->intensity)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->intensity = profile->intensity; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Intensity set to \"%s\"", pools[i]->pool_no, pools[i]->intensity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->xintensity)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->xintensity = profile->xintensity; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i XIntensity set to \"%s\"", pools[i]->pool_no, pools[i]->xintensity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->rawintensity)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->rawintensity = profile->rawintensity; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Raw Intensity set to \"%s\"", pools[i]->pool_no, pools[i]->rawintensity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->thread_concurrency)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->thread_concurrency = profile->thread_concurrency; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i Thread Concurrency set to \"%s\"", pools[i]->pool_no, pools[i]->thread_concurrency); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef HAVE_ADL |
|
|
|
|
if(!empty_string(profile->gpu_engine)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_engine = profile->gpu_engine; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Clock set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_engine); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->gpu_memclock)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_memclock = profile->gpu_memclock; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Memory clock set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_memclock); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->gpu_threads)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_threads = profile->gpu_threads; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Threads set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_threads); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->gpu_fan)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_fan = profile->gpu_fan; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Fan set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_fan); |
|
|
|
|
} |
|
|
|
|
if(!empty_string(profile->gpu_engine)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_engine = profile->gpu_engine; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Clock set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_engine); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->gpu_memclock)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_memclock = profile->gpu_memclock; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Memory clock set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_memclock); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->gpu_threads)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_threads = profile->gpu_threads; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Threads set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_threads); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(!empty_string(profile->gpu_fan)) |
|
|
|
|
{ |
|
|
|
|
pools[i]->gpu_fan = profile->gpu_fan; |
|
|
|
|
applog(LOG_DEBUG, "Pool %i GPU Fan set to \"%s\"", pools[i]->pool_no, pools[i]->gpu_fan); |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
applog(LOG_DEBUG, "Profile load failed for pool %i: profile %s not found.", pools[i]->pool_no, pools[i]->profile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
applog(LOG_DEBUG, "Profile load failed for pool %i: profile %s not found.", pools[i]->pool_no, pools[i]->profile); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|