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 82
 void	*core_cfg = &default_core_cfg;
83 83
 
84 84
 cfg_def_t core_cfg_def[] = {
85
-	{"debug",	CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0, "debug level"},
85
+	{"debug",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
86
+		"debug level"},
87
+	{"log_facility",	CFG_VAR_INT|CFG_INPUT_STRING,	0, 0, log_facility_fixup, 0,
88
+		"syslog facility, see \"man 3 syslog\""},
86 89
 #ifdef USE_DST_BLACKLIST
87 90
 	/* blacklist */
88 91
 	{"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 209
 	}
210 210
 	
211 211
 	if (log_stderr==0)
212
-		openlog(name, LOG_PID|LOG_CONS, log_facility);
212
+		openlog(name, LOG_PID|LOG_CONS, cfg_get(core, core_cfg, log_facility));
213 213
 		/* LOG_CONS, LOG_PERRROR ? */
214 214
 
215 215
 	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 68
 void dprint (char* format, ...);
69 69
 
70 70
 int str2facility(char *s);
71
+int log_facility_fixup(void *handle, str *name, void **val);
71 72
 
72 73
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
73 74
 #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 116
 					if (log_stderr){ \
117 117
 						dprint (fmt, ## args); \
118 118
 					}else{ \
119
-						syslog(DPRINT_LEV|log_facility, fmt, ## args); \
119
+						syslog(DPRINT_LEV|cfg_get(core, core_cfg, log_facility), \
120
+							fmt, ## args); \
120 121
 					}\
121 122
 					DPRINT_CRIT_EXIT; \
122 123
 				} \
... ...
@@ -145,25 +147,32 @@ int str2facility(char *s);
145 145
 					else { \
146 146
 						switch(lev){ \
147 147
 							case L_CRIT: \
148
-								syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
148
+								syslog(LOG_CRIT|cfg_get(core, core_cfg, log_facility), \
149
+									__VA_ARGS__); \
149 150
 								break; \
150 151
 							case L_ALERT: \
151
-								syslog(LOG_ALERT|log_facility, __VA_ARGS__); \
152
+								syslog(LOG_ALERT|cfg_get(core, core_cfg, log_facility), \
153
+									__VA_ARGS__); \
152 154
 								break; \
153 155
 							case L_ERR: \
154
-								syslog(LOG_ERR|log_facility, __VA_ARGS__); \
156
+								syslog(LOG_ERR|cfg_get(core, core_cfg, log_facility), \
157
+									__VA_ARGS__); \
155 158
 								break; \
156 159
 							case L_WARN: \
157
-								syslog(LOG_WARNING|log_facility, __VA_ARGS__);\
160
+								syslog(LOG_WARNING|cfg_get(core, core_cfg, log_facility), \
161
+									__VA_ARGS__);\
158 162
 								break; \
159 163
 							case L_NOTICE: \
160
-								syslog(LOG_NOTICE|log_facility, __VA_ARGS__); \
164
+								syslog(LOG_NOTICE|cfg_get(core, core_cfg, log_facility), \
165
+									__VA_ARGS__); \
161 166
 								break; \
162 167
 							case L_INFO: \
163
-								syslog(LOG_INFO|log_facility, __VA_ARGS__); \
168
+								syslog(LOG_INFO|cfg_get(core, core_cfg, log_facility), \
169
+									__VA_ARGS__); \
164 170
 								break; \
165 171
 							case L_DBG: \
166
-								syslog(LOG_DEBUG|log_facility, __VA_ARGS__); \
172
+								syslog(LOG_DEBUG|cfg_get(core, core_cfg, log_facility), \
173
+									__VA_ARGS__); \
167 174
 								break; \
168 175
 						} \
169 176
 					} \
... ...
@@ -179,25 +188,32 @@ int str2facility(char *s);
179 179
 					else { \
180 180
 						switch(lev){ \
181 181
 							case L_CRIT: \
182
-								syslog(LOG_CRIT|log_facility, fmt, ##args); \
182
+								syslog(LOG_CRIT|cfg_get(core, core_cfg, log_facility), \
183
+									fmt, ##args); \
183 184
 								break; \
184 185
 							case L_ALERT: \
185
-								syslog(LOG_ALERT|log_facility, fmt, ##args); \
186
+								syslog(LOG_ALERT|cfg_get(core, core_cfg, log_facility), \
187
+									fmt, ##args); \
186 188
 								break; \
187 189
 							case L_ERR: \
188
-								syslog(LOG_ERR|log_facility, fmt, ##args); \
190
+								syslog(LOG_ERR|cfg_get(core, core_cfg, log_facility), \
191
+									fmt, ##args); \
189 192
 								break; \
190 193
 							case L_WARN: \
191
-								syslog(LOG_WARNING|log_facility, fmt, ##args);\
194
+								syslog(LOG_WARNING|cfg_get(core, core_cfg, log_facility), \
195
+									fmt, ##args);\
192 196
 								break; \
193 197
 							case L_NOTICE: \
194
-								syslog(LOG_NOTICE|log_facility, fmt, ##args); \
198
+								syslog(LOG_NOTICE|cfg_get(core, core_cfg, log_facility), \
199
+									fmt, ##args); \
195 200
 								break; \
196 201
 							case L_INFO: \
197
-								syslog(LOG_INFO|log_facility, fmt, ##args); \
202
+								syslog(LOG_INFO|cfg_get(core, core_cfg, log_facility), \
203
+									fmt, ##args); \
198 204
 								break; \
199 205
 							case L_DBG: \
200
-								syslog(LOG_DEBUG|log_facility, fmt, ##args); \
206
+								syslog(LOG_DEBUG|cfg_get(core, core_cfg, log_facility), \
207
+									fmt, ##args); \
201 208
 								break; \
202 209
 						} \
203 210
 					} \
... ...
@@ -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;