Change stratum strings under stratum_lock in reconnect and free old strings.
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
diff --git a/util.c b/util.c
index 4e292d4..16aa8da 100644
--- a/util.c
+++ b/util.c
@@ -1665,8 +1665,18 @@ static bool parse_diff(struct pool *pool, json_t *val)
return true;
}
+static void __suspend_stratum(struct pool *pool)
+{
+ clear_sockbuf(pool);
+ pool->stratum_active = pool->stratum_notify = false;
+ if (pool->sock)
+ CLOSESOCKET(pool->sock);
+ pool->sock = 0;
+}
+
static bool parse_reconnect(struct pool *pool, json_t *val)
{
+ char *sockaddr_url, *stratum_port, *tmp;
char *url, *port, address[256];
memset(address, 0, 255);
@@ -1680,13 +1690,22 @@ static bool parse_reconnect(struct pool *pool, json_t *val)
sprintf(address, "%s:%s", url, port);
- if (!extract_sockaddr(address, &pool->sockaddr_url, &pool->stratum_port))
+ if (!extract_sockaddr(address, &sockaddr_url, &stratum_port))
return false;
- pool->stratum_url = pool->sockaddr_url;
-
applog(LOG_NOTICE, "Reconnect requested from pool %d to %s", pool->pool_no, address);
+ mutex_lock(&pool->stratum_lock);
+ __suspend_stratum(pool);
+ tmp = pool->sockaddr_url;
+ pool->sockaddr_url = sockaddr_url;
+ pool->stratum_url = pool->sockaddr_url;
+ free(tmp);
+ tmp = pool->stratum_port;
+ pool->stratum_port = stratum_port;
+ free(tmp);
+ mutex_unlock(&pool->stratum_lock);
+
if (!restart_stratum(pool))
return false;
@@ -2261,14 +2280,10 @@ out:
void suspend_stratum(struct pool *pool)
{
- clear_sockbuf(pool);
applog(LOG_INFO, "Closing socket for stratum pool %d", pool->pool_no);
mutex_lock(&pool->stratum_lock);
- pool->stratum_active = pool->stratum_notify = false;
- if (pool->sock)
- CLOSESOCKET(pool->sock);
- pool->sock = 0;
+ __suspend_stratum(pool);
mutex_unlock(&pool->stratum_lock);
}