From 8e8ced8d6872dbc5fdf6dc965e600e6d694f3184 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Sun, 17 Oct 2004 07:17:10 +0000 Subject: [PATCH] Created semfile_signal() to be optionally used in place of ftouch() for signalling semaphore files. If not text specified, writes the local hostname to file (for debugging purposes). semfile_list_init() handles a gethostname() failure better. semfile_check() will initialize the passed timestamp to the current time, if 0. --- src/sbbs3/sbbs.h | 1 + src/sbbs3/semfile.c | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h index 280781e0a3..3e0ec88d3b 100644 --- a/src/sbbs3/sbbs.h +++ b/src/sbbs3/sbbs.h @@ -880,6 +880,7 @@ extern "C" { ,const char* fpath, const char* fspec, char* cmd); /* semfile.c */ + DLLEXPORT BOOL DLLCALL semfile_signal(const char* fname, const char* text); DLLEXPORT BOOL DLLCALL semfile_check(time_t* t, const char* fname); DLLEXPORT char* DLLCALL semfile_list_check(time_t* t, link_list_t* filelist); DLLEXPORT void DLLCALL semfile_list_init(link_list_t* filelist, const char* parent, diff --git a/src/sbbs3/semfile.c b/src/sbbs3/semfile.c index e041c4c8ba..6e68004fc4 100644 --- a/src/sbbs3/semfile.c +++ b/src/sbbs3/semfile.c @@ -46,6 +46,9 @@ BOOL DLLCALL semfile_check(time_t* t, const char* fname) { time_t ft; + if(*t==0) /* uninitialized */ + *t=time(NULL); + if((ft=fdate(fname))==-1 || ft<=*t) return(FALSE); @@ -77,17 +80,17 @@ void DLLCALL semfile_list_init(link_list_t* filelist, const char* parent, char path[MAX_PATH+1]; char hostname[128]; - gethostname(hostname,sizeof(hostname)); - listInit(filelist,0); SAFEPRINTF2(path,"%s%s",parent,action); listPushNodeString(filelist,path); - SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname); - listPushNodeString(filelist,path); SAFEPRINTF3(path,"%s%s.%s",parent,action,service); listPushNodeString(filelist,path); - SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service); - listPushNodeString(filelist,path); + if(gethostname(hostname,sizeof(hostname))==0) { + SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname); + listPushNodeString(filelist,path); + SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service); + listPushNodeString(filelist,path); + } } void DLLCALL semfile_list_add(link_list_t* filelist, const char* path) @@ -99,3 +102,18 @@ void DLLCALL semfile_list_free(link_list_t* filelist) { listFree(filelist); } + +BOOL DLLCALL semfile_signal(const char* fname, const char* text) +{ + int file; + char hostname[128]; + + if((file=nopen(fname,O_CREAT|O_WRONLY))<0) + return(FALSE); + if(text==NULL && gethostname(hostname,sizeof(hostname))==0) + text=hostname; + if(text!=NULL) + write(file,text,strlen(text)); + close(file); + return(TRUE); +} -- GitLab