Commit 149e73aa authored by rswindell's avatar rswindell
Browse files

fmutex() now supports an option max_age argument (to detect and remove stale

mutex files).
parent 5f0c129a
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -1734,7 +1734,7 @@ void event_thread(void* arg)
getuserdat(&sbbs->cfg,&sbbs->useron);
if(sbbs->useron.number && flength(g.gl_pathv[i])>0) {
sprintf(semfile,"%s.lock",g.gl_pathv[i]);
if(!fmutex(semfile,startup->host_name))
if(!fmutex(semfile,startup->host_name,24*60*60))
continue;
sbbs->online=ON_LOCAL;
eprintf(LOG_INFO,"Un-packing QWK Reply packet from %s",sbbs->useron.alias);
......@@ -1758,7 +1758,7 @@ void event_thread(void* arg)
eprintf(LOG_DEBUG,"QWK pack semaphore signaled: %s", g.gl_pathv[i]);
sbbs->useron.number=atoi(g.gl_pathv[i]+offset);
sprintf(semfile,"%spack%04u.lock",sbbs->cfg.data_dir,sbbs->useron.number);
if(!fmutex(semfile,startup->host_name)) {
if(!fmutex(semfile,startup->host_name,24*60*60)) {
eprintf(LOG_WARNING,"%s exists (already being packed?)", semfile);
continue;
}
......
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -118,15 +118,20 @@ BOOL ftouch(const char* fname)
return(TRUE);
}
BOOL fmutex(const char* fname, const char* text)
BOOL fmutex(const char* fname, const char* text, long max_age)
{
int file;
long t;
#if !defined(NO_SOCKET_SUPPORT)
char hostname[128];
if(text==NULL && gethostname(hostname,sizeof(hostname))==0)
text=hostname;
#endif
if(max_age && (t=fdate(fname)) >= 0 && (time(NULL)-t) > max_age) {
if(remove(fname)!=0)
return(FALSE);
}
if((file=open(fname,O_CREAT|O_WRONLY|O_EXCL,S_IREAD|S_IWRITE))<0)
return(FALSE);
if(text!=NULL)
......
......@@ -4,7 +4,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -41,7 +41,7 @@ extern "C" {
int nopen(const char* str, int access);
FILE * fnopen(int* file, const char* str, int access);
BOOL ftouch(const char* fname);
BOOL fmutex(const char* fname, const char* text);
BOOL fmutex(const char* fname, const char* text, long max_age);
#ifdef __cplusplus
}
......
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