Browse Source

-added support for fake LOG_NONE syslog facility that disables syslogging completely

Tomas Mandys 19 years ago
parent
commit
63dc566ef5
3 changed files with 12 additions and 7 deletions
  1. 2 1
      daemonize.c
  2. 4 2
      dprint.c
  3. 6 4
      dprint.h

+ 2 - 1
daemonize.c

@@ -198,7 +198,8 @@ int daemonize(char*  name)
 	}
 	
 	if (log_stderr==0)
-		openlog(name, LOG_PID|LOG_CONS, log_facility);
+		if (log_facility!=LOG_NONE)
+			openlog(name, LOG_PID|LOG_CONS, log_facility);
 		/* LOG_CONS, LOG_PERRROR ? */
 
 	return  0;

+ 4 - 2
dprint.c

@@ -45,15 +45,17 @@ static char* str_fac[]={"LOG_AUTH","LOG_CRON","LOG_DAEMON",
 #ifndef __OS_solaris
 					"LOG_AUTHPRIV","LOG_FTP","LOG_SYSLOG",
 #endif
+					"LOG_NONE",
 					0};
 static int int_fac[]={LOG_AUTH ,  LOG_CRON , LOG_DAEMON ,
 					LOG_KERN , LOG_LOCAL0 , LOG_LOCAL1 ,
 					LOG_LOCAL2 , LOG_LOCAL3 , LOG_LOCAL4 , LOG_LOCAL5 ,
 					LOG_LOCAL6 , LOG_LOCAL7 , LOG_LPR , LOG_MAIL ,
-					LOG_NEWS , LOG_USER , LOG_UUCP
+					LOG_NEWS , LOG_USER , LOG_UUCP,
 #ifndef __OS_solaris
-					,LOG_AUTHPRIV,LOG_FTP,LOG_SYSLOG
+					LOG_AUTHPRIV,LOG_FTP,LOG_SYSLOG,
 #endif
+					LOG_NONE
 					};
 
 

+ 6 - 4
dprint.h

@@ -32,6 +32,8 @@
 
 #include <syslog.h>
 
+/* define non existing facility to disable logging */
+#define LOG_NONE (~LOG_FACMASK)
 
 #define L_ALERT -3
 #define L_CRIT  -2
@@ -91,7 +93,7 @@ int str2facility(char *s);
 					if (log_stderr){ \
 						dprint (__VA_ARGS__); \
 					}else{ \
-						syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
+						if (log_facility!=LOG_NONE) syslog(DPRINT_LEV|log_facility,  __VA_ARGS__); \
 					}\
 				} \
 			}while(0)
@@ -102,7 +104,7 @@ int str2facility(char *s);
 					if (log_stderr){ \
 						dprint (fmt, ## args); \
 					}else{ \
-						syslog(DPRINT_LEV|log_facility, fmt, ## args); \
+						if (log_facility!=LOG_NONE) syslog(DPRINT_LEV|log_facility, fmt, ## args); \
 					}\
 				} \
 			}while(0)
@@ -126,7 +128,7 @@ int str2facility(char *s);
 			do { \
 				if (debug>=(lev)){ \
 					if (log_stderr) dprint (__VA_ARGS__); \
-					else { \
+					else if (log_facility!=LOG_NONE) { \
 						switch(lev){ \
 							case L_CRIT: \
 								syslog(LOG_CRIT|log_facility, __VA_ARGS__); \
@@ -158,7 +160,7 @@ int str2facility(char *s);
 			do { \
 				if (debug>=(lev)){ \
 					if (log_stderr) dprint (fmt, ## args); \
-					else { \
+					else if (log_facility!=LOG_NONE) { \
 						switch(lev){ \
 							case L_CRIT: \
 								syslog(LOG_CRIT|log_facility, fmt, ##args); \