Parcourir la source

log_facility config parameter is declared in the cfg framework

Miklos Tirpak il y a 17 ans
Parent
commit
0d09b88d31
7 fichiers modifiés avec 56 ajouts et 22 suppressions
  1. 1 1
      cfg.y
  2. 5 1
      cfg_core.c
  3. 1 0
      cfg_core.h
  4. 2 1
      daemonize.c
  5. 14 0
      dprint.c
  6. 33 17
      dprint.h
  7. 0 2
      main.c

+ 1 - 1
cfg.y

@@ -603,7 +603,7 @@ assign_stm:
 		if ( (i_tmp=str2facility($3))==-1)
 			yyerror("bad facility (see syslog(3) man page)");
 		if (!config_check)
-			log_facility=i_tmp;
+			default_core_cfg.log_facility=i_tmp;
 	}
 	| LOGFACILITY EQUAL error { yyerror("ID expected"); }
 	| DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }

+ 5 - 1
cfg_core.c

@@ -43,6 +43,7 @@
 
 struct cfg_group_core default_core_cfg = {
 	L_DEFAULT, /*  print only msg. < L_WARN */
+	LOG_DAEMON,	/* log_facility -- see syslog(3) */
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	0, /* dst blacklist is disabled by default */
@@ -82,7 +83,10 @@ struct cfg_group_core default_core_cfg = {
 void	*core_cfg = &default_core_cfg;
 
 cfg_def_t core_cfg_def[] = {
-	{"debug",	CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0, "debug level"},
+	{"debug",		CFG_VAR_INT|CFG_ATOMIC,	0, 0, 0, 0,
+		"debug level"},
+	{"log_facility",	CFG_VAR_INT|CFG_INPUT_STRING,	0, 0, log_facility_fixup, 0,
+		"syslog facility, see \"man 3 syslog\""},
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	{"use_dst_blacklist",	CFG_VAR_INT,	0, 1, use_dst_blacklist_fixup, 0,

+ 1 - 0
cfg_core.h

@@ -46,6 +46,7 @@ extern void	*core_cfg;
 
 struct cfg_group_core {
 	int	debug;
+	int	log_facility;
 #ifdef USE_DST_BLACKLIST
 	/* blacklist */
 	int	use_dst_blacklist; /* 1 if blacklist is enabled */

+ 2 - 1
daemonize.c

@@ -71,6 +71,7 @@
 #include "globals.h"
 #include "dprint.h"
 #include "signals.h"
+#include "cfg/cfg.h"
 
 
 #define MAX_FD 32 /* maximum number of inherited open file descriptors,
@@ -209,7 +210,7 @@ int daemonize(char*  name)
 	}
 	
 	if (log_stderr==0)
-		openlog(name, LOG_PID|LOG_CONS, log_facility);
+		openlog(name, LOG_PID|LOG_CONS, cfg_get(core, core_cfg, log_facility));
 		/* LOG_CONS, LOG_PERRROR ? */
 
 	return  0;

+ 14 - 0
dprint.c

@@ -82,3 +82,17 @@ int str2facility(char *s)
 	}
 	return -1;
 }
+
+/* fixup function for log_facility cfg parameter */
+int log_facility_fixup(void *handle, str *name, void **val)
+{
+	int	i;
+
+	if ((i = str2facility((char *)*val)) == -1) {
+		LOG(L_ERR, "log_facility_fixup: invalid log facility: %s\n",
+			(char *)*val);
+		return -1;
+	}
+	*val = (void *)(long)i;
+	return 0;
+}

+ 33 - 17
dprint.h

@@ -46,7 +46,6 @@
 /* vars:*/
 
 extern int log_stderr;
-extern int log_facility;
 extern volatile int dprint_crit; /* protection against "simultaneous"
 									printing from signal handlers */
 
@@ -68,6 +67,7 @@ extern volatile int dprint_crit; /* protection against "simultaneous"
 void dprint (char* format, ...);
 
 int str2facility(char *s);
+int log_facility_fixup(void *handle, str *name, void **val);
 
 /* C >= 99 has __func__, older gcc versions have __FUNCTION__ */
 #if __STDC_VERSION__ < 199901L
@@ -103,7 +103,8 @@ int str2facility(char *s);
 					if (log_stderr){ \
 						dprint (__VA_ARGS__); \
 					}else{ \
-						syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
+						syslog(DPRINT_LEV|cfg_get(core, core_cfg, log_facility), \
+							__VA_ARGS__); \
 					}\
 					DPRINT_CRIT_EXIT; \
 				} \
@@ -116,7 +117,8 @@ int str2facility(char *s);
 					if (log_stderr){ \
 						dprint (fmt, ## args); \
 					}else{ \
-						syslog(DPRINT_LEV|log_facility, fmt, ## args); \
+						syslog(DPRINT_LEV|cfg_get(core, core_cfg, log_facility), \
+							fmt, ## args); \
 					}\
 					DPRINT_CRIT_EXIT; \
 				} \
@@ -145,25 +147,32 @@ int str2facility(char *s);
 					else { \
 						switch(lev){ \
 							case L_CRIT: \
-								syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
+								syslog(LOG_CRIT|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__); \
 								break; \
 							case L_ALERT: \
-								syslog(LOG_ALERT|log_facility, __VA_ARGS__); \
+								syslog(LOG_ALERT|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__); \
 								break; \
 							case L_ERR: \
-								syslog(LOG_ERR|log_facility, __VA_ARGS__); \
+								syslog(LOG_ERR|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__); \
 								break; \
 							case L_WARN: \
-								syslog(LOG_WARNING|log_facility, __VA_ARGS__);\
+								syslog(LOG_WARNING|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__);\
 								break; \
 							case L_NOTICE: \
-								syslog(LOG_NOTICE|log_facility, __VA_ARGS__); \
+								syslog(LOG_NOTICE|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__); \
 								break; \
 							case L_INFO: \
-								syslog(LOG_INFO|log_facility, __VA_ARGS__); \
+								syslog(LOG_INFO|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__); \
 								break; \
 							case L_DBG: \
-								syslog(LOG_DEBUG|log_facility, __VA_ARGS__); \
+								syslog(LOG_DEBUG|cfg_get(core, core_cfg, log_facility), \
+									__VA_ARGS__); \
 								break; \
 						} \
 					} \
@@ -179,25 +188,32 @@ int str2facility(char *s);
 					else { \
 						switch(lev){ \
 							case L_CRIT: \
-								syslog(LOG_CRIT|log_facility, fmt, ##args); \
+								syslog(LOG_CRIT|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args); \
 								break; \
 							case L_ALERT: \
-								syslog(LOG_ALERT|log_facility, fmt, ##args); \
+								syslog(LOG_ALERT|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args); \
 								break; \
 							case L_ERR: \
-								syslog(LOG_ERR|log_facility, fmt, ##args); \
+								syslog(LOG_ERR|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args); \
 								break; \
 							case L_WARN: \
-								syslog(LOG_WARNING|log_facility, fmt, ##args);\
+								syslog(LOG_WARNING|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args);\
 								break; \
 							case L_NOTICE: \
-								syslog(LOG_NOTICE|log_facility, fmt, ##args); \
+								syslog(LOG_NOTICE|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args); \
 								break; \
 							case L_INFO: \
-								syslog(LOG_INFO|log_facility, fmt, ##args); \
+								syslog(LOG_INFO|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args); \
 								break; \
 							case L_DBG: \
-								syslog(LOG_DEBUG|log_facility, fmt, ##args); \
+								syslog(LOG_DEBUG|cfg_get(core, core_cfg, log_facility), \
+									fmt, ##args); \
 								break; \
 						} \
 					} \

+ 0 - 2
main.c

@@ -299,8 +299,6 @@ int dont_fork = 0;
 int dont_daemonize = 0;
 int log_stderr = 0;
 pid_t creator_pid = (pid_t) -1;
-/* log facility (see syslog(3)) */
-int log_facility = LOG_DAEMON;
 int config_check = 0;
 /* check if reply first via host==us */
 int check_via =  0;