Browse code

- logging facility can be configure - usefull when you config syslogd to divert all ser loggings into a separat file. Config param is log_facility=LOG_LOCAL0 (see syslog(3) man page)

Bogdan-Andrei Iancu authored on 12/02/2004 15:47:37
Showing 5 changed files
... ...
@@ -155,6 +155,7 @@ OR		"or"|"||"|"|"
155 155
 DEBUG	debug
156 156
 FORK	fork
157 157
 LOGSTDERROR	log_stderror
158
+LOGFACILITY	log_facility
158 159
 LISTEN		listen
159 160
 ALIAS		alias
160 161
 DNS		 dns
... ...
@@ -315,6 +316,7 @@ EAT_ABLE	[\ \t\b\r]
315 315
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
316 316
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
317 317
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
318
+<INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
318 319
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
319 320
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
320 321
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
... ...
@@ -181,6 +181,7 @@ static struct id_list* mk_listen_id(char*, int, int);
181 181
 %token DEBUG
182 182
 %token FORK
183 183
 %token LOGSTDERROR
184
+%token LOGFACILITY
184 185
 %token LISTEN
185 186
 %token ALIAS
186 187
 %token DNS
... ...
@@ -367,6 +368,13 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
367 367
 		| FORK  EQUAL error  { yyerror("boolean value expected"); }
368 368
 		| LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
369 369
 		| LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
370
+		| LOGFACILITY EQUAL ID {
371
+					if ( (i_tmp=str2facility($3))==-1)
372
+						yyerror("bad facility (see syslog(3) man page)");
373
+					if (!config_check)
374
+						log_facility=i_tmp;
375
+									}
376
+		| LOGFACILITY EQUAL error { yyerror("ID expected"); }
370 377
 		| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
371 378
 		| DNS EQUAL error { yyerror("boolean value expected"); }
372 379
 		| REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
... ...
@@ -35,6 +35,19 @@
35 35
  
36 36
 #include <stdarg.h>
37 37
 #include <stdio.h>
38
+#include <strings.h>
39
+
40
+static char* str_fac[]={"LOG_AUTH","LOG_AUTHPRIV","LOG_CRON","LOG_DAEMON",
41
+					"LOG_FTP","LOG_KERN","LOG_LOCAL0","LOG_LOCAL1",
42
+					"LOG_LOCAL2","LOG_LOCAL3","LOG_LOCAL4","LOG_LOCAL5",
43
+					"LOG_LOCAL6","LOG_LOCAL7","LOG_LPR","LOG_MAIL",
44
+					"LOG_NEWS","LOG_SYSLOG","LOG_USER","LOG_UUCP",0};
45
+static int int_fac[]={LOG_AUTH , LOG_AUTHPRIV , LOG_CRON , LOG_DAEMON ,
46
+					LOG_FTP , LOG_KERN , LOG_LOCAL0 , LOG_LOCAL1 ,
47
+					LOG_LOCAL2 , LOG_LOCAL3 , LOG_LOCAL4 , LOG_LOCAL5 ,
48
+					LOG_LOCAL6 , LOG_LOCAL7 , LOG_LPR , LOG_MAIL ,
49
+					LOG_NEWS , LOG_SYSLOG , LOG_USER , LOG_UUCP};
50
+
38 51
 
39 52
 void dprint(char * format, ...)
40 53
 {
... ...
@@ -46,3 +59,15 @@ void dprint(char * format, ...)
46 46
 	fflush(stderr);
47 47
 	va_end(ap);
48 48
 }
49
+
50
+
51
+int str2facility(char *s)
52
+{
53
+	int i;
54
+
55
+	for( i=0; str_fac[i] ; i++) {
56
+		if (!strcasecmp(s,str_fac[i]))
57
+			return int_fac[i];
58
+	}
59
+	return -1;
60
+}
... ...
@@ -45,17 +45,19 @@
45 45
 
46 46
 extern int debug;
47 47
 extern int log_stderr;
48
+extern int log_facility;
48 49
 
49 50
 
50 51
 #define DPRINT_LEV	1
51
-/* log facility (see syslog(3)) */
52
-#define L_FAC  LOG_DAEMON
53 52
 /* priority at which we log */
54 53
 #define DPRINT_PRIO LOG_DEBUG
55 54
 
56 55
 
57 56
 void dprint (char* format, ...);
58 57
 
58
+int str2facility(char *s);
59
+
60
+
59 61
 #ifdef NO_DEBUG
60 62
 	#ifdef __SUNPRO_C
61 63
 		#define DPrint(...)
... ...
@@ -70,7 +72,7 @@ void dprint (char* format, ...);
70 70
 					if (log_stderr){ \
71 71
 						dprint (__VA_ARGS__); \
72 72
 					}else{ \
73
-						syslog(DPRINT_LEV|L_FAC,  __VA_ARGS__); \
73
+						syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
74 74
 					}\
75 75
 				} \
