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 316
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
316 317
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
317 318
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
319
+<INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
318 320
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
319 321
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
320 322
 <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 368
 		| FORK  EQUAL error  { yyerror("boolean value expected"); }
368 369
 		| LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
369 370
 		| LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
371
+		| LOGFACILITY EQUAL ID {
372
+					if ( (i_tmp=str2facility($3))==-1)
373
+						yyerror("bad facility (see syslog(3) man page)");
374
+					if (!config_check)
375
+						log_facility=i_tmp;
376
+									}
377
+		| LOGFACILITY EQUAL error { yyerror("ID expected"); }
370 378
 		| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
371 379
 		| DNS EQUAL error { yyerror("boolean value expected"); }
372 380
 		| 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 59
 	fflush(stderr);
47 60
 	va_end(ap);
48 61
 }
62
+
63
+
64
+int str2facility(char *s)
65
+{
66
+	int i;
67
+
68
+	for( i=0; str_fac[i] ; i++) {
69
+		if (!strcasecmp(s,str_fac[i]))
70
+			return int_fac[i];
71
+	}
72
+	return -1;
73
+}
... ...
@@ -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 72
 					if (log_stderr){ \
71 73
 						dprint (__VA_ARGS__); \
72 74
 					}else{ \
73
-						syslog(DPRINT_LEV|L_FAC,  __VA_ARGS__); \
75
+						syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
74 76
 					}\
75 77
 				} \
76 78
 			}while(0)
... ...
@@ -81,7 +83,7 @@ void dprint (char* format, ...);
81 83
 					if (log_stderr){ \
82 84
 						dprint (fmt, ## args); \
83 85
 					}else{ \
84
-						syslog(DPRINT_LEV|L_FAC, fmt, ## args); \
86
+						syslog(DPRINT_LEV|log_facility, fmt, ## args); \
85 87
 					}\
86 88
 				} \
87 89
 			}while(0)
... ...
@@ -108,25 +110,25 @@ void dprint (char* format, ...);
108 110
 					else { \
109 111
 						switch(lev){ \
110 112
 							case L_CRIT: \
111
-								syslog(LOG_CRIT | L_FAC, __VA_ARGS__); \
113
+								syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
112 114
 								break; \
113 115
 							case L_ALERT: \
114
-								syslog(LOG_ALERT | L_FAC, __VA_ARGS__); \
116
+								syslog(LOG_ALERT|log_facility, __VA_ARGS__); \
115 117
 								break; \
116 118
 							case L_ERR: \
117
-								syslog(LOG_ERR | L_FAC, __VA_ARGS__); \
119
+								syslog(LOG_ERR|log_facility, __VA_ARGS__); \
118 120
 								break; \
119 121
 							case L_WARN: \
120
-								syslog(LOG_WARNING | L_FAC, __VA_ARGS__);\
122
+								syslog(LOG_WARNING|log_facility, __VA_ARGS__);\
121 123
 								break; \
122 124
 							case L_NOTICE: \
123
-								syslog(LOG_NOTICE | L_FAC, __VA_ARGS__); \
125
+								syslog(LOG_NOTICE|log_facility, __VA_ARGS__); \
124 126
 								break; \
125 127
 							case L_INFO: \
126
-								syslog(LOG_INFO | L_FAC, __VA_ARGS__); \
128
+								syslog(LOG_INFO|log_facility, __VA_ARGS__); \
127 129
 								break; \
128 130
 							case L_DBG: \
129
-								syslog(LOG_DEBUG | L_FAC, __VA_ARGS__); \
131
+								syslog(LOG_DEBUG|log_facility, __VA_ARGS__); \
130 132
 								break; \
131 133
 						} \
132 134
 					} \
... ...
@@ -140,25 +142,25 @@ void dprint (char* format, ...);
140 142
 					else { \
141 143
 						switch(lev){ \
142 144
 							case L_CRIT: \
143
-								syslog(LOG_CRIT | L_FAC, fmt, ##args); \
145
+								syslog(LOG_CRIT|log_facility, fmt, ##args); \
144 146
 								break; \
145 147
 							case L_ALERT: \
146
-								syslog(LOG_ALERT | L_FAC, fmt, ##args); \
148
+								syslog(LOG_ALERT|log_facility, fmt, ##args); \
147 149
 								break; \
148 150
 							case L_ERR: \
149
-								syslog(LOG_ERR | L_FAC, fmt, ##args); \
151
+								syslog(LOG_ERR|log_facility, fmt, ##args); \
150 152
 								break; \
151 153
 							case L_WARN: \
152
-								syslog(LOG_WARNING | L_FAC, fmt, ##args); \
154
+								syslog(LOG_WARNING|log_facility, fmt, ##args);\
153 155
 								break; \
154 156
 							case L_NOTICE: \
155
-								syslog(LOG_NOTICE | L_FAC, fmt, ##args); \
157
+								syslog(LOG_NOTICE|log_facility, fmt, ##args); \
156 158
 								break; \
157 159
 							case L_INFO: \
158
-								syslog(LOG_INFO | L_FAC, fmt, ##args); \
160
+								syslog(LOG_INFO|log_facility, fmt, ##args); \
159 161
 								break; \
160 162
 							case L_DBG: \
161
-								syslog(LOG_DEBUG | L_FAC, fmt, ##args); \
163
+								syslog(LOG_DEBUG|log_facility, fmt, ##args); \
162 164
 								break; \
163 165
 						} \
164 166
 					} \
... ...
@@ -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 536
 	}
535 537
 	
536 538
 	if (log_stderr==0)
537
-		openlog(name, LOG_PID|LOG_CONS, LOG_DAEMON);
539
+		openlog(name, LOG_PID|LOG_CONS, log_facility);
538 540
 		/* LOG_CONS, LOG_PERRROR ? */
539 541
 	return  0;
540 542