Blame


1 f4ade537 2001-12-11 alex /*
2 f4ade537 2001-12-11 alex * ngIRCd -- The Next Generation IRC Daemon
3 1547f76c 2002-01-02 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 f4ade537 2001-12-11 alex *
5 f4ade537 2001-12-11 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 f4ade537 2001-12-11 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 f4ade537 2001-12-11 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 f4ade537 2001-12-11 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 f4ade537 2001-12-11 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 804b1ec4 2001-12-31 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11 f4ade537 2001-12-11 alex *
12 bdf53a6d 2002-03-27 alex * $Id: log.c,v 1.24 2002/03/27 16:40:06 alex Exp $
13 f4ade537 2001-12-11 alex *
14 f4ade537 2001-12-11 alex * log.c: Logging-Funktionen
15 f4ade537 2001-12-11 alex */
16 f4ade537 2001-12-11 alex
17 f4ade537 2001-12-11 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 f4ade537 2001-12-11 alex
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 f4ade537 2001-12-11 alex #include <assert.h>
22 fe2bc90e 2002-03-06 alex #include <errno.h>
23 f4ade537 2001-12-11 alex #include <stdarg.h>
24 f4ade537 2001-12-11 alex #include <stdio.h>
25 3be92e9d 2001-12-26 alex #include <string.h>
26 fe2bc90e 2002-03-06 alex #include <sys/types.h>
27 fe2bc90e 2002-03-06 alex #include <unistd.h>
28 50352dc9 2001-12-27 alex
29 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
30 3d1a0962 2001-12-12 alex #include <syslog.h>
31 50352dc9 2001-12-27 alex #endif
32 f4ade537 2001-12-11 alex
33 006c0328 2002-01-11 alex #include "ngircd.h"
34 ca33cbda 2002-03-12 alex #include "defines.h"
35 006c0328 2002-01-11 alex
36 ca33cbda 2002-03-12 alex #include "exp.h"
37 f4ade537 2001-12-11 alex #include "log.h"
38 f4ade537 2001-12-11 alex
39 f4ade537 2001-12-11 alex
40 f4ade537 2001-12-11 alex GLOBAL VOID Log_Init( VOID )
41 f4ade537 2001-12-11 alex {
42 fcb47ae6 2002-02-19 alex CHAR txt[127];
43 fcb47ae6 2002-02-19 alex
44 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
45 fcb47ae6 2002-02-19 alex /* Syslog initialisieren */
46 0dc0308d 2001-12-25 alex openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
47 50352dc9 2001-12-27 alex #endif
48 fcb47ae6 2002-02-19 alex
49 fcb47ae6 2002-02-19 alex /* Hello World! */
50 006c0328 2002-01-11 alex Log( LOG_NOTICE, "%s started.", NGIRCd_Version( ));
51 fe2bc90e 2002-03-06 alex
52 fcb47ae6 2002-02-19 alex /* Informationen uebern den "Operation Mode" */
53 fcb47ae6 2002-02-19 alex strcpy( txt, "" );
54 fcb47ae6 2002-02-19 alex #ifdef DEBUG
55 fcb47ae6 2002-02-19 alex if( NGIRCd_Debug )
56 fcb47ae6 2002-02-19 alex {
57 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
58 fcb47ae6 2002-02-19 alex strcat( txt, "debug-mode" );
59 fcb47ae6 2002-02-19 alex }
60 fcb47ae6 2002-02-19 alex #endif
61 fcb47ae6 2002-02-19 alex if( NGIRCd_NoDaemon )
62 fcb47ae6 2002-02-19 alex {
63 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
64 fcb47ae6 2002-02-19 alex strcat( txt, "no-daemon-mode" );
65 fcb47ae6 2002-02-19 alex }
66 fcb47ae6 2002-02-19 alex if( NGIRCd_Passive )
67 fcb47ae6 2002-02-19 alex {
68 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
69 fcb47ae6 2002-02-19 alex strcat( txt, "passive-mode" );
70 fcb47ae6 2002-02-19 alex }
71 fcb47ae6 2002-02-19 alex #ifdef SNIFFER
72 fcb47ae6 2002-02-19 alex if( NGIRCd_Sniffer )
73 fcb47ae6 2002-02-19 alex {
74 fcb47ae6 2002-02-19 alex if( txt[0] ) strcat( txt, ", " );
75 fcb47ae6 2002-02-19 alex strcat( txt, "network sniffer" );
76 fcb47ae6 2002-02-19 alex }
77 fcb47ae6 2002-02-19 alex #endif
78 fcb47ae6 2002-02-19 alex if( txt[0] ) Log( LOG_INFO, "Activating: %s.", txt );
79 fe2bc90e 2002-03-06 alex
80 fe2bc90e 2002-03-06 alex /* stderr in Datei umlenken */
81 fe2bc90e 2002-03-06 alex fflush( stderr );
82 fe2bc90e 2002-03-06 alex if( ! freopen( ERROR_FILE, "a+", stderr )) Log( LOG_ERR, "Can't reopen stderr (\""ERROR_FILE"\"): %s", strerror( errno ));
83 fe2bc90e 2002-03-06 alex
84 fe2bc90e 2002-03-06 alex fprintf( stderr, "\n--- %s ---\n\n", NGIRCd_StartStr );
85 95a4b1b1 2002-03-25 alex fprintf( stderr, "%s started.\npid=%ld, ppid=%ld, uid=%ld, gid=%ld [euid=%ld, egid=%ld].\nActivating: %s\n\n", NGIRCd_Version( ), (INT32)getpid( ), (INT32)getppid( ), (INT32)getuid( ), (INT32)getgid( ), (INT32)geteuid( ), (INT32)getegid( ), txt[0] ? txt : "-" );
86 fe2bc90e 2002-03-06 alex fflush( stderr );
87 f4ade537 2001-12-11 alex } /* Log_Init */
88 f4ade537 2001-12-11 alex
89 f4ade537 2001-12-11 alex
90 f4ade537 2001-12-11 alex GLOBAL VOID Log_Exit( VOID )
91 f4ade537 2001-12-11 alex {
92 b9a2c4a8 2002-03-21 alex time_t t;
93 b9a2c4a8 2002-03-21 alex
94 fcb47ae6 2002-02-19 alex /* Good Bye! */
95 3b51e18c 2001-12-15 alex Log( LOG_NOTICE, PACKAGE" done.");
96 b9a2c4a8 2002-03-21 alex
97 b9a2c4a8 2002-03-21 alex t = time( NULL );
98 b9a2c4a8 2002-03-21 alex fputs( ctime( &t ), stderr );
99 95a4b1b1 2002-03-25 alex fprintf( stderr, PACKAGE" done (pid=%ld).\n", (INT32)getpid( ));
100 fe2bc90e 2002-03-06 alex fflush( stderr );
101 fe2bc90e 2002-03-06 alex
102 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
103 fcb47ae6 2002-02-19 alex /* syslog abmelden */
104 3d1a0962 2001-12-12 alex closelog( );
105 50352dc9 2001-12-27 alex #endif
106 f4ade537 2001-12-11 alex } /* Log_Exit */
107 f4ade537 2001-12-11 alex
108 f4ade537 2001-12-11 alex
109 f4ade537 2001-12-11 alex GLOBAL VOID Log( CONST INT Level, CONST CHAR *Format, ... )
110 f4ade537 2001-12-11 alex {
111 f4ade537 2001-12-11 alex /* Eintrag in Logfile(s) schreiben */
112 f4ade537 2001-12-11 alex
113 f4ade537 2001-12-11 alex CHAR msg[MAX_LOG_MSG_LEN];
114 f4ade537 2001-12-11 alex va_list ap;
115 b9a2c4a8 2002-03-21 alex time_t t;
116 f4ade537 2001-12-11 alex
117 ec1922ef 2001-12-29 alex assert( Format != NULL );
118 ec1922ef 2001-12-29 alex
119 006c0328 2002-01-11 alex #ifdef DEBUG
120 006c0328 2002-01-11 alex if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
121 006c0328 2002-01-11 alex #else
122 d4a60bd4 2001-12-25 alex if( Level == LOG_DEBUG ) return;
123 d4a60bd4 2001-12-25 alex #endif
124 d4a60bd4 2001-12-25 alex
125 f4ade537 2001-12-11 alex /* String mit variablen Argumenten zusammenbauen ... */
126 f4ade537 2001-12-11 alex va_start( ap, Format );
127 10363b39 2002-03-03 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
128 10363b39 2002-03-03 alex va_end( ap );
129 f4ade537 2001-12-11 alex
130 fe2bc90e 2002-03-06 alex /* In Error-File schreiben */
131 b9a2c4a8 2002-03-21 alex if( Level <= LOG_ERR )
132 b9a2c4a8 2002-03-21 alex {
133 b9a2c4a8 2002-03-21 alex t = time( NULL );
134 b9a2c4a8 2002-03-21 alex fputs( ctime( &t ), stderr );
135 b9a2c4a8 2002-03-21 alex fprintf( stderr, "[%d] %s\n\n", Level, msg );
136 b9a2c4a8 2002-03-21 alex }
137 fe2bc90e 2002-03-06 alex
138 f4ade537 2001-12-11 alex /* ... und ausgeben */
139 006c0328 2002-01-11 alex if( NGIRCd_NoDaemon ) printf( "[%d] %s\n", Level, msg );
140 fe2bc90e 2002-03-06 alex
141 50352dc9 2001-12-27 alex #ifdef USE_SYSLOG
142 fe2bc90e 2002-03-06 alex /* Syslog */
143 3d1a0962 2001-12-12 alex syslog( Level, msg );
144 50352dc9 2001-12-27 alex #endif
145 f4ade537 2001-12-11 alex } /* Log */
146 f4ade537 2001-12-11 alex
147 f4ade537 2001-12-11 alex
148 ec1922ef 2001-12-29 alex GLOBAL VOID Log_Init_Resolver( VOID )
149 ec1922ef 2001-12-29 alex {
150 ec1922ef 2001-12-29 alex #ifdef USE_SYSLOG
151 ec1922ef 2001-12-29 alex openlog( PACKAGE, LOG_CONS|LOG_PID, LOG_LOCAL5 );
152 ec1922ef 2001-12-29 alex #endif
153 ec1922ef 2001-12-29 alex } /* Log_Init_Resolver */
154 ec1922ef 2001-12-29 alex
155 ec1922ef 2001-12-29 alex
156 ec1922ef 2001-12-29 alex GLOBAL VOID Log_Exit_Resolver( VOID )
157 ec1922ef 2001-12-29 alex {
158 ec1922ef 2001-12-29 alex #ifdef USE_SYSLOG
159 ec1922ef 2001-12-29 alex closelog( );
160 ec1922ef 2001-12-29 alex #endif
161 ec1922ef 2001-12-29 alex } /* Log_Exit_Resolver */
162 ec1922ef 2001-12-29 alex
163 ec1922ef 2001-12-29 alex
164 ec1922ef 2001-12-29 alex GLOBAL VOID Log_Resolver( CONST INT Level, CONST CHAR *Format, ... )
165 ec1922ef 2001-12-29 alex {
166 ec1922ef 2001-12-29 alex /* Eintrag des Resolver in Logfile(s) schreiben */
167 ec1922ef 2001-12-29 alex
168 03783eea 2002-01-05 alex #ifndef USE_SYSLOG
169 03783eea 2002-01-05 alex return;
170 03783eea 2002-01-05 alex #else
171 03783eea 2002-01-05 alex
172 ec1922ef 2001-12-29 alex CHAR msg[MAX_LOG_MSG_LEN];
173 ec1922ef 2001-12-29 alex va_list ap;
174 ec1922ef 2001-12-29 alex
175 ec1922ef 2001-12-29 alex assert( Format != NULL );
176 ec1922ef 2001-12-29 alex
177 006c0328 2002-01-11 alex #ifdef DEBUG
178 006c0328 2002-01-11 alex if(( Level == LOG_DEBUG ) && ( ! NGIRCd_Debug )) return;
179 006c0328 2002-01-11 alex #else
180 ec1922ef 2001-12-29 alex if( Level == LOG_DEBUG ) return;
181 ec1922ef 2001-12-29 alex #endif
182 ec1922ef 2001-12-29 alex
183 ec1922ef 2001-12-29 alex /* String mit variablen Argumenten zusammenbauen ... */
184 ec1922ef 2001-12-29 alex va_start( ap, Format );
185 10363b39 2002-03-03 alex vsnprintf( msg, MAX_LOG_MSG_LEN, Format, ap );
186 10363b39 2002-03-03 alex va_end( ap );
187 ec1922ef 2001-12-29 alex
188 ec1922ef 2001-12-29 alex /* ... und ausgeben */
189 ec1922ef 2001-12-29 alex syslog( Level, msg );
190 ec1922ef 2001-12-29 alex
191 03783eea 2002-01-05 alex #endif
192 ec1922ef 2001-12-29 alex } /* Log_Resolver */
193 ec1922ef 2001-12-29 alex
194 ec1922ef 2001-12-29 alex
195 f4ade537 2001-12-11 alex /* -eof- */