2 f4ade537 2001-12-11 alex * ngIRCd -- The Next Generation IRC Daemon
3 5e3e3ad4 2003-01-01 alex * Copyright (c)2001-2003 by Alexander Barton (alex@barton.de)
5 fa7b3f0e 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 fa7b3f0e 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 fa7b3f0e 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 fa7b3f0e 2002-12-12 alex * (at your option) any later version.
9 fa7b3f0e 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 fa7b3f0e 2002-12-12 alex * Main program -- main()
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 5e3e3ad4 2003-01-01 alex static char UNUSED id[] = "$Id: ngircd.c,v 1.71 2003/01/01 13:32:23 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 f4ade537 2001-12-11 alex #include <assert.h>
21 22cf0c5d 2002-01-12 alex #include <errno.h>
22 f4ade537 2001-12-11 alex #include <stdio.h>
23 75c0bd25 2002-04-04 alex #include <stdlib.h>
24 418add93 2001-12-12 alex #include <signal.h>
25 52424b49 2002-01-11 alex #include <string.h>
26 22cf0c5d 2002-01-12 alex #include <unistd.h>
27 03d971d9 2002-01-02 alex #include <sys/types.h>
28 9ec32d15 2002-06-02 alex #include <sys/stat.h>
29 03d971d9 2002-01-02 alex #include <sys/wait.h>
30 ac9da09e 2001-12-30 alex #include <time.h>
31 70c9c051 2002-11-10 alex #include <pwd.h>
32 70c9c051 2002-11-10 alex #include <grp.h>
34 ba258e65 2002-05-27 alex #include "resolve.h"
35 ba258e65 2002-05-27 alex #include "conn.h"
36 58c6c8f3 2001-12-14 alex #include "client.h"
37 ba258e65 2002-05-27 alex #include "channel.h"
38 418add93 2001-12-12 alex #include "conf.h"
39 25f32ce8 2002-10-07 alex #include "cvs-version.h"
40 ca33cbda 2002-03-12 alex #include "defines.h"
41 ba258e65 2002-05-27 alex #include "lists.h"
42 f4ade537 2001-12-11 alex #include "log.h"
43 1751c869 2001-12-21 alex #include "parse.h"
44 ba258e65 2002-05-27 alex #include "irc.h"
46 ca33cbda 2002-03-12 alex #include "exp.h"
47 f4ade537 2001-12-11 alex #include "ngircd.h"
50 ba258e65 2002-05-27 alex LOCAL VOID Initialize_Signal_Handler PARAMS(( VOID ));
51 ba258e65 2002-05-27 alex LOCAL VOID Signal_Handler PARAMS(( INT Signal ));
53 ba258e65 2002-05-27 alex LOCAL VOID Show_Version PARAMS(( VOID ));
54 ba258e65 2002-05-27 alex LOCAL VOID Show_Help PARAMS(( VOID ));
58 ba258e65 2002-05-27 alex main( int argc, const char *argv[] )
60 70c9c051 2002-11-10 alex struct passwd *pwd;
61 70c9c051 2002-11-10 alex struct group *grp;
62 a89dc546 2002-03-27 alex BOOLEAN ok, configtest = FALSE;
63 c7b55aa6 2002-10-09 alex LONG pid, n;
66 9ec32d15 2002-06-02 alex umask( 0077 );
68 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = NGIRCd_SignalRestart = NGIRCd_SignalRehash = FALSE;
69 43a4bc5b 2002-12-19 alex NGIRCd_NoDaemon = NGIRCd_Passive = FALSE;
70 52424b49 2002-01-11 alex #ifdef DEBUG
71 52424b49 2002-01-11 alex NGIRCd_Debug = FALSE;
73 d79a7d28 2002-01-18 alex #ifdef SNIFFER
74 d79a7d28 2002-01-18 alex NGIRCd_Sniffer = FALSE;
76 6626395c 2002-12-26 alex strlcpy( NGIRCd_ConfFile, SYSCONFDIR, sizeof( NGIRCd_ConfFile ));
77 6626395c 2002-12-26 alex strlcat( NGIRCd_ConfFile, CONFIG_FILE, sizeof( NGIRCd_ConfFile ));
79 52424b49 2002-01-11 alex /* Kommandozeile parsen */
80 52424b49 2002-01-11 alex for( i = 1; i < argc; i++ )
83 52424b49 2002-01-11 alex if(( argv[i][0] == '-' ) && ( argv[i][1] == '-' ))
85 52424b49 2002-01-11 alex /* Lange Option */
87 72accd4e 2002-03-28 alex if( strcmp( argv[i], "--config" ) == 0 )
89 72accd4e 2002-03-28 alex if( i + 1 < argc )
91 0ced4181 2002-12-26 alex /* Ok, there's an parameter left */
92 0ced4181 2002-12-26 alex strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile ));
94 0ced4181 2002-12-26 alex /* next parameter */
95 72accd4e 2002-03-28 alex i++; ok = TRUE;
98 a89dc546 2002-03-27 alex if( strcmp( argv[i], "--configtest" ) == 0 )
100 a89dc546 2002-03-27 alex configtest = TRUE;
103 eea1a88b 2002-02-19 alex #ifdef DEBUG
104 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--debug" ) == 0 )
106 eea1a88b 2002-02-19 alex NGIRCd_Debug = TRUE;
110 52424b49 2002-01-11 alex if( strcmp( argv[i], "--help" ) == 0 )
112 a89dc546 2002-03-27 alex Show_Version( );
113 a89dc546 2002-03-27 alex puts( "" ); Show_Help( ); puts( "" );
116 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--nodaemon" ) == 0 )
118 eea1a88b 2002-02-19 alex NGIRCd_NoDaemon = TRUE;
121 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--passive" ) == 0 )
123 eea1a88b 2002-02-19 alex NGIRCd_Passive = TRUE;
126 d79a7d28 2002-01-18 alex #ifdef SNIFFER
127 d79a7d28 2002-01-18 alex if( strcmp( argv[i], "--sniffer" ) == 0 )
129 d79a7d28 2002-01-18 alex NGIRCd_Sniffer = TRUE;
133 eea1a88b 2002-02-19 alex if( strcmp( argv[i], "--version" ) == 0 )
135 d67d94ea 2002-03-10 alex Show_Version( );
139 52424b49 2002-01-11 alex else if(( argv[i][0] == '-' ) && ( argv[i][1] != '-' ))
141 52424b49 2002-01-11 alex /* Kurze Option */
143 c7b55aa6 2002-10-09 alex for( n = 1; n < (LONG)strlen( argv[i] ); n++ )
145 52424b49 2002-01-11 alex ok = FALSE;
146 52424b49 2002-01-11 alex #ifdef DEBUG
147 52424b49 2002-01-11 alex if( argv[i][n] == 'd' )
149 52424b49 2002-01-11 alex NGIRCd_Debug = TRUE;
153 72accd4e 2002-03-28 alex if( argv[i][n] == 'f' )
155 85aad869 2002-03-31 alex if(( ! argv[i][n + 1] ) && ( i + 1 < argc ))
157 0ced4181 2002-12-26 alex /* Ok, next character is a blank */
158 0ced4181 2002-12-26 alex strlcpy( NGIRCd_ConfFile, argv[i + 1], sizeof( NGIRCd_ConfFile ));
160 0ced4181 2002-12-26 alex /* go to the following parameter */
161 c7b55aa6 2002-10-09 alex i++; n = (LONG)strlen( argv[i] );
165 eea1a88b 2002-02-19 alex if( argv[i][n] == 'n' )
167 eea1a88b 2002-02-19 alex NGIRCd_NoDaemon = TRUE;
170 eea1a88b 2002-02-19 alex if( argv[i][n] == 'p' )
172 eea1a88b 2002-02-19 alex NGIRCd_Passive = TRUE;
175 d79a7d28 2002-01-18 alex #ifdef SNIFFER
176 d79a7d28 2002-01-18 alex if( argv[i][n] == 's' )
178 d79a7d28 2002-01-18 alex NGIRCd_Sniffer = TRUE;
185 ba258e65 2002-05-27 alex printf( "%s: invalid option \"-%c\"!\n", PACKAGE, argv[i][n] );
186 ba258e65 2002-05-27 alex printf( "Try \"%s --help\" for more information.\n", PACKAGE );
194 ba258e65 2002-05-27 alex printf( "%s: invalid option \"%s\"!\n", PACKAGE, argv[i] );
195 ba258e65 2002-05-27 alex printf( "Try \"%s --help\" for more information.\n", PACKAGE );
200 eea1a88b 2002-02-19 alex /* Debug-Level (fuer IRC-Befehl "VERSION") ermitteln */
201 eea1a88b 2002-02-19 alex strcpy( NGIRCd_DebugLevel, "" );
202 eea1a88b 2002-02-19 alex #ifdef DEBUG
203 eea1a88b 2002-02-19 alex if( NGIRCd_Debug ) strcpy( NGIRCd_DebugLevel, "1" );
205 eea1a88b 2002-02-19 alex #ifdef SNIFFER
206 991da8ea 2002-05-18 alex if( NGIRCd_Sniffer )
208 991da8ea 2002-05-18 alex NGIRCd_Debug = TRUE;
209 991da8ea 2002-05-18 alex strcpy( NGIRCd_DebugLevel, "2" );
213 a89dc546 2002-03-27 alex /* Soll nur die Konfigurations ueberprueft und ausgegeben werden? */
214 a89dc546 2002-03-27 alex if( configtest )
216 a89dc546 2002-03-27 alex Show_Version( ); puts( "" );
217 a89dc546 2002-03-27 alex exit( Conf_Test( ));
220 43a4bc5b 2002-12-19 alex while( ! NGIRCd_SignalQuit )
222 22cf0c5d 2002-01-12 alex /* In der Regel wird ein Sub-Prozess ge-fork()'t, der
223 22cf0c5d 2002-01-12 alex * nicht mehr mit dem Terminal verbunden ist. Mit der
224 22cf0c5d 2002-01-12 alex * Option "--nodaemon" kann dies (z.B. zum Debuggen)
225 22cf0c5d 2002-01-12 alex * verhindert werden. */
226 22cf0c5d 2002-01-12 alex if( ! NGIRCd_NoDaemon )
228 22cf0c5d 2002-01-12 alex /* Daemon im Hintergrund erzeugen */
229 c7b55aa6 2002-10-09 alex pid = (LONG)fork( );
230 22cf0c5d 2002-01-12 alex if( pid > 0 )
232 22cf0c5d 2002-01-12 alex /* "alter" Prozess */
235 22cf0c5d 2002-01-12 alex if( pid < 0 )
237 22cf0c5d 2002-01-12 alex /* Fehler */
238 ba258e65 2002-05-27 alex printf( "%s: Can't fork: %s!\nFatal error, exiting now ...\n", PACKAGE, strerror( errno ));
242 fe2bc90e 2002-03-06 alex /* Child-Prozess initialisieren */
243 95a4b1b1 2002-03-25 alex (VOID)setsid( );
244 22cf0c5d 2002-01-12 alex chdir( "/" );
247 804b1ec4 2001-12-31 alex /* Globale Variablen initialisieren */
248 804b1ec4 2001-12-31 alex NGIRCd_Start = time( NULL );
249 95a4b1b1 2002-03-25 alex (VOID)strftime( NGIRCd_StartStr, 64, "%a %b %d %Y at %H:%M:%S (%Z)", localtime( &NGIRCd_Start ));
250 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = FALSE;
251 43a4bc5b 2002-12-19 alex NGIRCd_SignalRestart = FALSE;
252 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = FALSE;
254 804b1ec4 2001-12-31 alex /* Module initialisieren */
255 804b1ec4 2001-12-31 alex Log_Init( );
256 ba258e65 2002-05-27 alex Resolve_Init( );
257 804b1ec4 2001-12-31 alex Conf_Init( );
258 ba258e65 2002-05-27 alex Lists_Init( );
259 804b1ec4 2001-12-31 alex Channel_Init( );
260 804b1ec4 2001-12-31 alex Client_Init( );
261 804b1ec4 2001-12-31 alex Conn_Init( );
263 07c3e62e 2002-03-29 alex /* Wenn als root ausgefuehrt und eine andere UID
264 07c3e62e 2002-03-29 alex * konfiguriert ist, jetzt zu dieser wechseln */
265 fe06f6e9 2002-03-29 alex if( getuid( ) == 0 )
267 fe06f6e9 2002-03-29 alex if( Conf_GID != 0 )
269 07c3e62e 2002-03-29 alex /* Neue Group-ID setzen */
270 07c3e62e 2002-03-29 alex if( setgid( Conf_GID ) != 0 ) Log( LOG_ERR, "Can't change Group-ID to %u: %s", Conf_GID, strerror( errno ));
272 fe06f6e9 2002-03-29 alex if( Conf_UID != 0 )
274 07c3e62e 2002-03-29 alex /* Neue User-ID setzen */
275 fe06f6e9 2002-03-29 alex if( setuid( Conf_UID ) != 0 ) Log( LOG_ERR, "Can't change User-ID to %u: %s", Conf_UID, strerror( errno ));
279 70c9c051 2002-11-10 alex /* User, Gruppe und Prozess-ID des Daemon ausgeben */
280 70c9c051 2002-11-10 alex pwd = getpwuid( getuid( )); grp = getgrgid( getgid( ));
281 70c9c051 2002-11-10 alex 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( ));
283 70c9c051 2002-11-10 alex /* stderr in "Error-File" umlenken */
284 fe06f6e9 2002-03-29 alex Log_InitErrorfile( );
286 804b1ec4 2001-12-31 alex /* Signal-Handler initialisieren */
287 804b1ec4 2001-12-31 alex Initialize_Signal_Handler( );
289 c76e6769 2002-09-02 alex /* Protokoll- und Server-Identifikation erzeugen. Die vom ngIRCd
290 c76e6769 2002-09-02 alex * beim PASS-Befehl verwendete Syntax sowie die erweiterten Flags
291 c76e6769 2002-09-02 alex * sind in doc/Protocol.txt beschrieben. */
292 14cbca87 2002-09-07 alex #ifdef IRCPLUS
293 1c668252 2002-09-03 alex sprintf( NGIRCd_ProtoID, "%s%s %s|%s:%s", PROTOVER, PROTOIRCPLUS, PACKAGE, VERSION, IRCPLUSFLAGS );
294 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
295 65f3adca 2002-11-26 alex strcat( NGIRCd_ProtoID, "Z" );
297 c76e6769 2002-09-02 alex if( Conf_OperCanMode ) strcat( NGIRCd_ProtoID, "o" );
299 14cbca87 2002-09-07 alex sprintf( NGIRCd_ProtoID, "%s%s %s|%s", PROTOVER, PROTOIRC, PACKAGE, VERSION );
301 c76e6769 2002-09-02 alex strcat( NGIRCd_ProtoID, " P" );
302 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
303 65f3adca 2002-11-26 alex strcat( NGIRCd_ProtoID, "Z" );
305 65b31ffb 2002-09-02 alex Log( LOG_DEBUG, "Protocol and server ID is \"%s\".", NGIRCd_ProtoID );
307 b788a3da 2002-06-02 alex /* Vordefinierte Channels anlegen */
308 b788a3da 2002-06-02 alex Channel_InitPredefined( );
310 804b1ec4 2001-12-31 alex /* Listen-Ports initialisieren */
311 e311cc01 2002-11-22 alex if( Conn_InitListeners( ) < 1 )
313 e311cc01 2002-11-22 alex Log( LOG_ALERT, "Server isn't listening on a single port!" );
314 e311cc01 2002-11-22 alex Log( LOG_ALERT, "%s exiting due to fatal errors!", PACKAGE );
318 804b1ec4 2001-12-31 alex /* Hauptschleife */
319 9ec32d15 2002-06-02 alex Conn_Handler( );
321 804b1ec4 2001-12-31 alex /* Alles abmelden */
322 804b1ec4 2001-12-31 alex Conn_Exit( );
323 804b1ec4 2001-12-31 alex Client_Exit( );
324 804b1ec4 2001-12-31 alex Channel_Exit( );
325 ba258e65 2002-05-27 alex Lists_Exit( );
326 804b1ec4 2001-12-31 alex Log_Exit( );
330 f4ade537 2001-12-11 alex } /* main */
333 ba258e65 2002-05-27 alex GLOBAL CHAR *
334 ba258e65 2002-05-27 alex NGIRCd_Version( VOID )
336 52424b49 2002-01-11 alex STATIC CHAR version[126];
338 25f32ce8 2002-10-07 alex #ifdef CVSDATE
339 25f32ce8 2002-10-07 alex sprintf( version, "%s %s(%s)-%s", PACKAGE, VERSION, CVSDATE, NGIRCd_VersionAddition( ));
341 14cbca87 2002-09-07 alex sprintf( version, "%s %s-%s", PACKAGE, VERSION, NGIRCd_VersionAddition( ));
343 3fbbfe44 2002-02-17 alex return version;
344 3fbbfe44 2002-02-17 alex } /* NGIRCd_Version */
347 ba258e65 2002-05-27 alex GLOBAL CHAR *
348 ba258e65 2002-05-27 alex NGIRCd_VersionAddition( VOID )
350 3fbbfe44 2002-02-17 alex STATIC CHAR txt[64];
352 52424b49 2002-01-11 alex strcpy( txt, "" );
354 52424b49 2002-01-11 alex #ifdef USE_SYSLOG
355 52424b49 2002-01-11 alex if( txt[0] ) strcat( txt, "+" );
356 52424b49 2002-01-11 alex strcat( txt, "SYSLOG" );
358 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
359 65f3adca 2002-11-26 alex if( txt[0] ) strcat( txt, "+" );
360 65f3adca 2002-11-26 alex strcat( txt, "ZLIB" );
362 52424b49 2002-01-11 alex #ifdef DEBUG
363 52424b49 2002-01-11 alex if( txt[0] ) strcat( txt, "+" );
364 52424b49 2002-01-11 alex strcat( txt, "DEBUG" );
366 52424b49 2002-01-11 alex #ifdef SNIFFER
367 52424b49 2002-01-11 alex if( txt[0] ) strcat( txt, "+" );
368 52424b49 2002-01-11 alex strcat( txt, "SNIFFER" );
370 14cbca87 2002-09-07 alex #ifdef STRICT_RFC
371 14cbca87 2002-09-07 alex if( txt[0] ) strcat( txt, "+" );
372 14cbca87 2002-09-07 alex strcat( txt, "RFC" );
374 14cbca87 2002-09-07 alex #ifdef IRCPLUS
375 14cbca87 2002-09-07 alex if( txt[0] ) strcat( txt, "+" );
376 14cbca87 2002-09-07 alex strcat( txt, "IRCPLUS" );
379 6626395c 2002-12-26 alex if( txt[0] ) strlcat( txt, "-", sizeof( txt ));
380 6626395c 2002-12-26 alex strlcat( txt, TARGET_CPU, sizeof( txt ));
381 6626395c 2002-12-26 alex strlcat( txt, "/", sizeof( txt ));
382 6626395c 2002-12-26 alex strlcat( txt, TARGET_VENDOR, sizeof( txt ));
383 6626395c 2002-12-26 alex strlcat( txt, "/", sizeof( txt ));
384 6626395c 2002-12-26 alex strlcat( txt, TARGET_OS, sizeof( txt ));
386 3fbbfe44 2002-02-17 alex return txt;
387 3fbbfe44 2002-02-17 alex } /* NGIRCd_VersionAddition */
390 e311cc01 2002-11-22 alex GLOBAL VOID
391 cf2d4794 2002-11-22 alex NGIRCd_Rehash( VOID )
393 e311cc01 2002-11-22 alex CHAR old_name[CLIENT_ID_LEN];
395 43a4bc5b 2002-12-19 alex Log( LOG_NOTICE|LOG_snotice, "Re-reading configuration NOW!" );
396 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = FALSE;
398 e311cc01 2002-11-22 alex /* Alle Listen-Sockets schliessen */
399 e311cc01 2002-11-22 alex Conn_ExitListeners( );
401 e311cc01 2002-11-22 alex /* Alten Server-Namen merken */
402 695631b2 2002-12-26 alex assert( sizeof( old_name ) == sizeof( Conf_ServerName ));
403 e311cc01 2002-11-22 alex strcpy( old_name, Conf_ServerName );
405 e311cc01 2002-11-22 alex /* Konfiguration neu lesen ... */
406 a2544e49 2002-12-30 alex Conf_Rehash( );
408 e311cc01 2002-11-22 alex /* Alten Server-Namen wiederherstellen: dieser
409 e311cc01 2002-11-22 alex * kann nicht zur Laufzeit geaendert werden ... */
410 e311cc01 2002-11-22 alex if( strcmp( old_name, Conf_ServerName ) != 0 )
412 e311cc01 2002-11-22 alex strcpy( Conf_ServerName, old_name );
413 e311cc01 2002-11-22 alex Log( LOG_ERR, "Can't change \"ServerName\" on runtime! Ignored new name." );
416 e311cc01 2002-11-22 alex /* neue pre-defined Channel anlegen: */
417 e311cc01 2002-11-22 alex Channel_InitPredefined( );
419 e311cc01 2002-11-22 alex /* Listen-Sockets neu anlegen: */
420 e311cc01 2002-11-22 alex Conn_InitListeners( );
422 43a4bc5b 2002-12-19 alex Log( LOG_NOTICE|LOG_snotice, "Re-reading of configuration done." );
423 cf2d4794 2002-11-22 alex } /* NGIRCd_Rehash */
427 ba258e65 2002-05-27 alex Initialize_Signal_Handler( VOID )
429 08cf5607 2001-12-26 alex /* Signal-Handler initialisieren: einige Signale
430 08cf5607 2001-12-26 alex * werden ignoriert, andere speziell behandelt. */
432 62266a8d 2002-02-25 alex #ifdef HAVE_SIGACTION
433 62266a8d 2002-02-25 alex /* sigaction() ist vorhanden */
435 418add93 2001-12-12 alex struct sigaction saction;
437 418add93 2001-12-12 alex /* Signal-Struktur initialisieren */
438 418add93 2001-12-12 alex memset( &saction, 0, sizeof( saction ));
439 23253edb 2002-01-22 alex saction.sa_handler = Signal_Handler;
440 9919f38d 2002-02-19 alex #ifdef SA_RESTART
441 6f955d2a 2002-02-23 alex saction.sa_flags |= SA_RESTART;
443 6f955d2a 2002-02-23 alex #ifdef SA_NOCLDWAIT
444 6f955d2a 2002-02-23 alex saction.sa_flags |= SA_NOCLDWAIT;
447 418add93 2001-12-12 alex /* Signal-Handler einhaengen */
448 418add93 2001-12-12 alex sigaction( SIGINT, &saction, NULL );
449 418add93 2001-12-12 alex sigaction( SIGQUIT, &saction, NULL );
450 418add93 2001-12-12 alex sigaction( SIGTERM, &saction, NULL);
451 3fbbfe44 2002-02-17 alex sigaction( SIGHUP, &saction, NULL);
452 03d971d9 2002-01-02 alex sigaction( SIGCHLD, &saction, NULL);
454 eb952e35 2001-12-24 alex /* einige Signale ignorieren */
455 eb952e35 2001-12-24 alex saction.sa_handler = SIG_IGN;
456 eb952e35 2001-12-24 alex sigaction( SIGPIPE, &saction, NULL );
458 62266a8d 2002-02-25 alex /* kein sigaction() vorhanden */
460 62266a8d 2002-02-25 alex /* Signal-Handler einhaengen */
461 62266a8d 2002-02-25 alex signal( SIGINT, Signal_Handler );
462 62266a8d 2002-02-25 alex signal( SIGQUIT, Signal_Handler );
463 62266a8d 2002-02-25 alex signal( SIGTERM, Signal_Handler );
464 62266a8d 2002-02-25 alex signal( SIGHUP, Signal_Handler );
465 62266a8d 2002-02-25 alex signal( SIGCHLD, Signal_Handler );
467 62266a8d 2002-02-25 alex /* einige Signale ignorieren */
468 62266a8d 2002-02-25 alex signal( SIGPIPE, SIG_IGN );
470 418add93 2001-12-12 alex } /* Initialize_Signal_Handler */
474 ba258e65 2002-05-27 alex Signal_Handler( INT Signal )
476 418add93 2001-12-12 alex /* Signal-Handler. Dieser wird aufgerufen, wenn eines der Signale eintrifft,
477 418add93 2001-12-12 alex * fuer das wir uns registriert haben (vgl. Initialize_Signal_Handler). Die
478 418add93 2001-12-12 alex * Nummer des eingetroffenen Signals wird der Funktion uebergeben. */
480 f4ade537 2001-12-11 alex switch( Signal )
482 f4ade537 2001-12-11 alex case SIGTERM:
483 b61b8c4d 2001-12-12 alex case SIGINT:
484 b61b8c4d 2001-12-12 alex case SIGQUIT:
485 418add93 2001-12-12 alex /* wir soll(t)en uns wohl beenden ... */
486 43a4bc5b 2002-12-19 alex NGIRCd_SignalQuit = TRUE;
488 3fbbfe44 2002-02-17 alex case SIGHUP:
489 e311cc01 2002-11-22 alex /* Konfiguration neu einlesen: */
490 43a4bc5b 2002-12-19 alex NGIRCd_SignalRehash = TRUE;
492 03d971d9 2002-01-02 alex case SIGCHLD:
493 03d971d9 2002-01-02 alex /* Child-Prozess wurde beendet. Zombies vermeiden: */
494 03d971d9 2002-01-02 alex while( waitpid( -1, NULL, WNOHANG ) > 0);
496 43a4bc5b 2002-12-19 alex #ifdef DEBUG
498 418add93 2001-12-12 alex /* unbekanntes bzw. unbehandeltes Signal */
499 43a4bc5b 2002-12-19 alex Log( LOG_DEBUG, "Got signal %d! Ignored.", Signal );
502 f4ade537 2001-12-11 alex } /* Signal_Handler */
506 ba258e65 2002-05-27 alex Show_Version( VOID )
508 52424b49 2002-01-11 alex puts( NGIRCd_Version( ));
509 5e3e3ad4 2003-01-01 alex puts( "Copyright (c)2001-2003 by Alexander Barton (<alex@barton.de>)." );
510 5b27e491 2002-04-01 alex puts( "Homepage: <http://arthur.ath.cx/~alex/ngircd/>\n" );
511 52424b49 2002-01-11 alex puts( "This is free software; see the source for copying conditions. There is NO" );
512 52424b49 2002-01-11 alex puts( "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." );
513 52424b49 2002-01-11 alex } /* Show_Version */
517 ba258e65 2002-05-27 alex Show_Help( VOID )
519 52424b49 2002-01-11 alex #ifdef DEBUG
520 72accd4e 2002-03-28 alex puts( " -d, --debug log extra debug messages" );
522 72accd4e 2002-03-28 alex puts( " -f, --config <f> use file <f> as configuration file" );
523 1c0ded41 2002-11-18 alex puts( " -n, --nodaemon don't fork and don't detach from controlling terminal" );
524 72accd4e 2002-03-28 alex puts( " -p, --passive disable automatic connections to other servers" );
525 72accd4e 2002-03-28 alex #ifdef SNIFFER
526 72accd4e 2002-03-28 alex puts( " -s, --sniffer enable network sniffer and display all IRC traffic" );
528 72accd4e 2002-03-28 alex puts( " --configtest read, validate and display configuration; then exit" );
529 72accd4e 2002-03-28 alex puts( " --version output version information and exit" );
530 72accd4e 2002-03-28 alex puts( " --help display this help and exit" );
531 52424b49 2002-01-11 alex } /* Show_Help */
534 f4ade537 2001-12-11 alex /* -eof- */