From 3258a44c7f4011c63dba699ecd81580aaa22fe30 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Fri, 15 Oct 2004 23:32:19 +0000
Subject: [PATCH] Created a semaphore file API to ease the support multiple
 recycle/shutdown type semaphore files (and possibly others in the future) for
 the different servers (e.g. telnet, ftp, etc.).

---
 src/sbbs3/objects.mk |  1 +
 src/sbbs3/sbbs.dsp   |  4 ++
 src/sbbs3/sbbs.h     |  8 ++++
 src/sbbs3/semfile.c  | 88 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 101 insertions(+)
 create mode 100644 src/sbbs3/semfile.c

diff --git a/src/sbbs3/objects.mk b/src/sbbs3/objects.mk
index 91580c0186..03ca87c4da 100644
--- a/src/sbbs3/objects.mk
+++ b/src/sbbs3/objects.mk
@@ -84,6 +84,7 @@ OBJS	=	$(MTOBJODIR)$(DIRSEP)ansiterm$(OFILE) \
 			$(MTOBJODIR)$(DIRSEP)scfglib1$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)scfglib2$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)scfgsave$(OFILE)\
+			$(MTOBJODIR)$(DIRSEP)semfile$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)sockopts$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)sortdir$(OFILE)\
 			$(MTOBJODIR)$(DIRSEP)str$(OFILE)\
diff --git a/src/sbbs3/sbbs.dsp b/src/sbbs3/sbbs.dsp
index f2825f307e..b170bc5745 100644
--- a/src/sbbs3/sbbs.dsp
+++ b/src/sbbs3/sbbs.dsp
@@ -402,6 +402,10 @@ SOURCE=.\scfgsave.c
 # End Source File
 # Begin Source File
 
+SOURCE=.\semfile.c
+# End Source File
+# Begin Source File
+
 SOURCE=.\sockopts.c
 # End Source File
 # Begin Source File
diff --git a/src/sbbs3/sbbs.h b/src/sbbs3/sbbs.h
index 6df22d8fb5..e78c691988 100644
--- a/src/sbbs3/sbbs.h
+++ b/src/sbbs3/sbbs.h
@@ -116,6 +116,7 @@
 #include "dirwrap.h"
 #include "filewrap.h"
 #include "sockwrap.h"
+#include "link_list.h"
 
 #include "smblib.h"
 #include "ars_defs.h"
@@ -878,6 +879,13 @@ extern "C" {
 	DLLEXPORT char*		DLLCALL cmdstr(scfg_t* cfg, user_t* user, const char* instr
 									,const char* fpath, const char* fspec, char* cmd);
 
+	/* semfile.c */
+	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, 
+								   const char* action, const char* hostname, const char* service);
+
+
 #ifdef JAVASCRIPT
 
 	typedef struct {
diff --git a/src/sbbs3/semfile.c b/src/sbbs3/semfile.c
new file mode 100644
index 0000000000..0a68a365b5
--- /dev/null
+++ b/src/sbbs3/semfile.c
@@ -0,0 +1,88 @@
+/* semfile.c */
+
+/* $Id$ */
+
+/****************************************************************************
+ * @format.tab-size 4		(Plain Text/Source Code File Header)			*
+ * @format.use-tabs true	(see http://www.synchro.net/ptsc_hdr.html)		*
+ *																			*
+ * Copyright 2004 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				*
+ * as published by the Free Software Foundation; either version 2			*
+ * of the License, or (at your option) any later version.					*
+ * See the GNU General Public License for more details: gpl.txt or			*
+ * http://www.fsf.org/copyleft/gpl.html										*
+ *																			*
+ * Anonymous FTP access to the most recent released source is available at	*
+ * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net	*
+ *																			*
+ * Anonymous CVS access to the development source and modification history	*
+ * is available at cvs.synchro.net:/cvsroot/sbbs, example:					*
+ * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login			*
+ *     (just hit return, no password is necessary)							*
+ * cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src		*
+ *																			*
+ * For Synchronet coding style and modification guidelines, see				*
+ * http://www.synchro.net/source.html										*
+ *																			*
+ * You are encouraged to submit any modifications (preferably in Unix diff	*
+ * format) via e-mail to mods@synchro.net									*
+ *																			*
+ * Note: If this box doesn't appear square, then you need to fix your tabs.	*
+ ****************************************************************************/
+
+#include "sbbs.h"
+#include "link_list.h"
+
+/****************************************************************************/
+/* This function compares a single semaphore file's							*/
+/* date/time stamp (if the file exists) against the passed time stamp (t)	*/
+/* updating the time stamp to the latest dated semaphore file and returning	*/
+/* TRUE if any where newer than the initial value.							*/
+/****************************************************************************/
+BOOL DLLCALL semfile_check(time_t* t, const char* fname)
+{
+	time_t	ft;
+
+	if((ft=fdate(fname))==-1 || ft<=*t)
+		return(FALSE);
+
+	*t=ft;
+	return(TRUE);
+}
+
+/****************************************************************************/
+/* This function goes through a list of semaphore files, comparing the file	*/
+/* date/time stamp (if the file exists) against the passed time stamp (t)	*/
+/* updating the time stamp to the latest dated semaphore file and returning	*/
+/* a pointer to the filename if any where newer than the initial timestamp.	*/
+/****************************************************************************/
+char* DLLCALL semfile_list_check(time_t* t, link_list_t* filelist)
+{
+	char*	signaled=NULL;
+	list_node_t* node;
+
+	for(node=listFirstNode(filelist);node!=NULL;node=listNextNode(node))
+		if(semfile_check(t, node->data))
+			signaled = node->data;
+
+	return(signaled);
+}
+
+void DLLCALL semfile_list_init(link_list_t* filelist, const char* parent, 
+							   const char* action, const char* hostname, const char* service)
+{
+	char path[MAX_PATH+1];
+
+	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);
+}
\ No newline at end of file
-- 
GitLab