From a48ea77194fc5c74ce8cbe13536975a8ebce1b0b Mon Sep 17 00:00:00 2001 From: me_desk Date: Sat, 3 Aug 2013 12:30:27 +0000 Subject: removed calls to log functions from nodewait_resolve_thread() and nodewait_connect_thread(), log functions are not thread safe, calling them caused segfaults git-svn-id: svn://localhost/project_picapica/trunk@256 fb96df88-216d-11de-830c-f3023f12d8ac --- PICA_log.c | 2 ++ PICA_node.c | 2 ++ PICA_nodewait.c | 11 ++++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/PICA_log.c b/PICA_log.c index 3e55381..51fa42f 100644 --- a/PICA_log.c +++ b/PICA_log.c @@ -4,6 +4,8 @@ #include #include +//logging functions are not thread-safe, call them only from the main thread + static int PICA_loglevel = PICA_LOG_INFO; void PICA_fatal(const char *fmt,...) diff --git a/PICA_node.c b/PICA_node.c index aa0d7c5..d4b98e5 100755 --- a/PICA_node.c +++ b/PICA_node.c @@ -2663,6 +2663,7 @@ while(nw) struct nodelink *nlp; PICA_debug1("connected to %.255s %u, sending request ", nw->addr.addr, nw->addr.port); + PICA_debug2("connection socket is %i", nw->nc.sck); nlp=nodelink_list_addnew(&nw->nc); if (nlp) { @@ -2682,6 +2683,7 @@ while(nw) case PICA_NODEWAIT_RESOLVING_FAILED: { PICA_debug1("resolving %.255s %u failed: %s", nw->addr.addr, nw->addr.port, gai_strerror(nw->ai_errorcode)); + PICA_debug2("socket %i is closed", nw->nc.sck); PICA_nodeaddr_update(nodecfg.nodes_db_file, &nw->addr, 0); kill_ptr = nw; } diff --git a/PICA_nodewait.c b/PICA_nodewait.c index 6a9a70c..db9df81 100644 --- a/PICA_nodewait.c +++ b/PICA_nodewait.c @@ -72,6 +72,9 @@ static DWORD WINAPI nodewait_resolve_thread (void *arg) static void *nodewait_resolve_thread (void *arg) #endif { +/* +* DO NOT CALL LOGGING FUNCTIONS HERE, THEY ARE NOT THREAD-SAFE +*/ struct nodewait *nw = (struct nodewait *)arg; struct addrinfo h; char portbuf[8]; @@ -110,6 +113,9 @@ static DWORD WINAPI nodewait_connect_thread (void *arg) static void *nodewait_connect_thread (void *arg) #endif { +/* +* DO NOT CALL LOGGING FUNCTIONS HERE, THEY ARE NOT THREAD-SAFE +*/ struct nodewait *nw = (struct nodewait *)arg; struct addrinfo *ap; @@ -126,16 +132,11 @@ while(ap) continue; } - PICA_debug2("created socket %i", nw->nc.sck); - if (0 != connect(nw->nc.sck,ap->ai_addr,ap->ai_addrlen)) { ap=ap->ai_next; - - PICA_debug2("connect() failed: %s", strerror(errno)); CLOSE(nw->nc.sck); - PICA_debug2("closed socket %i", nw->nc.sck); continue; } else -- cgit v1.2.1