From 149e73aa647e84913c6fcc195b0a1fde86a7ed01 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Fri, 13 Jan 2006 08:48:25 +0000 Subject: [PATCH] fmutex() now supports an option max_age argument (to detect and remove stale mutex files). --- src/sbbs3/main.cpp | 6 +++--- src/sbbs3/nopen.c | 9 +++++++-- src/sbbs3/nopen.h | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/sbbs3/main.cpp b/src/sbbs3/main.cpp index 8eb53089d1..30a5badba5 100644 --- a/src/sbbs3/main.cpp +++ b/src/sbbs3/main.cpp @@ -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; } diff --git a/src/sbbs3/nopen.c b/src/sbbs3/nopen.c index 3a0d8e303c..c40e84a2b7 100644 --- a/src/sbbs3/nopen.c +++ b/src/sbbs3/nopen.c @@ -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) diff --git a/src/sbbs3/nopen.h b/src/sbbs3/nopen.h index b83241227d..4c9645a8ac 100644 --- a/src/sbbs3/nopen.h +++ b/src/sbbs3/nopen.h @@ -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 } -- GitLab