]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/ngircd.c
Enlarged buffer for version string ;-)
[ngircd-alex.git] / src / ngircd / ngircd.c
index 37cc97fc5d97fe71809f292cd06af1c3393efc59..1166c7b74881ade1349e508fc1cb578b04c534d8 100644 (file)
@@ -1,22 +1,21 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2003 by Alexander Barton (alex@barton.de)
  *
- * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
- * der GNU General Public License (GPL), wie von der Free Software Foundation
- * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
- * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
- * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
- * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
+ * 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.
+ * Please read the file COPYING, README and AUTHORS for more information.
  *
- * $Id: ngircd.c,v 1.60 2002/11/22 17:59:43 alex Exp $
- *
- * ngircd.c: Hier beginnt alles ;-)
+ * Main program -- main()
  */
 
 
 #include "portab.h"
 
+static char UNUSED id[] = "$Id: ngircd.c,v 1.74 2003/03/07 14:50:13 alex Exp $";
+
 #include "imp.h"
 #include <assert.h>
 #include <errno.h>
 #include "parse.h"
 #include "irc.h"
 
+#ifdef RENDEZVOUS
+#include "rendezvous.h"
+#endif
+
 #include "exp.h"
 #include "ngircd.h"
 
@@ -66,17 +69,16 @@ main( int argc, const char *argv[] )
 
        umask( 0077 );
 
-       NGIRCd_Restart = FALSE;
-       NGIRCd_Quit = FALSE;
-       NGIRCd_NoDaemon = FALSE;
-       NGIRCd_Passive = FALSE;
+       NGIRCd_SignalQuit = NGIRCd_SignalRestart = NGIRCd_SignalRehash = FALSE;
+       NGIRCd_NoDaemon = NGIRCd_Passive = FALSE;
 #ifdef DEBUG
        NGIRCd_Debug = FALSE;
 #endif
 #ifdef SNIFFER
        NGIRCd_Sniffer = FALSE;
 #endif
-       strcpy( NGIRCd_ConfFile, CONFIG_FILE );
+       strlcpy( NGIRCd_ConfFile, SYSCONFDIR, sizeof( NGIRCd_ConfFile ));
+       strlcat( NGIRCd_ConfFile, CONFIG_FILE, sizeof( NGIRCd_ConfFile ));
 
        /* Kommandozeile parsen */
        for( i = 1; i < argc; i++ )
@@ -90,11 +92,10 @@ main( int argc, const char *argv[] )
                        {
                                if( i + 1 < argc )
                                {
-                                       /* Ok, danach kommt noch ein Parameter */
-                                       strncpy( NGIRCd_ConfFile, argv[i + 1], FNAME_LEN - 1 );
-                                       NGIRCd_ConfFile[FNAME_LEN - 1] = '\0';
+                                       /* Ok, there's an parameter left */
+                                       strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile ));
 
-                                       /* zum uebernaechsten Parameter */
+                                       /* next parameter */
                                        i++; ok = TRUE;
                                }
                        }
@@ -157,11 +158,10 @@ main( int argc, const char *argv[] )
                                {
                                        if(( ! argv[i][n + 1] ) && ( i + 1 < argc ))
                                        {
-                                               /* Ok, danach kommt ein Leerzeichen */
-                                               strncpy( NGIRCd_ConfFile, argv[i + 1], FNAME_LEN - 1 );
-                                               NGIRCd_ConfFile[FNAME_LEN - 1] = '\0';
+                                               /* Ok, next character is a blank */
+                                               strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile ));
 
-                                               /* zum uebernaechsten Parameter */
+                                               /* go to the following parameter */
                                                i++; n = (LONG)strlen( argv[i] );
                                                ok = TRUE;
                                        }
@@ -221,7 +221,7 @@ main( int argc, const char *argv[] )
                exit( Conf_Test( ));
        }
        
