Commit 21136117 authored by rswindell's avatar rswindell
Browse files

semfile API now using string lists (str_list_t) instead of linked-lists.

String lists are simplier, faster, and require less memory.
parent 96eef094
......@@ -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 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2005 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 *
......@@ -96,8 +96,8 @@ static DWORD served=0;
static BOOL terminate_server=FALSE;
static char revision[16];
static char *text[TOTAL_TEXT];
static link_list_t recycle_semfiles;
static link_list_t shutdown_semfiles;
static str_list_t recycle_semfiles;
static str_list_t shutdown_semfiles;
#ifdef _DEBUG
static BYTE socket_debug[0x10000]={0};
......@@ -4686,14 +4686,14 @@ void DLLCALL ftp_server(void* arg)
status(STATUS_WFC);
/* Setup recycle/shutdown semaphore file lists */
semfile_list_init(&shutdown_semfiles,scfg.ctrl_dir,"shutdown","ftp");
semfile_list_init(&recycle_semfiles,scfg.ctrl_dir,"recycle","ftp");
shutdown_semfiles=semfile_list_init(scfg.ctrl_dir,"shutdown","ftp");
recycle_semfiles=semfile_list_init(scfg.ctrl_dir,"recycle","ftp");
SAFEPRINTF(path,"%sftpsrvr.rec",scfg.ctrl_dir); /* legacy */
semfile_list_add(&recycle_semfiles,path);
if(!initialized) {
initialized=time(NULL);
semfile_list_check(&initialized,&recycle_semfiles);
semfile_list_check(&initialized,&shutdown_semfiles);
semfile_list_check(&initialized,recycle_semfiles);
semfile_list_check(&initialized,shutdown_semfiles);
}
......@@ -4705,7 +4705,7 @@ void DLLCALL ftp_server(void* arg)
if(active_clients==0) {
if(!(startup->options&FTP_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,&recycle_semfiles))!=NULL) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
lprintf(LOG_INFO,"0000 Recycle semaphore file (%s) detected",p);
break;
}
......@@ -4719,7 +4719,7 @@ void DLLCALL ftp_server(void* arg)
break;
}
}
if(((p=semfile_list_check(&initialized,&shutdown_semfiles))!=NULL
if(((p=semfile_list_check(&initialized,shutdown_semfiles))!=NULL
&& lprintf(LOG_INFO,"0000 Shutdown semaphore file (%s) detected",p))
|| (startup->shutdown_now==TRUE
&& lprintf(LOG_INFO,"0000 Shutdown semaphore signaled"))) {
......
......@@ -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 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2005 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 *
......@@ -104,8 +104,8 @@ static BOOL terminate_sendmail=FALSE;
static sem_t sendmail_wakeup_sem;
static char revision[16];
static time_t uptime;
static link_list_t recycle_semfiles;
static link_list_t shutdown_semfiles;
static str_list_t recycle_semfiles;
static str_list_t shutdown_semfiles;
static int mailproc_count;
struct mailproc {
......@@ -4215,14 +4215,14 @@ void DLLCALL mail_server(void* arg)
status(STATUS_WFC);
/* Setup recycle/shutdown semaphore file lists */
semfile_list_init(&shutdown_semfiles,scfg.ctrl_dir,"shutdown","mail");
semfile_list_init(&recycle_semfiles,scfg.ctrl_dir,"recycle","mail");
shutdown_semfiles=semfile_list_init(scfg.ctrl_dir,"shutdown","mail");
recycle_semfiles=semfile_list_init(scfg.ctrl_dir,"recycle","mail");
SAFEPRINTF(path,"%smailsrvr.rec",scfg.ctrl_dir); /* legacy */
semfile_list_add(&recycle_semfiles,path);
if(!initialized) {
initialized=time(NULL);
semfile_list_check(&initialized,&recycle_semfiles);
semfile_list_check(&initialized,&shutdown_semfiles);
semfile_list_check(&initialized,recycle_semfiles);
semfile_list_check(&initialized,shutdown_semfiles);
}
/* signal caller that we've started up successfully */
......@@ -4233,7 +4233,7 @@ void DLLCALL mail_server(void* arg)
if(active_clients==0) {
if(!(startup->options&MAIL_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,&recycle_semfiles))!=NULL) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
lprintf(LOG_INFO,"%04d Recycle semaphore file (%s) detected"
,server_socket,p);
break;
......@@ -4248,7 +4248,7 @@ void DLLCALL mail_server(void* arg)
break;
}
}
if(((p=semfile_list_check(&initialized,&shutdown_semfiles))!=NULL
if(((p=semfile_list_check(&initialized,shutdown_semfiles))!=NULL
&& lprintf(LOG_INFO,"%04d Shutdown semaphore file (%s) detected"
,server_socket,p))
|| (startup->shutdown_now==TRUE
......
......@@ -92,8 +92,8 @@ static char * text[TOTAL_TEXT];
static WORD first_node;
static WORD last_node;
static bool terminate_server=false;
static link_list_t recycle_semfiles;
static link_list_t shutdown_semfiles;
static str_list_t recycle_semfiles;
static str_list_t shutdown_semfiles;
extern "C" {
......@@ -4075,13 +4075,13 @@ void DLLCALL bbs_thread(void* arg)
#endif // _WIN32 && _DEBUG && _MSC_VER
/* Setup recycle/shutdown semaphore file lists */
semfile_list_init(&shutdown_semfiles,scfg.ctrl_dir,"shutdown","telnet");
semfile_list_init(&recycle_semfiles,scfg.ctrl_dir,"recycle","telnet");
shutdown_semfiles=semfile_list_init(scfg.ctrl_dir,"shutdown","telnet");
recycle_semfiles=semfile_list_init(scfg.ctrl_dir,"recycle","telnet");
SAFEPRINTF(str,"%stelnet.rec",scfg.ctrl_dir); /* legacy */
semfile_list_add(&recycle_semfiles,str);
if(!initialized) {
semfile_list_check(&initialized,&recycle_semfiles);
semfile_list_check(&initialized,&shutdown_semfiles);
semfile_list_check(&initialized,recycle_semfiles);
semfile_list_check(&initialized,shutdown_semfiles);
}
#ifdef __unix__ // unix-domain spy sockets
......@@ -4151,7 +4151,7 @@ void DLLCALL bbs_thread(void* arg)
if(rerun)
break;
if(!(startup->options&BBS_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,&recycle_semfiles))!=NULL) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
lprintf(LOG_INFO,"%04d Recycle semaphore file (%s) detected"
,telnet_socket,p);
break;
......@@ -4166,7 +4166,7 @@ void DLLCALL bbs_thread(void* arg)
break;
}
}
if(((p=semfile_list_check(&initialized,&shutdown_semfiles))!=NULL
if(((p=semfile_list_check(&initialized,shutdown_semfiles))!=NULL
&& lprintf(LOG_INFO,"%04d Shutdown semaphore file (%s) detected"
,telnet_socket,p))
|| (startup->shutdown_now==TRUE
......
......@@ -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 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2005 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 *
......@@ -892,11 +892,12 @@ extern "C" {
/* 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,
const char* action, const char* service);
DLLEXPORT void DLLCALL semfile_list_add(link_list_t* filelist, const char* fname);
DLLEXPORT void DLLCALL semfile_list_free(link_list_t* filelist);
DLLEXPORT char* DLLCALL semfile_list_check(time_t* t, str_list_t filelist);
DLLEXPORT str_list_t
DLLCALL semfile_list_init(const char* parent, const char* action
,const char* service);
DLLEXPORT void DLLCALL semfile_list_add(str_list_t* filelist, const char* fname);
DLLEXPORT void DLLCALL semfile_list_free(str_list_t* filelist);
#ifdef JAVASCRIPT
......
......@@ -6,7 +6,7 @@
* @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 *
* Copyright 2005 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 *
......@@ -61,53 +61,57 @@ BOOL DLLCALL semfile_check(time_t* t, const char* fname)
/* 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* DLLCALL semfile_list_check(time_t* t, str_list_t filelist)
{
char* signaled=NULL;
list_node_t* node;
size_t i;
for(node=listFirstNode(filelist);node!=NULL;node=listNextNode(node))
if(semfile_check(t, node->data))
signaled = node->data;
for(i=0;filelist[i]!=NULL;i++)
if(semfile_check(t, filelist[i]))
signaled = filelist[i];
return(signaled);
}
void DLLCALL semfile_list_init(link_list_t* filelist, const char* parent,
str_list_t DLLCALL semfile_list_init(const char* parent,
const char* action, const char* service)
{
char path[MAX_PATH+1];
char hostname[128];
char* p;
str_list_t list;
listInit(filelist,0);
if((list=strListInit())==NULL)
return(NULL);
SAFEPRINTF2(path,"%s%s",parent,action);
listPushNodeString(filelist,path);
strListPush(&list,path);
SAFEPRINTF3(path,"%s%s.%s",parent,action,service);
listPushNodeString(filelist,path);
strListPush(&list,path);
if(gethostname(hostname,sizeof(hostname))==0) {
SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname);
listPushNodeString(filelist,path);
strListPush(&list,path);
SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service);
listPushNodeString(filelist,path);
strListPush(&list,path);
if((p=strchr(hostname,'.'))!=NULL) {
*p=0;
SAFEPRINTF3(path,"%s%s.%s",parent,action,hostname);
listPushNodeString(filelist,path);
strListPush(&list,path);
SAFEPRINTF4(path,"%s%s.%s.%s",parent,action,hostname,service);
listPushNodeString(filelist,path);
strListPush(&list,path);
}
}
return(list);
}
void DLLCALL semfile_list_add(link_list_t* filelist, const char* path)
void DLLCALL semfile_list_add(str_list_t* filelist, const char* path)
{
listPushNodeString(filelist, path);
strListPush(filelist, path);
}
void DLLCALL semfile_list_free(link_list_t* filelist)
void DLLCALL semfile_list_free(str_list_t* filelist)
{
listFree(filelist);
strListFree(filelist);
}
BOOL DLLCALL semfile_signal(const char* fname, const char* text)
......@@ -121,6 +125,7 @@ BOOL DLLCALL semfile_signal(const char* fname, const char* text)
text=hostname;
if(text!=NULL)
write(file,text,strlen(text));
/* use utime() for force the time-stamp to that of the local system? */
close(file);
return(TRUE);
}
......@@ -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 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2005 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 *
......@@ -84,8 +84,8 @@ static BOOL terminated=FALSE;
static time_t uptime=0;
static DWORD served=0;
static char revision[16];
static link_list_t recycle_semfiles;
static link_list_t shutdown_semfiles;
static str_list_t recycle_semfiles;
static str_list_t shutdown_semfiles;
typedef struct {
/* These are sysop-configurable */
......@@ -1775,14 +1775,14 @@ void DLLCALL services_thread(void* arg)
status("Listening");
/* Setup recycle/shutdown semaphore file lists */
semfile_list_init(&shutdown_semfiles,scfg.ctrl_dir,"shutdown","services");
semfile_list_init(&recycle_semfiles,scfg.ctrl_dir,"recycle","services");
shutdown_semfiles=semfile_list_init(scfg.ctrl_dir,"shutdown","services");
recycle_semfiles=semfile_list_init(scfg.ctrl_dir,"recycle","services");
SAFEPRINTF(path,"%sservices.rec",scfg.ctrl_dir); /* legacy */
semfile_list_add(&recycle_semfiles,path);
if(!initialized) {
initialized=time(NULL);
semfile_list_check(&initialized,&recycle_semfiles);
semfile_list_check(&initialized,&shutdown_semfiles);
semfile_list_check(&initialized,recycle_semfiles);
semfile_list_check(&initialized,shutdown_semfiles);
}
terminated=FALSE;
......@@ -1796,7 +1796,7 @@ void DLLCALL services_thread(void* arg)
if(active_clients()==0) {
if(!(startup->options&BBS_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,&recycle_semfiles))!=NULL) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
lprintf(LOG_INFO,"0000 Recycle semaphore file (%s) detected",p);
break;
}
......@@ -1810,7 +1810,7 @@ void DLLCALL services_thread(void* arg)
break;
}
}
if(((p=semfile_list_check(&initialized,&shutdown_semfiles))!=NULL
if(((p=semfile_list_check(&initialized,shutdown_semfiles))!=NULL
&& lprintf(LOG_INFO,"0000 Shutdown semaphore file (%s) detected",p))
|| (startup->shutdown_now==TRUE
&& lprintf(LOG_INFO,"0000 Shutdown semaphore signaled"))) {
......
......@@ -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 2004 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2005 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 *
......@@ -149,8 +149,8 @@ static time_t uptime=0;
static DWORD served=0;
static web_startup_t* startup=NULL;
static js_server_props_t js_server_props;
static link_list_t recycle_semfiles;
static link_list_t shutdown_semfiles;
static str_list_t recycle_semfiles;
static str_list_t shutdown_semfiles;
static named_string_t** mime_types;
......@@ -3612,14 +3612,14 @@ void DLLCALL web_server(void* arg)
}
/* Setup recycle/shutdown semaphore file lists */
semfile_list_init(&shutdown_semfiles,scfg.ctrl_dir,"shutdown","web");
semfile_list_init(&recycle_semfiles,scfg.ctrl_dir,"recycle","web");
shutdown_semfiles=semfile_list_init(scfg.ctrl_dir,"shutdown","web");
recycle_semfiles=semfile_list_init(scfg.ctrl_dir,"recycle","web");
SAFEPRINTF(path,"%swebsrvr.rec",scfg.ctrl_dir); /* legacy */
semfile_list_add(&recycle_semfiles,path);
if(!initialized) {
initialized=time(NULL);
semfile_list_check(&initialized,&recycle_semfiles);
semfile_list_check(&initialized,&shutdown_semfiles);
semfile_list_check(&initialized,recycle_semfiles);
semfile_list_check(&initialized,shutdown_semfiles);
}
/* signal caller that we've started up successfully */
......@@ -3631,7 +3631,7 @@ void DLLCALL web_server(void* arg)
/* check for re-cycle/shutdown semaphores */
if(active_clients==0) {
if(!(startup->options&BBS_OPT_NO_RECYCLE)) {
if((p=semfile_list_check(&initialized,&recycle_semfiles))!=NULL) {
if((p=semfile_list_check(&initialized,recycle_semfiles))!=NULL) {
lprintf(LOG_INFO,"%04d Recycle semaphore file (%s) detected"
,server_socket,p);
break;
......@@ -3646,7 +3646,7 @@ void DLLCALL web_server(void* arg)
break;
}
}
if(((p=semfile_list_check(&initialized,&shutdown_semfiles))!=NULL
if(((p=semfile_list_check(&initialized,shutdown_semfiles))!=NULL
&& lprintf(LOG_INFO,"%04d Shutdown semaphore file (%s) detected"
,server_socket,p))
|| (startup->shutdown_now==TRUE
......
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