From 9e17bec09cc486e0c71b1ca55a4ed46298758a82 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 22 Feb 2016 15:48:50 +1100 Subject: [PATCH] Inherit serverurl correctly when none is specified --- src/connector.c | 13 +++++++------ src/stratifier.c | 4 ---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/connector.c b/src/connector.c index 6fbe2387..c980160f 100644 --- a/src/connector.c +++ b/src/connector.c @@ -1460,6 +1460,7 @@ void *connector(void *arg) proc_instance_t *pi = (proc_instance_t *)arg; cdata_t *cdata = ckzalloc(sizeof(cdata_t)); int threads, sockd, ret = 0, i, tries = 0; + char newurl[INET6_ADDRSTRLEN], newport[8]; ckpool_t *ckp = pi->ckp; const int on = 1; @@ -1468,16 +1469,13 @@ void *connector(void *arg) ckp->cdata = cdata; cdata->ckp = ckp; - if (!ckp->serverurls) - cdata->serverfd = ckalloc(sizeof(int *)); - else - cdata->serverfd = ckalloc(sizeof(int *) * ckp->serverurls); - if (!ckp->serverurls) { /* No serverurls have been specified. Bind to all interfaces * on default sockets. */ struct sockaddr_in serv_addr; + cdata->serverfd = ckalloc(sizeof(int *)); + sockd = socket(AF_INET, SOCK_STREAM, 0); if (sockd < 0) { LOGERR("Connector failed to open socket"); @@ -1509,11 +1507,14 @@ void *connector(void *arg) goto out; } cdata->serverfd[0] = sockd; + url_from_socket(sockd, newurl, newport); + ASPRINTF(&ckp->serverurl[0], "%s:%s", newurl, newport); ckp->serverurls = 1; } else { + cdata->serverfd = ckalloc(sizeof(int *) * ckp->serverurls); + for (i = 0; i < ckp->serverurls; i++) { char oldurl[INET6_ADDRSTRLEN], oldport[8]; - char newurl[INET6_ADDRSTRLEN], newport[8]; char *serverurl = ckp->serverurl[i]; if (!url_from_serverurl(serverurl, newurl, newport)) { diff --git a/src/stratifier.c b/src/stratifier.c index 7c7cabe7..675269d3 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -7568,10 +7568,6 @@ void *stratifier(void *arg) if (!ckp->proxy) sdata->blockchange_id = sdata->workbase_id = randomiser; - if (!ckp->serverurls) { - ckp->serverurl[0] = "127.0.0.1"; - ckp->serverurls = 1; - } cklock_init(&sdata->instance_lock); cksem_init(&sdata->update_sem); cksem_post(&sdata->update_sem);