76 76
 			}while(0)
... ...
@@ -81,7 +83,7 @@ void dprint (char* format, ...);
81 81
 					if (log_stderr){ \
82 82
 						dprint (fmt, ## args); \
83 83
 					}else{ \
84
-						syslog(DPRINT_LEV|L_FAC, fmt, ## args); \
84
+						syslog(DPRINT_LEV|log_facility, fmt, ## args); \
85 85
 					}\
86 86
 				} \
87 87
 			}while(0)
... ...
@@ -108,25 +110,25 @@ void dprint (char* format, ...);
108 108
 					else { \
109 109
 						switch(lev){ \
110 110
 							case L_CRIT: \
111
-								syslog(LOG_CRIT | L_FAC, __VA_ARGS__); \
111
+								syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
112 112
 								break; \
113 113
 							case L_ALERT: \
114
-								syslog(LOG_ALERT | L_FAC, __VA_ARGS__); \
114
+								syslog(LOG_ALERT|log_facility, __VA_ARGS__); \
115 115
 								break; \
116 116
 							case L_ERR: \
117
-								syslog(LOG_ERR | L_FAC, __VA_ARGS__); \
117
+								syslog(LOG_ERR|log_facility, __VA_ARGS__); \
118 118
 								break; \
119 119
 							case L_WARN: \
120
-								syslog(LOG_WARNING | L_FAC, __VA_ARGS__);\
120
+								syslog(LOG_WARNING|log_facility, __VA_ARGS__);\
121 121
 								break; \
122 122
 							case L_NOTICE: \
123
-								syslog(LOG_NOTICE | L_FAC, __VA_ARGS__); \
123
+								syslog(LOG_NOTICE|log_facility, __VA_ARGS__); \
124 124
 								break; \
125 125
 							case L_INFO: \
126
-								syslog(LOG_INFO | L_FAC, __VA_ARGS__); \
126
+								syslog(LOG_INFO|log_facility, __VA_ARGS__); \
127 127
 								break; \
128 128
 							case L_DBG: \
129
-								syslog(LOG_DEBUG | L_FAC, __VA_ARGS__); \
129
+								syslog(LOG_DEBUG|log_facility, __VA_ARGS__); \
130 130
 								break; \
131 131
 						} \
132 132
 					} \
... ...
@@ -140,25 +142,25 @@ void dprint (char* format, ...);
140 140
 					else { \
141 141
 						switch(lev){ \
142 142
 							case L_CRIT: \
143
-								syslog(LOG_CRIT | L_FAC, fmt, ##args); \
143
+								syslog(LOG_CRIT|log_facility, fmt, ##args); \
144 144
 								break; \
145 145
 							case L_ALERT: \
146
-								syslog(LOG_ALERT | L_FAC, fmt, ##args); \
146
+								syslog(LOG_ALERT|log_facility, fmt, ##args); \
147 147
 								break; \
148 148
 							case L_ERR: \
149
-								syslog(LOG_ERR | L_FAC, fmt, ##args); \
149
+								syslog(LOG_ERR|log_facility, fmt, ##args); \
150 150
 								break; \
151 151
 							case L_WARN: \
152
-								syslog(LOG_WARNING | L_FAC, fmt, ##args); \
152
+								syslog(LOG_WARNING|log_facility, fmt, ##args);\
153 153
 								break; \
154 154
 							case L_NOTICE: \
155
-								syslog(LOG_NOTICE | L_FAC, fmt, ##args); \
155
+								syslog(LOG_NOTICE|log_facility, fmt, ##args); \
156 156
 								break; \
157 157
 							case L_INFO: \
158
-								syslog(LOG_INFO | L_FAC, fmt, ##args); \
158
+								syslog(LOG_INFO|log_facility, fmt, ##args); \
159 159
 								break; \
160 160
 							case L_DBG: \
161
-								syslog(LOG_DEBUG | L_FAC, fmt, ##args); \
161
+								syslog(LOG_DEBUG|log_facility, fmt, ##args); \
162 162
 								break; \
163 163
 						} \
164 164
 					} \
... ...
@@ -294,6 +294,8 @@ int sig_flag = 0;              /* last signal received */
294 294
 int debug = L_NOTICE;
295 295
 int dont_fork = 0;
296 296
 int log_stderr = 0;
297
+/* log facility (see syslog(3)) */
298
+int log_facility = LOG_DAEMON;
297 299
 int config_check = 0;
298 300
 /* check if reply first via host==us */
299 301
 int check_via =  0;        
... ...
@@ -534,7 +536,7 @@ int daemonize(char*  name)
534 534
 	}
535 535
 	
536 536
 	if (log_stderr==0)
537
-		openlog(name, LOG_PID|LOG_CONS, LOG_DAEMON);
537
+		openlog(name, LOG_PID|LOG_CONS, log_facility);
538 538
 		/* LOG_CONS, LOG_PERRROR ? */
539 539
 	return  0;
540 540