Browse code

log_facility config parameter is declared in the cfg framework

Miklos Tirpak authored on 29/02/2008 10:04:49
Showing 7 changed files
... ...
@@ -603,7 +603,7 @@ assign_stm:
603 603
 		if ( (i_tmp=str2facility($3))==-1)
604 604
 			yyerror("bad facility (see syslog(3) man page)");
605 605
 		if (!config_check)
606
-			log_facility=i_tmp;
606
+			default_core_cfg.log_facility=i_tmp;
607 607
 	}
608 608
 	| LOGFACILITY EQUAL error { yyerror("ID expected"); }
609 609
 	| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
... ...
@@ -43,6 +43,7 @@
43 43
 
44 44
 struct cfg_group_core default_core_cfg = {
45 45
 	L_DEFAULT, /*  print only msg. < L_WARN */
46
+	LOG_DAEMON,	/* log_facility -- see syslog(3) */
46 47
 #ifdef USE_DST_BLACKLIST
47 48
 	/* blacklist */
48 49
 	0, /* dst blacklist is disabled by default */
... ...
@@ -82,7 +83,10 @@ struct cfg_group_core default_core_cfg = {
82 83
 void	*core_cfg = &default_core_cfg;
83 84
 
84 85
 cfg_def_t core_cfg_def[] = {
85
-	{"debug",	CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0, "debug level"},
86
+	{"debug",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
87
+		"debug level"},
88
+	{"log_facility",	CFG_VAR_INT|CFG_INPUT_STRING,	0, 0, log_facility_fixup, 0,
89
+		"syslog facility, see \"man 3 syslog\""},
86 90
 #ifdef USE_DST_BLACKLIST
87 91
 	/* blacklist */
88 92
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 1, use_dst_blacklist_fixup, 0,
... ...
@@ -46,6 +46,7 @@ extern void	*core_cfg;
46 46
 
47 47
 struct cfg_group_core {
48 48
 	int	debug;
49
+	int	log_facility;
49 50
 #ifdef USE_DST_BLACKLIST
50 51
 	/* blacklist */
51 52
 	int	use_dst_blacklist; /* 1 if blacklist is enabled */
... ...
@@ -71,6 +71,7 @@
71 71
 #include "globals.h"
72 72
 #include "dprint.h"
73 73
 #include "signals.h"
74
+#include "cfg/cfg.h"
74 75
 
75 76
 
76 77
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
... ...
@@ -209,7 +210,7 @@ int daemonize(char*  name)
209 210
 	}
210 211
 	
211 212
 	if (log_stderr==0)
212
-		openlog(name, LOG_PID|LOG_CONS, log_facility);
213
+		openlog(name, LOG_PID|LOG_CONS, cfg_get(core, core_cfg, log_facility));
213 214
 		/* LOG_CONS, LOG_PERRROR ? */
214 215
 
215 216
 	return  0;
... ...
@@ -82,3 +82,17 @@ int str2facility(char *s)
82 82
 	}
83 83
 	return -1;
84 84
 }
85
+
86
+/* fixup function for log_facility cfg parameter */
87
+int log_facility_fixup(void *handle, str *name, void **val)
88
+{
89
+	int	i;
90
+
91
+	if ((i = str2facility((char *)*val)) == -1) {
92
+		LOG(L_ERR, "log_facility_fixup: invalid log facility: %s\n",
93
+			(char *)*val);
94
+		return -1;
95
+	}
96
+	*val = (void *)(long)i;
97
+	return 0;
98
+}
... ...
@@ -46,7 +46,6 @@
46 46
 /* vars:*/
47 47
 
48 48
 extern int log_stderr;
49
-extern int log_facility;
50 49
 extern volatile int dprint_crit; /* protection against "simultaneous"
51 50
 									printing from signal handlers */
52 51
 
... ...
@@ -68,6 +67,7 @@ extern volatile int dprint_crit; /* protection against "simultaneous"
68 67
 void dprint (char* format, ...);
69 68
 
70 69
 int str2facility(char *s);
70
+int log_facility_fixup(void *handle, str *name, void **val);
71 71
 
72 72
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
73 73
 #if __STDC_VERSION__ < 199901L
... ...
@@ -103,7 +103,8 @@ int str2facility(char *s);
103 103
 					if (log_stderr){ \
104 104
 						dprint (__VA_ARGS__); \
105 105
 					}else{ \
106
-						syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
106
+						syslog(DPRINT_LEV|cfg_get(core, core_cfg, log_facility), \
107
+							__VA_ARGS__); \
107 108
 					}\
108 109
 					DPRINT_CRIT_EXIT; \
109 110
 				} \
... ...
@@ -116,7 +117,8 @@ int str2facility(char *s);
116 117
 					if (log_stderr){ \
117 118
 						dprint (fmt, ## args); \
118 119
 					}else{ \
119
-						syslog(DPRINT_LEV|log_facility, fmt, ## args); \
120
+						syslog(DPRINT_LEV|cfg_get(core, core_cfg, log_facility), \
121
+							fmt, ## args); \
120 122
 					}\
121 123
 					DPRINT_CRIT_EXIT; \
122 124
 				} \
... ...
@@ -145,25 +147,32 @@ int str2facility(char *s);
145 147
 					else { \
146 148
 						switch(lev){ \
147 149
 							case L_CRIT: \
148
-								syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
150
+								syslog(LOG_CRIT|cfg_get(core, core_cfg, log_facility), \
151
+									__VA_ARGS__); \
149 152
 								break; \
150 153
 							case L_ALERT: \
151
-								syslog(LOG_ALERT|log_facility, __VA_ARGS__); \
154
+								syslog(LOG_ALERT|cfg_get(core, core_cfg, log_facility), \
155
+									__VA_ARGS__); \
152 156
 								break; \
153 157
 							case L_ERR: \
154
-								syslog(LOG_ERR|log_facility, __VA_ARGS__); \
158
+								syslog(LOG_ERR|cfg_get(core, core_cfg, log_facility), \
159
+									__VA_ARGS__); \
155 160
 								break; \
156 161
 							case L_WARN: \
157
-								syslog(LOG_WARNING|log_facility, __VA_ARGS__);\
162
+								syslog(LOG_WARNING|cfg_get(core, core_cfg, log_facility), \
163
+									__VA_ARGS__);\
158 164
 								break; \
159 165
 							case L_NOTICE: \
160
-								syslog(LOG_NOTICE|log_facility, __VA_ARGS__); \
166
+								syslog(LOG_NOTICE|cfg_get(core, core_cfg, log_facility), \
167
+									__VA_ARGS__); \
161 168
 								break; \
162 169
 							case L_INFO: \
163
-								syslog(LOG_INFO|log_facility, __VA_ARGS__); \
170
+								syslog(LOG_INFO|cfg_get(core, core_cfg, log_facility), \
171
+									__VA_ARGS__); \
164 172
 								break; \
165 173
 							case L_DBG: \
166
-								syslog(LOG_DEBUG|log_facility, __VA_ARGS__); \
174
+								syslog(LOG_DEBUG|cfg_get(core, core_cfg, log_facility), \
175
+									__VA_ARGS__); \
167 176
 								break; \
168 177
 						} \
169 178
 					} \
... ...
@@ -179,25 +188,32 @@ int str2facility(char *s);
179 188
 					else { \
180 189
 						switch(lev){ \
181 190
 							case L_CRIT: \
182
-								syslog(LOG_CRIT|log_facility, fmt, ##args); \
191
+								syslog(LOG_CRIT|cfg_get(core, core_cfg, log_facility), \
192
+									fmt, ##args); \
183 193
 								break; \
184 194
 							case L_ALERT: \
185
-								syslog(LOG_ALERT|log_facility, fmt, ##args); \
195
+								syslog(LOG_ALERT|cfg_get(core, core_cfg, log_facility), \
196
+									fmt, ##args); \
186 197
 								break; \
187 198
 							case L_ERR: \
188
-								syslog(LOG_ERR|log_facility, fmt, ##args); \
199
+								syslog(LOG_ERR|cfg_get(core, core_cfg, log_facility), \
200
+									fmt, ##args); \
189 201
 								break; \
190 202
 							case L_WARN: \
191
-								syslog(LOG_WARNING|log_facility, fmt, ##args);\
203
+								syslog(LOG_WARNING|cfg_get(core, core_cfg, log_facility), \
204
+									fmt, ##args);\
192 205
 								break; \
193 206
 							case L_NOTICE: \
194
-								syslog(LOG_NOTICE|log_facility, fmt, ##args); \
207
+								syslog(LOG_NOTICE|cfg_get(core, core_cfg, log_facility), \
208
+									fmt, ##args); \
195 209
 								break; \
196 210
 							case L_INFO: \
197
-								syslog(LOG_INFO|log_facility, fmt, ##args); \
211
+								syslog(LOG_INFO|cfg_get(core, core_cfg, log_facility), \
212
+									fmt, ##args); \
198 213
 								break; \
199 214
 							case L_DBG: \
200
-								syslog(LOG_DEBUG|log_facility, fmt, ##args); \
215
+								syslog(LOG_DEBUG|cfg_get(core, core_cfg, log_facility), \
216
+									fmt, ##args); \
201 217
 								break; \
202 218
 						} \
203 219
 					} \
... ...
@@ -299,8 +299,6 @@ int dont_fork = 0;
299 299
 int dont_daemonize = 0;
300 300
 int log_stderr = 0;
301 301
 pid_t creator_pid = (pid_t) -1;
302
-/* log facility (see syslog(3)) */
303
-int log_facility = LOG_DAEMON;
304 302
 int config_check = 0;
305 303
 /* check if reply first via host==us */
306 304
 int check_via =  0;