-       while( ! NGIRCd_Quit )
+       while( ! NGIRCd_SignalQuit )
        {
                /* In der Regel wird ein Sub-Prozess ge-fork()'t, der
                 * nicht mehr mit dem Terminal verbunden ist. Mit der
@@ -251,8 +251,9 @@ main( int argc, const char *argv[] )
                /* Globale Variablen initialisieren */
                NGIRCd_Start = time( NULL );
                (VOID)strftime( NGIRCd_StartStr, 64, "%a %b %d %Y at %H:%M:%S (%Z)", localtime( &NGIRCd_Start ));
-               NGIRCd_Restart = FALSE;
-               NGIRCd_Quit = FALSE;
+               NGIRCd_SignalRehash = FALSE;
+               NGIRCd_SignalRestart = FALSE;
+               NGIRCd_SignalQuit = FALSE;
 
                /* Module initialisieren */
                Log_Init( );
@@ -261,6 +262,9 @@ main( int argc, const char *argv[] )
                Lists_Init( );
                Channel_Init( );
                Client_Init( );
+#ifdef RENDEZVOUS
+               Rendezvous_Init( );
+#endif
                Conn_Init( );
 
                /* Wenn als root ausgefuehrt und eine andere UID
@@ -294,11 +298,17 @@ main( int argc, const char *argv[] )
                 * sind in doc/Protocol.txt beschrieben. */
 #ifdef IRCPLUS
                sprintf( NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE, VERSION, IRCPLUSFLAGS );
+#ifdef USE_ZLIB
+               strcat( NGIRCd_ProtoID, "Z" );
+#endif
                if( Conf_OperCanMode ) strcat( NGIRCd_ProtoID, "o" );
 #else
                sprintf( NGIRCd_ProtoID, "%s%s %s|%s", PROTOVER, PROTOIRC, PACKAGE, VERSION );
 #endif
                strcat( NGIRCd_ProtoID, " P" );
+#ifdef USE_ZLIB
+               strcat( NGIRCd_ProtoID, "Z" );
+#endif
                Log( LOG_DEBUG, "Protocol and server ID is \"%s\".", NGIRCd_ProtoID );
 
                /* Vordefinierte Channels anlegen */
@@ -317,6 +327,9 @@ main( int argc, const char *argv[] )
 
                /* Alles abmelden */
                Conn_Exit( );
+#ifdef RENDEZVOUS
+               Rendezvous_Exit( );
+#endif
                Client_Exit( );
                Channel_Exit( );
                Lists_Exit( );
@@ -344,7 +357,7 @@ NGIRCd_Version( VOID )
 GLOBAL CHAR *
 NGIRCd_VersionAddition( VOID )
 {
-       STATIC CHAR txt[64];
+       STATIC CHAR txt[200];
 
        strcpy( txt, "" );
 
@@ -352,6 +365,18 @@ NGIRCd_VersionAddition( VOID )
        if( txt[0] ) strcat( txt, "+" );
        strcat( txt, "SYSLOG" );
 #endif
+#ifdef USE_ZLIB
+       if( txt[0] ) strcat( txt, "+" );
+       strcat( txt, "ZLIB" );
+#endif
+#ifdef USE_TCPWRAP
+       if( txt[0] ) strcat( txt, "+" );
+       strcat( txt, "TCPWRAP" );
+#endif
+#ifdef RENDEZVOUS
+       if( txt[0] ) strcat( txt, "+" );
+       strcat( txt, "RENDEZVOUS" );
+#endif
 #ifdef DEBUG
        if( txt[0] ) strcat( txt, "+" );
        strcat( txt, "DEBUG" );
@@ -369,30 +394,34 @@ NGIRCd_VersionAddition( VOID )
        strcat( txt, "IRCPLUS" );
 #endif
        
-       if( txt[0] ) strcat( txt, "-" );
-       strcat( txt, TARGET_CPU );
-       strcat( txt, "/" );
-       strcat( txt, TARGET_VENDOR );
-       strcat( txt, "/" );
-       strcat( txt, TARGET_OS );
+       if( txt[0] ) strlcat( txt, "-", sizeof( txt ));
+       strlcat( txt, TARGET_CPU, sizeof( txt ));
+       strlcat( txt, "/", sizeof( txt ));
+       strlcat( txt, TARGET_VENDOR, sizeof( txt ));
+       strlcat( txt, "/", sizeof( txt ));
+       strlcat( txt, TARGET_OS, sizeof( txt ));
 
        return txt;
 } /* NGIRCd_VersionAddition */
 
 
 GLOBAL VOID
-NGIRCd_Reload( VOID )
+NGIRCd_Rehash( VOID )
 {
        CHAR old_name[CLIENT_ID_LEN];
-       
+
+       Log( LOG_NOTICE|LOG_snotice, "Re-reading configuration NOW!" );
+       NGIRCd_SignalRehash = FALSE;
+
        /* Alle Listen-Sockets schliessen */
        Conn_ExitListeners( );
 
        /* Alten Server-Namen merken */
+       assert( sizeof( old_name ) == sizeof( Conf_ServerName ));
        strcpy( old_name, Conf_ServerName );
 
        /* Konfiguration neu lesen ... */
-       Conf_Init( );
+       Conf_Rehash( );
 
        /* Alten Server-Namen wiederherstellen: dieser
         * kann nicht zur Laufzeit geaendert werden ... */
@@ -408,8 +437,8 @@ NGIRCd_Reload( VOID )
        /* Listen-Sockets neu anlegen: */
        Conn_InitListeners( );
 
-       Log( LOG_INFO, "Re-reading of configuration done." );
-} /* NGIRCd_Reload */
+       Log( LOG_NOTICE|LOG_snotice, "Re-reading of configuration done." );
+} /* NGIRCd_Rehash */
 
 
 LOCAL VOID
@@ -472,23 +501,21 @@ Signal_Handler( INT Signal )
                case SIGINT:
                case SIGQUIT:
                        /* wir soll(t)en uns wohl beenden ... */
-                       if( Signal == SIGTERM ) Log( LOG_WARNING|LOG_snotice, "Got TERM signal, terminating now ..." );
-                       else if( Signal == SIGINT ) Log( LOG_WARNING|LOG_snotice, "Got INT signal, terminating now ..." );
-                       else if( Signal == SIGQUIT ) Log( LOG_WARNING|LOG_snotice, "Got QUIT signal, terminating now ..." );
-                       NGIRCd_Quit = TRUE;
+                       NGIRCd_SignalQuit = TRUE;
                        break;
                case SIGHUP:
                        /* Konfiguration neu einlesen: */
-                       Log( LOG_WARNING|LOG_snotice, "Got HUP signal, re-reading configuration ..." );
-                       NGIRCd_Reload( );
+                       NGIRCd_SignalRehash = TRUE;
                        break;
                case SIGCHLD:
                        /* Child-Prozess wurde beendet. Zombies vermeiden: */
                        while( waitpid( -1, NULL, WNOHANG ) > 0);
                        break;
+#ifdef DEBUG
                default:
                        /* unbekanntes bzw. unbehandeltes Signal */
-                       Log( LOG_NOTICE, "Got signal %d! Ignored.", Signal );
+                       Log( LOG_DEBUG, "Got signal %d! Ignored.", Signal );
+#endif
        }
 } /* Signal_Handler */
 
@@ -497,7 +524,7 @@ LOCAL VOID
 Show_Version( VOID )
 {
        puts( NGIRCd_Version( ));
-       puts( "Copyright (c)2001,2002 by Alexander Barton (<alex@barton.de>)." );
+       puts( "Copyright (c)2001-2003 by Alexander Barton (<alex@barton.de>)." );
        puts( "Homepage: <http://arthur.ath.cx/~alex/ngircd/>\n" );
        puts( "This is free software; see the source for copying conditions. There is NO" );
        puts( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." );