2001-12-11 22:53:04 +01:00
/*
* ngIRCd - - The Next Generation IRC Daemon
2003-01-01 14:32:23 +01:00
* Copyright ( c ) 2001 - 2003 by Alexander Barton ( alex @ barton . de )
2001-12-11 22:53:04 +01:00
*
2002-12-12 12:30:23 +01:00
* 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 .
2001-12-11 22:53:04 +01:00
*
2002-12-12 12:30:23 +01:00
* Main program - - main ( )
2001-12-11 22:53:04 +01:00
*/
2002-03-12 15:37:51 +01:00
# include "portab.h"
2001-12-11 23:04:21 +01:00
2003-01-01 14:32:23 +01:00
static char UNUSED id [ ] = " $Id: ngircd.c,v 1.71 2003/01/01 13:32:23 alex Exp $ " ;
2002-12-12 12:30:23 +01:00
2002-03-12 15:37:51 +01:00
# include "imp.h"
2001-12-11 22:53:04 +01:00
# include <assert.h>
2002-01-12 01:17:28 +01:00
# include <errno.h>
2001-12-11 22:53:04 +01:00
# include <stdio.h>
2002-04-04 15:03:55 +02:00
# include <stdlib.h>
2001-12-12 18:21:21 +01:00
# include <signal.h>
2002-01-11 15:45:18 +01:00
# include <string.h>
2002-01-12 01:17:28 +01:00
# include <unistd.h>
2002-01-02 03:44:36 +01:00
# include <sys/types.h>
2002-06-02 19:01:21 +02:00
# include <sys/stat.h>
2002-01-02 03:44:36 +01:00
# include <sys/wait.h>
2001-12-30 12:42:00 +01:00
# include <time.h>
2002-11-10 14:38:41 +01:00
# include <pwd.h>
# include <grp.h>
2001-12-12 18:21:21 +01:00
2002-05-27 15:00:50 +02:00
# include "resolve.h"
# include "conn.h"
2001-12-14 09:15:26 +01:00
# include "client.h"
2002-05-27 15:00:50 +02:00
# include "channel.h"
2001-12-12 18:21:21 +01:00
# include "conf.h"
2002-10-07 23:16:12 +02:00
# include "cvs-version.h"
2002-03-12 15:37:51 +01:00
# include "defines.h"
2002-05-27 15:00:50 +02:00
# include "lists.h"
2001-12-11 22:53:04 +01:00
# include "log.h"
2001-12-21 23:24:50 +01:00
# include "parse.h"
2002-05-27 15:00:50 +02:00
# include "irc.h"
2001-12-11 22:53:04 +01:00
2002-03-12 15:37:51 +01:00
# include "exp.h"
2001-12-11 22:53:04 +01:00
# include "ngircd.h"
2002-05-27 15:00:50 +02:00
LOCAL VOID Initialize_Signal_Handler PARAMS ( ( VOID ) ) ;
LOCAL VOID Signal_Handler PARAMS ( ( INT Signal ) ) ;
2001-12-11 22:53:04 +01:00
2002-05-27 15:00:50 +02:00
LOCAL VOID Show_Version PARAMS ( ( VOID ) ) ;
LOCAL VOID Show_Help PARAMS ( ( VOID ) ) ;
2002-01-11 15:45:18 +01:00
2001-12-11 22:53:04 +01:00
2002-05-27 15:00:50 +02:00
GLOBAL int
main ( int argc , const char * argv [ ] )
2001-12-11 22:53:04 +01:00
{
2002-11-10 14:38:41 +01:00
struct passwd * pwd ;
struct group * grp ;
2002-03-27 17:41:25 +01:00
BOOLEAN ok , configtest = FALSE ;
2002-10-09 18:53:02 +02:00
LONG pid , n ;
2002-03-25 20:11:01 +01:00
INT i ;
2002-01-11 15:45:18 +01:00
2002-06-02 19:01:21 +02:00
umask ( 0077 ) ;
2002-12-19 05:29:59 +01:00
NGIRCd_SignalQuit = NGIRCd_SignalRestart = NGIRCd_SignalRehash = FALSE ;
NGIRCd_NoDaemon = NGIRCd_Passive = FALSE ;
2002-01-11 15:45:18 +01:00
# ifdef DEBUG
NGIRCd_Debug = FALSE ;
# endif
2002-01-18 12:12:11 +01:00
# ifdef SNIFFER
NGIRCd_Sniffer = FALSE ;
# endif
2002-12-26 17:48:14 +01:00
strlcpy ( NGIRCd_ConfFile , SYSCONFDIR , sizeof ( NGIRCd_ConfFile ) ) ;
strlcat ( NGIRCd_ConfFile , CONFIG_FILE , sizeof ( NGIRCd_ConfFile ) ) ;
2002-01-11 15:45:18 +01:00
/* Kommandozeile parsen */
for ( i = 1 ; i < argc ; i + + )
{
ok = FALSE ;
if ( ( argv [ i ] [ 0 ] = = ' - ' ) & & ( argv [ i ] [ 1 ] = = ' - ' ) )
{
/* Lange Option */
2002-03-28 15:15:33 +01:00
if ( strcmp ( argv [ i ] , " --config " ) = = 0 )
{
if ( i + 1 < argc )
{
2002-12-26 17:25:43 +01:00
/* Ok, there's an parameter left */
strlcpy ( NGIRCd_ConfFile , argv [ i + 1 ] , sizeof ( NGIRCd_ConfFile ) ) ;
2002-03-28 15:15:33 +01:00
2002-12-26 17:25:43 +01:00
/* next parameter */
2002-03-28 15:15:33 +01:00
i + + ; ok = TRUE ;
}
}
2002-03-27 17:41:25 +01:00
if ( strcmp ( argv [ i ] , " --configtest " ) = = 0 )
{
configtest = TRUE ;
ok = TRUE ;
}
2002-02-19 21:08:24 +01:00
# ifdef DEBUG
if ( strcmp ( argv [ i ] , " --debug " ) = = 0 )
{
NGIRCd_Debug = TRUE ;
ok = TRUE ;
}
# endif
2002-01-11 15:45:18 +01:00
if ( strcmp ( argv [ i ] , " --help " ) = = 0 )
{
2002-03-27 17:41:25 +01:00
Show_Version ( ) ;
puts ( " " ) ; Show_Help ( ) ; puts ( " " ) ;
2002-01-11 15:45:18 +01:00
exit ( 1 ) ;
}
2002-02-19 21:08:24 +01:00
if ( strcmp ( argv [ i ] , " --nodaemon " ) = = 0 )
2002-01-11 15:45:18 +01:00
{
2002-02-19 21:08:24 +01:00
NGIRCd_NoDaemon = TRUE ;
ok = TRUE ;
2002-01-11 15:45:18 +01:00
}
2002-02-19 21:08:24 +01:00
if ( strcmp ( argv [ i ] , " --passive " ) = = 0 )
2002-01-11 15:45:18 +01:00
{
2002-02-19 21:08:24 +01:00
NGIRCd_Passive = TRUE ;
2002-01-11 15:45:18 +01:00
ok = TRUE ;
}
2002-01-18 12:12:11 +01:00
# ifdef SNIFFER
if ( strcmp ( argv [ i ] , " --sniffer " ) = = 0 )
{
NGIRCd_Sniffer = TRUE ;
ok = TRUE ;
}
2002-01-11 15:45:18 +01:00
# endif
2002-02-19 21:08:24 +01:00
if ( strcmp ( argv [ i ] , " --version " ) = = 0 )
2002-01-11 15:45:18 +01:00
{
2002-03-10 18:50:48 +01:00
Show_Version ( ) ;
2002-02-19 21:08:24 +01:00
exit ( 1 ) ;
2002-01-11 15:45:18 +01:00
}
}
else if ( ( argv [ i ] [ 0 ] = = ' - ' ) & & ( argv [ i ] [ 1 ] ! = ' - ' ) )
{
/* Kurze Option */
2002-10-09 18:53:02 +02:00
for ( n = 1 ; n < ( LONG ) strlen ( argv [ i ] ) ; n + + )
2002-01-11 15:45:18 +01:00
{
ok = FALSE ;
# ifdef DEBUG
if ( argv [ i ] [ n ] = = ' d ' )
{
NGIRCd_Debug = TRUE ;
ok = TRUE ;
}
2002-01-18 12:12:11 +01:00
# endif
2002-03-28 15:15:33 +01:00
if ( argv [ i ] [ n ] = = ' f ' )
{
2002-03-31 15:20:42 +02:00
if ( ( ! argv [ i ] [ n + 1 ] ) & & ( i + 1 < argc ) )
2002-03-28 15:15:33 +01:00
{
2002-12-26 17:25:43 +01:00
/* Ok, next character is a blank */
strlcpy ( NGIRCd_ConfFile , argv [ i + 1 ] , sizeof ( NGIRCd_ConfFile ) ) ;
2002-03-28 15:15:33 +01:00
2002-12-26 17:25:43 +01:00
/* go to the following parameter */
2002-10-09 18:53:02 +02:00
i + + ; n = ( LONG ) strlen ( argv [ i ] ) ;
2002-03-28 15:15:33 +01:00
ok = TRUE ;
}
}
2002-02-19 21:08:24 +01:00
if ( argv [ i ] [ n ] = = ' n ' )
{
NGIRCd_NoDaemon = TRUE ;
ok = TRUE ;
}
if ( argv [ i ] [ n ] = = ' p ' )
{
NGIRCd_Passive = TRUE ;
ok = TRUE ;
}
2002-01-18 12:12:11 +01:00
# ifdef SNIFFER
if ( argv [ i ] [ n ] = = ' s ' )
{
NGIRCd_Sniffer = TRUE ;
ok = TRUE ;
}
2002-01-11 15:45:18 +01:00
# endif
if ( ! ok )
{
2002-05-27 15:00:50 +02:00
printf ( " %s: invalid option \" -%c \" ! \n " , PACKAGE , argv [ i ] [ n ] ) ;
printf ( " Try \" %s --help \" for more information. \n " , PACKAGE ) ;
2002-01-11 15:45:18 +01:00
exit ( 1 ) ;
}
}
}
if ( ! ok )
{
2002-05-27 15:00:50 +02:00
printf ( " %s: invalid option \" %s \" ! \n " , PACKAGE , argv [ i ] ) ;
printf ( " Try \" %s --help \" for more information. \n " , PACKAGE ) ;
2002-01-11 15:45:18 +01:00
exit ( 1 ) ;
}
}
2002-02-19 21:08:24 +01:00
/* Debug-Level (fuer IRC-Befehl "VERSION") ermitteln */
strcpy ( NGIRCd_DebugLevel , " " ) ;
# ifdef DEBUG
if ( NGIRCd_Debug ) strcpy ( NGIRCd_DebugLevel , " 1 " ) ;
# endif
# ifdef SNIFFER
2002-05-18 14:20:02 +02:00
if ( NGIRCd_Sniffer )
{
NGIRCd_Debug = TRUE ;
strcpy ( NGIRCd_DebugLevel , " 2 " ) ;
}
2002-02-19 21:08:24 +01:00
# endif
2002-03-27 17:41:25 +01:00
/* Soll nur die Konfigurations ueberprueft und ausgegeben werden? */
if ( configtest )
{
Show_Version ( ) ; puts ( " " ) ;
exit ( Conf_Test ( ) ) ;
}
2002-02-19 21:08:24 +01:00
2002-12-19 05:29:59 +01:00
while ( ! NGIRCd_SignalQuit )
2001-12-11 22:53:04 +01:00
{
2002-01-12 01:17:28 +01:00
/* In der Regel wird ein Sub-Prozess ge-fork()'t, der
* nicht mehr mit dem Terminal verbunden ist . Mit der
* Option " --nodaemon " kann dies ( z . B . zum Debuggen )
* verhindert werden . */
if ( ! NGIRCd_NoDaemon )
{
/* Daemon im Hintergrund erzeugen */
2002-10-09 18:53:02 +02:00
pid = ( LONG ) fork ( ) ;
2002-01-12 01:17:28 +01:00
if ( pid > 0 )
{
/* "alter" Prozess */
exit ( 0 ) ;
}
if ( pid < 0 )
{
/* Fehler */
2002-05-27 15:00:50 +02:00
printf ( " %s: Can't fork: %s! \n Fatal error, exiting now ... \n " , PACKAGE , strerror ( errno ) ) ;
2002-01-12 01:17:28 +01:00
exit ( 1 ) ;
}
2002-03-06 16:36:04 +01:00
/* Child-Prozess initialisieren */
2002-03-25 20:11:01 +01:00
( VOID ) setsid ( ) ;
2002-01-12 01:17:28 +01:00
chdir ( " / " ) ;
}
2001-12-31 03:18:51 +01:00
/* Globale Variablen initialisieren */
NGIRCd_Start = time ( NULL ) ;
2002-03-25 20:11:01 +01:00
( VOID ) strftime ( NGIRCd_StartStr , 64 , " %a %b %d %Y at %H:%M:%S (%Z) " , localtime ( & NGIRCd_Start ) ) ;
2002-12-19 05:29:59 +01:00
NGIRCd_SignalRehash = FALSE ;
NGIRCd_SignalRestart = FALSE ;
NGIRCd_SignalQuit = FALSE ;
2001-12-31 03:18:51 +01:00
/* Module initialisieren */
Log_Init ( ) ;
2002-05-27 15:00:50 +02:00
Resolve_Init ( ) ;
2001-12-31 03:18:51 +01:00
Conf_Init ( ) ;
2002-05-27 15:00:50 +02:00
Lists_Init ( ) ;
2001-12-31 03:18:51 +01:00
Channel_Init ( ) ;
Client_Init ( ) ;
Conn_Init ( ) ;
2002-03-29 23:56:40 +01:00
/* Wenn als root ausgefuehrt und eine andere UID
* konfiguriert ist , jetzt zu dieser wechseln */
2002-03-30 00:34:18 +01:00
if ( getuid ( ) = = 0 )
2002-03-29 23:56:40 +01:00
{
2002-03-30 00:34:18 +01:00
if ( Conf_GID ! = 0 )
2002-03-29 23:56:40 +01:00
{
/* Neue Group-ID setzen */
if ( setgid ( Conf_GID ) ! = 0 ) Log ( LOG_ERR , " Can't change Group-ID to %u: %s " , Conf_GID , strerror ( errno ) ) ;
}
2002-03-30 00:34:18 +01:00
if ( Conf_UID ! = 0 )
2002-03-29 23:56:40 +01:00
{
/* Neue User-ID setzen */
2002-03-30 00:34:18 +01:00
if ( setuid ( Conf_UID ) ! = 0 ) Log ( LOG_ERR , " Can't change User-ID to %u: %s " , Conf_UID , strerror ( errno ) ) ;
2002-03-29 23:56:40 +01:00
}
}
2002-11-10 14:38:41 +01:00
/* User, Gruppe und Prozess-ID des Daemon ausgeben */
pwd = getpwuid ( getuid ( ) ) ; grp = getgrgid ( getgid ( ) ) ;
Log ( LOG_INFO , " Running as user %s(%ld), group %s(%ld), with PID %ld. " , pwd ? pwd - > pw_name : " unknown " , ( LONG ) getuid ( ) , grp ? grp - > gr_name : " unknown " , ( LONG ) getgid ( ) , ( LONG ) getpid ( ) ) ;
2002-03-29 23:56:40 +01:00
2002-11-10 14:38:41 +01:00
/* stderr in "Error-File" umlenken */
2002-03-30 00:34:18 +01:00
Log_InitErrorfile ( ) ;
2001-12-31 03:18:51 +01:00
/* Signal-Handler initialisieren */
Initialize_Signal_Handler ( ) ;
2002-09-02 23:06:11 +02:00
/* Protokoll- und Server-Identifikation erzeugen. Die vom ngIRCd
* beim PASS - Befehl verwendete Syntax sowie die erweiterten Flags
* sind in doc / Protocol . txt beschrieben . */
2002-09-07 19:57:17 +02:00
# ifdef IRCPLUS
2002-09-04 01:53:19 +02:00
sprintf ( NGIRCd_ProtoID , " %s%s %s|%s:%s " , PROTOVER , PROTOIRCPLUS , PACKAGE , VERSION , IRCPLUSFLAGS ) ;
2002-11-27 00:07:24 +01:00
# ifdef USE_ZLIB
strcat ( NGIRCd_ProtoID , " Z " ) ;
# endif
2002-09-02 23:06:11 +02:00
if ( Conf_OperCanMode ) strcat ( NGIRCd_ProtoID , " o " ) ;
2002-09-07 19:57:17 +02:00
# else
sprintf ( NGIRCd_ProtoID , " %s%s %s|%s " , PROTOVER , PROTOIRC , PACKAGE , VERSION ) ;
# endif
2002-09-02 23:06:11 +02:00
strcat ( NGIRCd_ProtoID , " P " ) ;
2002-11-27 00:07:24 +01:00
# ifdef USE_ZLIB
strcat ( NGIRCd_ProtoID , " Z " ) ;
# endif
2002-09-02 21:00:25 +02:00
Log ( LOG_DEBUG , " Protocol and server ID is \" %s \" . " , NGIRCd_ProtoID ) ;
2002-06-02 19:13:33 +02:00
/* Vordefinierte Channels anlegen */
Channel_InitPredefined ( ) ;
2001-12-31 03:18:51 +01:00
/* Listen-Ports initialisieren */
2002-11-22 18:59:43 +01:00
if ( Conn_InitListeners ( ) < 1 )
{
Log ( LOG_ALERT , " Server isn't listening on a single port! " ) ;
Log ( LOG_ALERT , " %s exiting due to fatal errors! " , PACKAGE ) ;
exit ( 1 ) ;
}
2001-12-31 03:18:51 +01:00
/* Hauptschleife */
2002-06-02 19:01:21 +02:00
Conn_Handler ( ) ;
2001-12-31 03:18:51 +01:00
/* Alles abmelden */
Conn_Exit ( ) ;
Client_Exit ( ) ;
Channel_Exit ( ) ;
2002-05-27 15:00:50 +02:00
Lists_Exit ( ) ;
2001-12-31 03:18:51 +01:00
Log_Exit ( ) ;
}
2002-03-06 16:36:04 +01:00
2001-12-11 22:53:04 +01:00
return 0 ;
} /* main */
2002-05-27 15:00:50 +02:00
GLOBAL CHAR *
NGIRCd_Version ( VOID )
2002-01-11 15:45:18 +01:00
{
STATIC CHAR version [ 126 ] ;
2002-10-07 23:16:12 +02:00
# ifdef CVSDATE
sprintf ( version , " %s %s(%s)-%s " , PACKAGE , VERSION , CVSDATE , NGIRCd_VersionAddition ( ) ) ;
# else
2002-09-07 19:57:17 +02:00
sprintf ( version , " %s %s-%s " , PACKAGE , VERSION , NGIRCd_VersionAddition ( ) ) ;
2002-10-07 23:16:12 +02:00
# endif
2002-02-18 00:40:21 +01:00
return version ;
} /* NGIRCd_Version */
2002-05-27 15:00:50 +02:00
GLOBAL CHAR *
NGIRCd_VersionAddition ( VOID )
2002-02-18 00:40:21 +01:00
{
STATIC CHAR txt [ 64 ] ;
2002-01-11 15:45:18 +01:00
strcpy ( txt , " " ) ;
# ifdef USE_SYSLOG
if ( txt [ 0 ] ) strcat ( txt , " + " ) ;
strcat ( txt , " SYSLOG " ) ;
# endif
2002-11-27 00:07:24 +01:00
# ifdef USE_ZLIB
if ( txt [ 0 ] ) strcat ( txt , " + " ) ;
strcat ( txt , " ZLIB " ) ;
# endif
2002-01-11 15:45:18 +01:00
# ifdef DEBUG
if ( txt [ 0 ] ) strcat ( txt , " + " ) ;
strcat ( txt , " DEBUG " ) ;
# endif
# ifdef SNIFFER
if ( txt [ 0 ] ) strcat ( txt , " + " ) ;
strcat ( txt , " SNIFFER " ) ;
# endif
2002-09-07 19:57:17 +02:00
# ifdef STRICT_RFC
if ( txt [ 0 ] ) strcat ( txt , " + " ) ;
strcat ( txt , " RFC " ) ;
# endif
# ifdef IRCPLUS
if ( txt [ 0 ] ) strcat ( txt , " + " ) ;
strcat ( txt , " IRCPLUS " ) ;
# endif
2002-12-26 17:48:14 +01:00
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 ) ) ;
2002-02-18 00:40:21 +01:00
return txt ;
} /* NGIRCd_VersionAddition */
2002-01-11 15:45:18 +01:00
2002-11-22 18:59:43 +01:00
GLOBAL VOID
2002-11-23 00:31:23 +01:00
NGIRCd_Rehash ( VOID )
2002-11-22 18:59:43 +01:00
{
CHAR old_name [ CLIENT_ID_LEN ] ;
2002-12-19 05:29:59 +01:00
Log ( LOG_NOTICE | LOG_snotice , " Re-reading configuration NOW! " ) ;
NGIRCd_SignalRehash = FALSE ;
2002-11-22 18:59:43 +01:00
/* Alle Listen-Sockets schliessen */
Conn_ExitListeners ( ) ;
/* Alten Server-Namen merken */
2002-12-26 18:04:54 +01:00
assert ( sizeof ( old_name ) = = sizeof ( Conf_ServerName ) ) ;
2002-11-22 18:59:43 +01:00
strcpy ( old_name , Conf_ServerName ) ;
/* Konfiguration neu lesen ... */
2002-12-30 01:01:42 +01:00
Conf_Rehash ( ) ;
2002-11-22 18:59:43 +01:00
/* Alten Server-Namen wiederherstellen: dieser
* kann nicht zur Laufzeit geaendert werden . . . */
if ( strcmp ( old_name , Conf_ServerName ) ! = 0 )
{
strcpy ( Conf_ServerName , old_name ) ;
Log ( LOG_ERR , " Can't change \" ServerName \" on runtime! Ignored new name. " ) ;
}
/* neue pre-defined Channel anlegen: */
Channel_InitPredefined ( ) ;
/* Listen-Sockets neu anlegen: */
Conn_InitListeners ( ) ;
2002-12-19 05:29:59 +01:00
Log ( LOG_NOTICE | LOG_snotice , " Re-reading of configuration done. " ) ;
2002-11-23 00:31:23 +01:00
} /* NGIRCd_Rehash */
2002-11-22 18:59:43 +01:00
2002-05-27 15:00:50 +02:00
LOCAL VOID
Initialize_Signal_Handler ( VOID )
2001-12-12 18:21:21 +01:00
{
2001-12-26 15:45:37 +01:00
/* Signal-Handler initialisieren: einige Signale
* werden ignoriert , andere speziell behandelt . */
2001-12-12 18:21:21 +01:00
2002-02-25 12:42:47 +01:00
# ifdef HAVE_SIGACTION
/* sigaction() ist vorhanden */
2001-12-12 18:21:21 +01:00
struct sigaction saction ;
/* Signal-Struktur initialisieren */
memset ( & saction , 0 , sizeof ( saction ) ) ;
2002-01-22 18:15:39 +01:00
saction . sa_handler = Signal_Handler ;
2002-02-19 21:30:47 +01:00
# ifdef SA_RESTART
2002-02-23 20:06:47 +01:00
saction . sa_flags | = SA_RESTART ;
# endif
# ifdef SA_NOCLDWAIT
saction . sa_flags | = SA_NOCLDWAIT ;
2002-02-19 21:30:47 +01:00
# endif
2001-12-12 18:21:21 +01:00
/* Signal-Handler einhaengen */
sigaction ( SIGINT , & saction , NULL ) ;
sigaction ( SIGQUIT , & saction , NULL ) ;
sigaction ( SIGTERM , & saction , NULL ) ;
2002-02-18 00:40:21 +01:00
sigaction ( SIGHUP , & saction , NULL ) ;
2002-01-02 03:44:36 +01:00
sigaction ( SIGCHLD , & saction , NULL ) ;
2001-12-24 02:34:38 +01:00
/* einige Signale ignorieren */
saction . sa_handler = SIG_IGN ;
sigaction ( SIGPIPE , & saction , NULL ) ;
2002-02-25 12:42:47 +01:00
# else
/* kein sigaction() vorhanden */
/* Signal-Handler einhaengen */
signal ( SIGINT , Signal_Handler ) ;
signal ( SIGQUIT , Signal_Handler ) ;
signal ( SIGTERM , Signal_Handler ) ;
signal ( SIGHUP , Signal_Handler ) ;
signal ( SIGCHLD , Signal_Handler ) ;
/* einige Signale ignorieren */
signal ( SIGPIPE , SIG_IGN ) ;
# endif
2001-12-12 18:21:21 +01:00
} /* Initialize_Signal_Handler */
2002-05-27 15:00:50 +02:00
LOCAL VOID
Signal_Handler ( INT Signal )
2001-12-11 22:53:04 +01:00
{
2001-12-12 18:21:21 +01:00
/* Signal-Handler. Dieser wird aufgerufen, wenn eines der Signale eintrifft,
* fuer das wir uns registriert haben ( vgl . Initialize_Signal_Handler ) . Die
* Nummer des eingetroffenen Signals wird der Funktion uebergeben . */
2001-12-11 22:53:04 +01:00
switch ( Signal )
{
case SIGTERM :
2001-12-12 02:40:39 +01:00
case SIGINT :
case SIGQUIT :
2001-12-12 18:21:21 +01:00
/* wir soll(t)en uns wohl beenden ... */
2002-12-19 05:29:59 +01:00
NGIRCd_SignalQuit = TRUE ;
2001-12-11 22:53:04 +01:00
break ;
2002-02-18 00:40:21 +01:00
case SIGHUP :
2002-11-22 18:59:43 +01:00
/* Konfiguration neu einlesen: */
2002-12-19 05:29:59 +01:00
NGIRCd_SignalRehash = TRUE ;
2002-02-18 00:40:21 +01:00
break ;
2002-01-02 03:44:36 +01:00
case SIGCHLD :
/* Child-Prozess wurde beendet. Zombies vermeiden: */
while ( waitpid ( - 1 , NULL , WNOHANG ) > 0 ) ;
break ;
2002-12-19 05:29:59 +01:00
# ifdef DEBUG
2001-12-11 22:53:04 +01:00
default :
2001-12-12 18:21:21 +01:00
/* unbekanntes bzw. unbehandeltes Signal */
2002-12-19 05:29:59 +01:00
Log ( LOG_DEBUG , " Got signal %d! Ignored. " , Signal ) ;
# endif
2001-12-11 22:53:04 +01:00
}
} /* Signal_Handler */
2002-05-27 15:00:50 +02:00
LOCAL VOID
Show_Version ( VOID )
2002-01-11 15:45:18 +01:00
{
puts ( NGIRCd_Version ( ) ) ;
2003-01-01 14:32:23 +01:00
puts ( " Copyright (c)2001-2003 by Alexander Barton (<alex@barton.de>). " ) ;
2002-04-01 19:05:48 +02:00
puts ( " Homepage: <http://arthur.ath.cx/~alex/ngircd/> \n " ) ;
2002-01-11 15:45:18 +01:00
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. " ) ;
} /* Show_Version */
2002-05-27 15:00:50 +02:00
LOCAL VOID
Show_Help ( VOID )
2002-01-11 15:45:18 +01:00
{
# ifdef DEBUG
2002-03-28 15:15:33 +01:00
puts ( " -d, --debug log extra debug messages " ) ;
2002-01-11 15:45:18 +01:00
# endif
2002-03-28 15:15:33 +01:00
puts ( " -f, --config <f> use file <f> as configuration file " ) ;
2002-11-18 19:49:34 +01:00
puts ( " -n, --nodaemon don't fork and don't detach from controlling terminal " ) ;
2002-03-28 15:15:33 +01:00
puts ( " -p, --passive disable automatic connections to other servers " ) ;
2002-01-21 01:02:11 +01:00
# ifdef SNIFFER
2002-03-28 15:15:33 +01:00
puts ( " -s, --sniffer enable network sniffer and display all IRC traffic " ) ;
2002-01-21 01:02:11 +01:00
# endif
2002-03-28 15:15:33 +01:00
puts ( " --configtest read, validate and display configuration; then exit " ) ;
puts ( " --version output version information and exit " ) ;
puts ( " --help display this help and exit " ) ;
2002-01-11 15:45:18 +01:00
} /* Show_Help */
2001-12-11 22:53:04 +01:00
/* -eof- */