From 3d7167ce2c319c879b61f6232373875761e79004 Mon Sep 17 00:00:00 2001 From: Noel Maersk Date: Fri, 18 Apr 2014 17:31:06 +0300 Subject: [PATCH] config: improve pool section writing. Order so JSON's not broken, write `priority` and `algorithm`. Closes #102. --- sgminer.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sgminer.c b/sgminer.c index 8b0032f9..f8dfc373 100644 --- a/sgminer.c +++ b/sgminer.c @@ -4274,13 +4274,6 @@ void write_config(FILE *fcfg) for(i = 0; i < total_pools; i++) { struct pool *pool = pools[i]; - /* Using get_pool_name() here is unsafe if opt_incognito is true. */ - if (strcmp(pool->name, "") != 0) { - fprintf(fcfg, "\n\t\t\"name\" : \"%s\",", json_escape(pool->name)); - } - if (strcmp(pool->description, "") != 0) { - fprintf(fcfg, "\n\t\t\"description\" : \"%s\",", json_escape(pool->description)); - } if (pool->quota != 1) { fprintf(fcfg, "%s\n\t{\n\t\t\"quota\" : \"%s%s%s%d;%s\",", i > 0 ? "," : "", pool->rpc_proxy ? json_escape((char *)proxytype(pool->rpc_proxytype)) : "", @@ -4296,8 +4289,22 @@ void write_config(FILE *fcfg) json_escape(pool->rpc_url)); } fprintf(fcfg, "\n\t\t\"user\" : \"%s\",", json_escape(pool->rpc_user)); - fprintf(fcfg, "\n\t\t\"pass\" : \"%s\"\n\t}", json_escape(pool->rpc_pass)); + fprintf(fcfg, "\n\t\t\"pass\" : \"%s\",", json_escape(pool->rpc_pass)); + /* Using get_pool_name() here is unsafe if opt_incognito is true. */ + if (strcmp(pool->name, "") != 0) { + fprintf(fcfg, "\n\t\t\"name\" : \"%s\",", json_escape(pool->name)); + } + if (strcmp(pool->description, "") != 0) { + fprintf(fcfg, "\n\t\t\"description\" : \"%s\",", json_escape(pool->description)); + } + if (!cmp_algorithm(&pool->algorithm, opt_algorithm)) { + fprintf(fcfg, "\n\t\t\"algorithm\" : \"%s\",", json_escape(pool->algorithm.name)); } + if (pool->prio != i) { + fprintf(fcfg, "\n\t\t\"priority\" : \"%d\"", pool->prio); + } + fprintf(fcfg, "\n\t}"); + } fputs("\n]\n", fcfg); /* Write only if there are usable GPUs */