Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit b9633069 authored by deuce's avatar deuce

Fix race in node.dab access. It's unfortunate that we end up holding the

lock across things with timeouts in them, but since if another thread has
the file locked we shouldn't be fillding with it anyway, this should be
fine.

Fixes weird (and relatively rare) timing issues with node.dab accesses on a
many core host.
parent 181fae90
......@@ -60,9 +60,11 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit)
if(node!=&thisnode)
memset(node,0,sizeof(node_t));
sprintf(str,"%snode.dab",cfg.ctrl_dir);
pthread_mutex_lock(&nodefile_mutex);
if(nodefile==-1) {
if((nodefile=nopen(str,O_RDWR|O_DENYNONE))==-1) {
errormsg(WHERE,ERR_OPEN,str,O_RDWR|O_DENYNONE);
pthread_mutex_unlock(&nodefile_mutex);
return(errno);
}
}
......@@ -94,8 +96,10 @@ int sbbs_t::getnodedat(uint number, node_t *node, bool lockit)
if(nodefile!=-1)
close(nodefile);
nodefile=-1;
pthread_mutex_unlock(&nodefile_mutex);
return(-2);
}
pthread_mutex_unlock(&nodefile_mutex);
if(count>(LOOP_NODEDAB/2)) {
sprintf(str,"NODE.DAB (node %d) COLLISION - Count: %d"
,number+1, count);
......
......@@ -3139,6 +3139,7 @@ sbbs_t::sbbs_t(ushort node_num, union xp_sockaddr *addr, size_t addr_len, const
logcol=1;
logfile_fp=NULL;
nodefile=-1;
pthread_mutex_init(&nodefile_mutex, NULL);
node_ext=-1;
nodefile_fp=NULL;
node_ext_fp=NULL;
......@@ -3265,8 +3266,10 @@ bool sbbs_t::init()
/* Shared NODE files */
SAFEPRINTF2(str,"%s%s",cfg.ctrl_dir,"node.dab");
pthread_mutex_lock(&nodefile_mutex);
if((nodefile=nopen(str,O_DENYNONE|O_RDWR|O_CREAT))==-1) {
errormsg(WHERE, ERR_OPEN, str, cfg.node_num);
pthread_mutex_unlock(&nodefile_mutex);
return(false);
}
memset(&node,0,sizeof(node_t)); /* write NULL to node struct */
......@@ -3289,6 +3292,7 @@ bool sbbs_t::init()
close(nodefile);
nodefile=-1;
}
pthread_mutex_unlock(&nodefile_mutex);
if(i>=LOOP_NODEDAB) {
errormsg(WHERE, ERR_LOCK, str, cfg.node_num);
......@@ -3536,9 +3540,11 @@ sbbs_t::~sbbs_t()
CloseEvent(telnet_ack_event);
/* Close all open files */
pthread_mutex_lock(&nodefile_mutex);
if(nodefile!=-1) {
close(nodefile);
nodefile=-1;
pthread_mutex_unlock(&nodefile_mutex);
}
if(node_ext!=-1) {
close(node_ext);
......
......@@ -81,9 +81,11 @@ int sbbs_t::putnodedat(uint number, node_t* node)
}
sprintf(path,"%snode.dab",cfg.ctrl_dir);
pthread_mutex_lock(&nodefile_mutex);
if(nodefile==-1) {
if((nodefile=nopen(path,O_CREAT|O_RDWR|O_DENYNONE))==-1) {
errormsg(WHERE,ERR_OPEN,path,O_CREAT|O_RDWR|O_DENYNONE);
pthread_mutex_unlock(&nodefile_mutex);
return(errno);
}
}
......@@ -103,6 +105,7 @@ int sbbs_t::putnodedat(uint number, node_t* node)
close(nodefile);
nodefile=-1;
}
pthread_mutex_unlock(&nodefile_mutex);
if(wr!=sizeof(node_t)) {
errno=wrerr;
......
......@@ -398,6 +398,7 @@ public:
*logfile_fp;
int nodefile; /* File handle for node.dab */
pthread_mutex_t nodefile_mutex;
int node_ext; /* File handle for node.exb */
int inputfile; /* File handle to use for input */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment