log_facility config parameter is declared in the cfg framework
authorMiklos Tirpak <miklos@iptel.org>
Fri, 29 Feb 2008 10:04:49 +0000 (10:04 +0000)
committerMiklos Tirpak <miklos@iptel.org>
Fri, 29 Feb 2008 10:04:49 +0000 (10:04 +0000)
cfg.y
cfg_core.c
cfg_core.h
daemonize.c
dprint.c
dprint.h
main.c

diff --git a/cfg.y b/cfg.y
index 53293d1..5d7b33a 100644 (file)
--- a/cfg.y
+++ b/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; }
index cb066d9..acb9ccc 100644 (file)
@@ -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,
index d8cbb1c..3d7adb7 100644 (file)
@@ -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 */
index 1890568..cb8c854 100644 (file)
@@ -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;
index 29a970e..f56d3ec 100644 (file)
--- a/dprint.c
+++ b/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;
+}
index 2c6575d..9535adc 100644 (file)
--- a/dprint.h
+++ b/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; \
                                                } \
                                        } \
diff --git a/main.c b/main.c
index 8ad29ad..3b03717 100644 (file)
--- a/main.c
+++ b/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;