/* Copyright (C) 1995 EGLE Magic, New Zealand, All rights reserved. */ #include #include #include #include #include "dnews.h" #include "str.h" #include "hist.h" #include "nntp.h" #include "chan.h" #include "feed.h" #include "item.h" #include "lib.h" #include "group.h" #include "emsg.h" #ifdef xVMS void lib_atexit( void fn(void)); #define atexit lib_atexit #endif void trace_email(void); void dnews_exit(void); void sig_init(void); void dnews_flush(void); #define LOCKFILE file_work("dnews.lock") int main(int argc, char *argv[]) { int i; int pchan = -1; if (argc==2) { if (strncmp(argv[1],"-p",2)!=0) { printf("Usage: dnews [-pchan_number]\n"); exit(1); } pchan = atoi(argv[1]+2); } strcpy(debug_str,config_getu(C_DEBUG)); if (strlen(debug_str)==0) { strcpy(debug_str,"control:cancel:file:lib:,warn:,fatal:,post:,chan:,feed:,hist:,nntp:,err:,debug:,expire:,info:,item:,group:,suck:,cmd:,ncmd:,init:"); } debug_lvl = 0; for (i=0; i<5; i++) if (strcmp(debug_names[i],config_get(C_LOGLVL))==0) { debug_lvl = i; } emsg("init: nntp server %s %s starting, debug=%d %s \n", DNEWS_NAME,DNEWS_VERSION,debug_lvl,debug_names[debug_lvl]); if (pchan>=0) imsg("init: Using pre-opened channel %d \n",pchan); imsg("init: Loading history database, may take some time \n"); access_read(); feed_load(); hist_init(); group_read(); atexit(dnews_exit); sig_init(); imsg("init: Loading NNTP \n"); nntp_init(pchan); emsg("init: Server initialized and running, %d groups \n",group_n()); nntp_wait(); emsg("init: Server Exiting for some reason \n"); return 0; } void dnews_exit(void) { emsg("fatal: %s exit handler called \n",DNEWS_NAME); dnews_flush(); group_write(); } void dnews_flush(void) { item_flush(); feed_flush(); hist_flush(); emsg_flush(); group_used_flush(); } void sig_hup(int x); void sig_exit(int x); void sig_init(void) { signal(SIGHUP,sig_hup); signal(SIGTERM,sig_exit); #ifdef unix signal(SIGPIPE,SIG_IGN); signal(SIGTRAP,sig_exit); signal(SIGFPE,sig_exit); signal(SIGBUS,sig_exit); signal(SIGSEGV,sig_exit); signal(SIGQUIT,sig_exit); #endif } void sig_hup(int x) { if (x==SIGHUP) emsg("dnews: Signal %d SIGHUP \n",x); else if (x==SIGTERM) { emsg("dnews: Signal %d SIGTERM \n",x); dnews_flush(); exit(1); } else emsg("dnews: Signal ?? %d ?? \n",x); dnews_flush(); config_load(); sig_init(); } void sig_exit(int x) { emsg("dnews: Signal %d causing exit \n",x); dnews_flush(); trace_email(); exit(1); }