Can disable syslog logging on tests.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 5 Oct 2008 13:40:21 +0000 (15:40 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Sun, 5 Oct 2008 13:40:21 +0000 (15:40 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
common/common.c
common/common.h
postlicyd/tst-filters.c

index 3d2862f..e9e4f2e 100644 (file)
@@ -46,6 +46,7 @@ sig_atomic_t sighup  = false;
 
 bool daemon_process  = true;
 int  log_level       = LOG_INFO;
+bool log_syslog      = false;
 
 static FILE *pidfile = NULL;
 
index 03d2fbb..30ce1d8 100644 (file)
@@ -72,7 +72,12 @@ typedef void (*exitcall_t)(void);
 
 #define __log(Level, Fmt, ...)                                    \
     if (log_level >= Level) {                                     \
-        syslog(Level, Fmt, ##__VA_ARGS__);                        \
+        if (log_syslog) {                                         \
+            syslog(Level, Fmt, ##__VA_ARGS__);                    \
+        } else {                                                  \
+            fprintf(stderr, "[%d] " Fmt "\n",                     \
+                    Level, ##__VA_ARGS__);                        \
+        }                                                         \
     }
 
 #define debug(Fmt, ...)  __log(LOG_DEBUG,   Fmt, ##__VA_ARGS__)
@@ -90,6 +95,7 @@ typedef void (*exitcall_t)(void);
 extern sig_atomic_t sigint;
 extern sig_atomic_t sighup;
 extern int          log_level;
+extern bool         log_syslog;
 
 void common_sighandler(int sig);
 
@@ -108,16 +114,23 @@ int pidfile_refresh(void);
 int common_setup(const char* pidfile, bool unsafe, const char* runas_user,
                  const char* runas_group, bool daemonize);
 
+static inline void common_startup(void)
+{
+    signal(SIGPIPE, SIG_IGN);
+    signal(SIGINT,  &common_sighandler);
+    signal(SIGTERM, &common_sighandler);
+    signal(SIGHUP,  &common_sighandler);
+    signal(SIGSEGV, &common_sighandler);
+    info("starting");
+}
+
+
 #define DECLARE_MAIN                                              \
     static int main_initialize(void)                              \
     {                                                             \
+        log_syslog = true;                                        \
         openlog(DAEMON_NAME, LOG_PID, LOG_MAIL);                  \
-        signal(SIGPIPE, SIG_IGN);                                 \
-        signal(SIGINT,  &common_sighandler);                      \
-        signal(SIGTERM, &common_sighandler);                      \
-        signal(SIGHUP,  &common_sighandler);                      \
-        signal(SIGSEGV, &common_sighandler);                      \
-        info("starting...");                                      \
+        common_startup();                                         \
         return 0;                                                 \
     }                                                             \
                                                                   \
index f391fc8..9de410c 100644 (file)
 #include "file.h"
 #include <dirent.h>
 
-#define DAEMON_NAME "tst-filters"
-
-DECLARE_MAIN
-
 static char *read_query(const char *basepath, const char *filename,
                         char *buff, char **end, query_t *q)
 {
@@ -189,6 +185,7 @@ int main(int argc, char *argv[])
     char path[FILENAME_MAX];
     char *p;
 
+    common_startup();
     p = strrchr(argv[0], '/');
     if (p == NULL) {
         p = argv[0];