Browse code

some backporting: - log_facility parameter - swiched from LOG to DBG some msg for SIGCHLD (done on unstable by Jan)

Bogdan-Andrei Iancu authored on 12/02/2004 16:17:48
Showing 5 changed files
... ...
@@ -151,6 +151,7 @@ OR		"or"|"||"|"|"
151 151
 DEBUG	debug
152 152
 FORK	fork
153 153
 LOGSTDERROR	log_stderror
154
+LOGFACILITY	log_facility
154 155
 LISTEN		listen
155 156
 ALIAS		alias
156 157
 DNS		 dns
... ...
@@ -302,6 +303,7 @@ EAT_ABLE	[\ \t\b\r]
302 303
 <INITIAL>{DEBUG}	{ count(); yylval.strval=yytext; return DEBUG; }
303 304
 <INITIAL>{FORK}		{ count(); yylval.strval=yytext; return FORK; }
304 305
 <INITIAL>{LOGSTDERROR}	{ yylval.strval=yytext; return LOGSTDERROR; }
306
+<INITIAL>{LOGFACILITY}	{ yylval.strval=yytext; return LOGFACILITY; }
305 307
 <INITIAL>{LISTEN}	{ count(); yylval.strval=yytext; return LISTEN; }
306 308
 <INITIAL>{ALIAS}	{ count(); yylval.strval=yytext; return ALIAS; }
307 309
 <INITIAL>{DNS}	{ count(); yylval.strval=yytext; return DNS; }
... ...
@@ -167,6 +167,7 @@ void warn(char* s);
167 167
 %token DEBUG
168 168
 %token FORK
169 169
 %token LOGSTDERROR
170
+%token LOGFACILITY
170 171
 %token LISTEN
171 172
 %token ALIAS
172 173
 %token DNS
... ...
@@ -343,6 +344,13 @@ assign_stm:	DEBUG EQUAL NUMBER { debug=$3; }
343 344
 		| FORK  EQUAL error  { yyerror("boolean value expected"); }
344 345
 		| LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
345 346
 		| LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
347
+		| LOGFACILITY EQUAL ID {
348
+					if ( (i_tmp=str2facility($3))==-1)
349
+						yyerror("bad facility (see syslog(3) man page)");
350
+					if (!config_check)
351
+						log_facility=i_tmp;
352
+									}
353
+		| LOGFACILITY EQUAL error { yyerror("ID expected"); }
346 354
 		| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
347 355
 		| DNS EQUAL error { yyerror("boolean value expected"); }
348 356
 		| 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
 					} \
... ...
@@ -291,6 +291,8 @@ int sig_flag = 0;              /* last signal received */
291 291
 int debug = L_NOTICE;
292 292
 int dont_fork = 0;
293 293
 int log_stderr = 0;
294
+/* log facility (see syslog(3)) */
295
+int log_facility = LOG_DAEMON;
294 296
 int config_check = 0;
295 297
 /* check if reply first via host==us */
296 298
 int check_via =  0;        
... ...
@@ -533,7 +535,7 @@ int daemonize(char*  name)
533 535
 	}
534 536
 	
535 537
 	if (log_stderr==0)
536
-		openlog(name, LOG_PID|LOG_CONS, LOG_DAEMON);
538
+		openlog(name, LOG_PID|LOG_CONS, log_facility);
537 539
 		/* LOG_CONS, LOG_PERRROR ? */
538 540
 	return  0;
539 541
 
... ...
@@ -699,7 +701,7 @@ static void sig_usr(int signo)
699 701
 					break;
700 702
 			case SIGCHLD:
701 703
 #ifndef 			STOP_JIRIS_CHANGES
702
-					LOG(L_INFO, "INFO: SIGCHLD received: "
704
+					DBG("INFO: SIGCHLD received: "
703 705
 						"we do not worry about grand-children\n");
704 706
 #else
705 707
 					exit(0); /* terminate if one child died */