From 9e6cb3cd54cd54c07fa383f7ee5fbd6cecb743ce Mon Sep 17 00:00:00 2001
From: Leif Johansson <leifj@sunet.se>
Date: Tue, 4 Sep 2012 15:37:28 +0200
Subject: [PATCH] - disable debugging by default - use syslog instead of stderr
 unless DEBUG_OUTPUT is 1

---
 config.h                    | 2 ++
 gck-rpc-daemon-standalone.c | 4 ++++
 gck-rpc-dispatch.c          | 8 +++++++-
 3 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/config.h b/config.h
index 35be6f9..671c0eb 100644
--- a/config.h
+++ b/config.h
@@ -1,6 +1,8 @@
 #ifndef CONFIG_H
 # define CONFIG_H
 
+# define DEBUG_OUTPUT 0 // change to 1 to enable debugging
+
 #ifdef __MINGW32__
 
 # include <stdint.h>
diff --git a/gck-rpc-daemon-standalone.c b/gck-rpc-daemon-standalone.c
index 5f30514..88c5c39 100644
--- a/gck-rpc-daemon-standalone.c
+++ b/gck-rpc-daemon-standalone.c
@@ -36,6 +36,8 @@
 #include <dlfcn.h>
 #include <pthread.h>
 
+#include <syslog.h>
+
 #ifdef __MINGW32__
 # include <winsock2.h>
 #endif
@@ -76,6 +78,8 @@ int main(int argc, char *argv[])
 	if (argc != 2 && argc != 3)
 		usage();
 
+        openlog("pkcs11-proxy",LOG_CONS|LOG_PID,LOG_DAEMON);
+
 	/* Load the library */
 	module = dlopen(argv[1], RTLD_NOW);
 	if (!module) {
diff --git a/gck-rpc-dispatch.c b/gck-rpc-dispatch.c
index 6b0687d..4f31e95 100644
--- a/gck-rpc-dispatch.c
+++ b/gck-rpc-dispatch.c
@@ -48,6 +48,7 @@
 #include <unistd.h>
 #include <errno.h>
 #include <stdio.h>
+#include <syslog.h>
 
 /* Where we dispatch the calls to */
 static CK_FUNCTION_LIST_PTR pkcs11_module = NULL;
@@ -83,8 +84,9 @@ static pthread_mutex_t pkcs11_dispatchers_mutex = PTHREAD_MUTEX_INITIALIZER;
 /* -----------------------------------------------------------------------------
  * LOGGING and DEBUGGING
  */
-#undef DEBUG_OUTPUT
+#ifndef DEBUG_OUTPUT
 #define DEBUG_OUTPUT 1
+#endif
 #if DEBUG_OUTPUT
 #define debug(x) gck_rpc_debug x
 #else
@@ -101,7 +103,11 @@ void gck_rpc_log(const char *msg, ...)
 	va_list ap;
 
 	va_start(ap, msg);
+#if DEBUG_OUTPUT
 	vfprintf(stderr, msg, ap);
+#else
+        vsyslog(LOG_INFO,msg,ap);        
+#endif
 	printf("\n");
 	va_end(ap);
 }
-- 
GitLab