#pragma module NNTP_MAIN "DNNTP/OVMS 2-B" /* **++ ** FACILITY: NNTP Server for OpenVMS ** ** MODULE DESCRIPTION: ** ** A main modlue of the server, performs an initialization task. ** ** AUTHORS: ** ** Copyright (c) 1996-98 Ruslan R. Laishev ** ** CREATION DATE: ??-???-1996 ** ** ** MODIFICATION HISTORY: ** ** 6-FEB-2002 RRL Changed scheduling of start an purging task, ** increased a thread stack size 32000->64000 bytes. ** 10-FEB-2002 RRL Redesign a waiting of purging event. ** ** {@tbs@}... **-- */ /* ** ** INCLUDE FILES ** */ #include #include "nntp.h" char *ID$IDcpy = "Copyright (c) 1996-2002,Ruslan R. Laishev (@RRL)."; char *ID$IDsrv = "DNNTP/OVMS 2-B"; char *ID$IDver = "DECThreads NNTP Server for OpenVMS Ver. 2-B, OpenVMS/"\ VMS_VERSION; pthread_attr_t tattr; int purging_enable = 0; /* **++ ** FUNCTIONAL DESCRIPTION: ** ** Timer AST procedure called at timer expiration time. Set a special flag (purging can be started) ** and wake uping a main thread. ** ** FORMAL PARAMETERS: ** ** None. ** ** RETURN VALUE: ** ** VMS condition code ** **-- */ int purging_AST ( void *arg ) { /* ** Set purging enable flag to nonzero value and wake the process */ return purging_enable = sys$wake(0,0); } /* **++ ** FUNCTIONAL DESCRIPTION: ** ** The server initialization. ** ** FORMAL PARAMETERS: ** ** None. ** ** RETURN VALUE: ** ** VMS condition code ** **-- */ int main (void) { int status,tomorrow_bin[2]; pthread_t th0,th1,th2; $DESCRIPTOR(tomorrow_dsc,"TOMORROW"); NNTP_LOG(LOGI,ID$IDcpy); NNTP_LOG(LOGI,ID$IDver); /* ** */ NNTP_LOG(LOGI,"Get configuration information."); status = nntp_conf_get(); if (!$VMS_STATUS_SUCCESS(status)) sys$exit(status); nntp_conf_out(); /* ** */ NNTP_LOG(LOGI,"Opening News Messages DataBase"); if ( !(1 & (status = MsgDBopen())) ) sys$exit(status); NNTP_LOG(LOGI,"Opening NewsGroups DataBase"); if ( !(1 & (status = GrpDBopen())) ) sys$exit(status); NNTP_LOG(LOGI,"Opening Feed and Suck DataBase"); if ( !(1 & (status = FeedSuckDBopen())) ) sys$exit(status); /* ** Some specific DECThreads initialization */ decc$set_reentrancy(C$C_MULTITHREAD); #ifdef __VAX pthread_attr_create(&tattr); pthread_attr_setstacksize(&tattr,64000); #else pthread_attr_init(&tattr); pthread_attr_setdetachstate(&tattr,PTHREAD_CREATE_DETACHED); pthread_attr_setstacksize(&tattr,64000); #endif NNTP_InitBosses (); /* ** */ if ( 0 > $PTHREAD_CREATE(&th0,tattr,NNTP_ClientBoss,0) ) { NNTP_LOG(LOGF,"Create Client Boss thread-%s.", strerror(errno)); } NNTP_LOG(LOGI,"Create Client Boss thread-Ok (Tid:0%xh).",th0); /* ** Start an incomming connections listener */ if (0 > $PTHREAD_CREATE(&th1,tattr,NNTP_SuckBoss,0) ) { NNTP_LOG(LOGF,"Create Suck Boss thread-%s.", strerror(errno)); } NNTP_LOG(LOGI,"Create Suck Boss thread-Ok (Tid:0%xh).",th1); /* ** Start a feed thread */ if ( 0 > $PTHREAD_CREATE(&th2,tattr,NNTP_FeedBoss,0) ) { NNTP_LOG(LOGF,"Create Feed Boss thread-%s.", strerror(errno)); } NNTP_LOG(LOGI,"Create Feed Boss thread-Ok (Tid:0%xh).",th2); /* ** Main loop */ while ( 1 ) { NNTP_LOG(LOGI,"Schedule of database purging thread at midnight."); /* ** Convert a time to VMS binary format */ if ( !(1 & (status = lib$convert_date_string(&tomorrow_dsc,tomorrow_bin))) ) sys$exit(status); /* ** Clear purging enable flag */ purging_enable = 0; /* ** Enqueue a timer request */ if ( !(1 & (status = sys$setimr(0,tomorrow_bin,purging_AST,&status,0))) ) lib$signal(status); /* ** Start sleeping until tomorrow, we use loop and purging_enable checking ** to prevent unexpected hibernation under DECThreads environment. */ while ( !purging_enable ) { if ( !(1 & (status = sys$hiber())) ) lib$signal(status); } /* ** Start Database purging task */ NNTP_LOG(LOGI,"Beging of database purging task."); NNTP_ExpireBoss(); NNTP_LOG(LOGI,"End of database purging task."); } /* ** Close databases and exit - must be never happened */ DBclose(); NNTP_LOG(LOGI,"%s-End.",ID$IDver); }