Main Page | Modules | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

signal.c

Go to the documentation of this file.
00001 /* $Id: signal.c,v 1.1.1.1 2003/07/04 02:56:27 Mysid Exp $ */
00002 
00003 /*
00004  * Copyright (c) 1996-1997 Chip Norkus
00005  * Copyright (c) 1997 Max Byrd
00006  * Copyright (c) 1997 Greg Poma
00007  * Copyright (c) 2001 James Hess
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. Neither the name of the authors nor the names of its contributors
00019  *    may be used to endorse or promote products derived from this software
00020  *    without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  */
00034 
00041 #include "services.h"
00042 #include "hash.h"
00043 #include "nickserv.h"
00044 #include "memoserv.h"
00045 #include "infoserv.h"
00046 #include "db.h"
00047 #include "log.h"
00048 
00049 /* --------------------------------------------------------------------- */
00050 
00051 #ifdef USE_SQL
00052 
00055 PGconn *dbConn = NULL;
00056 #endif
00057 
00061 char myname[255],
00062      mypass[33];
00063 
00064 /*
00065  * Their hostname, and port
00066  */
00067 char hostname[255];
00068 int port;
00069 
00070 /*
00071  * the servers socket...
00072  */
00073 int server;
00074 
00075 /*
00076  * array of services, and their data...
00077  * see above for Service struct.
00078  */
00079 Service services[NUMSERVS];
00080 database db;
00081 SLogfile *operlog, *nicklog, *chanlog;
00082 FILE *corelog;
00083 u_long totalusers;
00084 u_long mostusers = 0, mostnicks = 0, mostchans = 0, mostmemos = 0;
00085 extern unsigned long top_akill_stamp;
00086 long startup, firstup;
00087 char *OperServ, *NickServ, *ChanServ, *MemoServ, *InfoServ, *GameServ;
00088 char *MassServ;
00089 char coreBuffer[IRCBUF];
00090 u_int AccessLimit = 3, OpLimit = 25, AkickLimit = 30, ChanLimit = 10, NickLimit = 5;
00091 time_t CTime; /* current time, keep this in mind... */
00092 
00093 time_t nextNsync, nextCsync;
00094 time_t nextMsync;
00095 
00103 void flushLogs(char *)
00104 {
00105     nicklog->flush();
00106     chanlog->flush();
00107     operlog->flush();
00108     fflush(corelog);
00109 
00110     timer(60, flushLogs, NULL);
00111 }
00112 
00122 void checkTusers(char *)
00123 {
00124 #ifdef PLUSLCHAN
00125     static u_int last_mostusers = 0;
00126 
00127     if (last_mostusers < mostusers) {
00128         sSend(":%s MODE %s +l %lu", OperServ, PLUSLCHAN, mostusers + 5);
00129         last_mostusers = mostusers;
00130     }
00131 
00132     timer(60, checkTusers, NULL);
00133 #endif
00134 }
00135 
00142 void writeServicesTotals()
00143 {
00144         FILE *fp = fopen("services.totals", "w");
00145 
00146         if (fp) {
00147                 fprintf(fp, "%lu\n%lu\n%lu\n%lu\n%lu\n", mostusers, mostnicks,
00148                                 mostchans, mostmemos, top_akill_stamp);
00149                 fflush(fp);
00150                 fclose(fp);
00151         }
00152 }
00153 
00155 
00165 void sshutdown(int type)
00166 {
00167     if (type != (-1) && type != 2) {
00168         writeServicesTotals();
00169         saveakills();
00170         saveNickData();
00171         syncChanData(1);
00172         saveMemoData();
00173         saveInfoData();
00174     }
00175 
00176     timed_akill_queue(NULL);
00177     unlink("services.pid");
00178 
00179     if (1 /*type == 0 || type == -1 || type > 2 */ ) {
00180 #ifdef USE_SQL
00181         if (dbConn != NULL)
00182             PQfinish(dbConn);
00183         dbConn = NULL;
00184 #endif
00185     }
00186 
00187     if (type == 1) {    
00188         sSend("SQUIT %s :Services %s fall down go BOOM!", hostname,
00189             VERSION_NUM);
00190         close(server);
00191         abort();                /* dump a core file */
00192         }
00193     else if (type == 2) {               /* No connection to server established */
00194         fprintf(stderr,
00195                 "Error connecting to server, check above message\n");
00196         exit(-1);
00197     }
00198     else if (type == 0) {
00199         sSend("SQUIT %s :Services %s shutdown", hostname, VERSION_NUM);
00200         close(server);
00201         exit(66);
00202     }
00203     else {
00204         sSend("SQUIT %s :Services %s shutdown", hostname, VERSION_NUM);
00205         close(server);
00206         exit(1);
00207     }
00208 }
00209 
00216 void handler(int sig)
00217 {
00218     switch (sig) {
00219     case SIGTERM:
00220         sSend("WALLOPS "
00221             ":Received some signal thats telling me to shutdown");
00222         timed_akill_queue(NULL);
00223         sshutdown(0);
00224         break;
00225     case SIGSEGV:
00226         timed_akill_queue(NULL);
00227         logDump(corelog, "Core dumped ---\n\"%s\"", coreBuffer);
00228         sSend("WALLOPS :Segmentation Violation, shutdown NOW");
00229         sSend("GOPER :Buffer is -> %s", coreBuffer);
00230         dlogDump(corelog);
00231         sshutdown(1);
00232         break;
00233 
00234     case SIGPIPE:
00235         timed_akill_queue(NULL);
00236         signal(SIGPIPE, SIG_IGN);  
00237 /*      sshutdown(0);*/
00238         break;
00239 
00240     default:
00241         sSend("GNOTICE :Recieved unidentified signal %i", sig);
00242         return;
00243     }
00244 }
00245 
00246 /* --------------------------------------------------------------------- */
00247 
00248 /* $Id: signal.c,v 1.1.1.1 2003/07/04 02:56:27 Mysid Exp $ */

Generated at Sat Oct 25 20:56:09 2003 for Services using Doxygen.
Services Copyr. 1996-2001 Chip Norkus, Max Byrd, Greg Poma, Michael Graff, James Hess, Dafydd James. All rights reserved See LICENSE for licensing information.