charon: Don't use syslog() if not supported
authorMartin Willi <martin@revosec.ch>
Tue, 29 Oct 2013 09:46:30 +0000 (10:46 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 4 Jun 2014 13:53:03 +0000 (15:53 +0200)
configure.ac
src/libcharon/Makefile.am
src/libcharon/daemon.c

index 3848f8c..0dc5ac6 100644 (file)
@@ -568,7 +568,7 @@ AC_CHECK_FUNC(
 )
 
 AC_CHECK_FUNCS(prctl mallinfo getpass closefrom getpwnam_r getgrnam_r getpwuid_r)
-AC_CHECK_FUNCS(fmemopen funopen mmap memrchr)
+AC_CHECK_FUNCS(fmemopen funopen mmap memrchr syslog)
 
 AC_CHECK_HEADERS(sys/sockio.h glob.h net/if_tun.h linux/fib_rules.h)
 AC_CHECK_HEADERS(net/pfkeyv2.h netipsec/ipsec.h netinet6/ipsec.h linux/udp.h)
index 3e7a961..586d1dd 100644 (file)
@@ -5,7 +5,6 @@ bus/bus.c bus/bus.h \
 bus/listeners/listener.h \
 bus/listeners/logger.h \
 bus/listeners/file_logger.c bus/listeners/file_logger.h \
-bus/listeners/sys_logger.c bus/listeners/sys_logger.h \
 config/backend_manager.c config/backend_manager.h config/backend.h \
 config/child_cfg.c config/child_cfg.h \
 config/ike_cfg.c config/ike_cfg.h \
@@ -144,6 +143,12 @@ libcharon_la_LIBADD = \
   $(top_builddir)/src/libhydra/libhydra.la \
   -lm $(PTHREADLIB) $(DLLIB) $(SOCKLIB)
 
+if USE_WINDOWS
+else
+  libcharon_la_SOURCES += \
+    bus/listeners/sys_logger.c bus/listeners/sys_logger.h
+endif
+
 EXTRA_DIST = Android.mk
 
 # compile options
index 16babf0..a89995a 100644 (file)
 #include <stdio.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <syslog.h>
 #include <time.h>
 #include <errno.h>
 
+#ifdef HAVE_SYSLOG
+#include <syslog.h>
+#endif
+
 #include "daemon.h"
 
 #include <library.h>
@@ -179,6 +182,7 @@ static bool logger_entry_match(logger_entry_t *this, char *target, bool *file)
  */
 static void handle_syslog_identifier(private_daemon_t *this)
 {
+#ifdef HAVE_SYSLOG
        char *identifier;
 
        identifier = lib->settings->get_str(lib->settings, "%s.syslog.identifier",
@@ -198,6 +202,7 @@ static void handle_syslog_identifier(private_daemon_t *this)
                closelog();
                this->syslog_identifier = NULL;
        }
+#endif /* HAVE_SYSLOG */
 }
 
 /**
@@ -206,6 +211,7 @@ static void handle_syslog_identifier(private_daemon_t *this)
  */
 static int get_syslog_facility(char *facility)
 {
+#ifdef HAVE_SYSLOG
        if (streq(facility, "daemon"))
        {
                return LOG_DAEMON;
@@ -214,6 +220,7 @@ static int get_syslog_facility(char *facility)
        {
                return LOG_AUTHPRIV;
        }
+#endif /* HAVE_SYSLOG */
        return -1;
 }
 
@@ -237,10 +244,12 @@ static logger_entry_t *get_logger_entry(char *target, bool is_file_logger,
                {
                        entry->logger.file = file_logger_create(target);
                }
+#ifdef HAVE_SYSLOG
                else
                {
                        entry->logger.sys = sys_logger_create(get_syslog_facility(target));
                }
+#endif /* HAVE_SYSLOG */
        }
        else
        {
@@ -381,18 +390,27 @@ METHOD(daemon_t, load_loggers, void,
 
                for (group = 0; group < DBG_MAX; group++)
                {
-                       sys_logger->set_level(sys_logger, group, levels[group]);
+                       if (sys_logger)
+                       {
+                               sys_logger->set_level(sys_logger, group, levels[group]);
+                       }
                        if (to_stderr)
                        {
                                file_logger->set_level(file_logger, group, levels[group]);
                        }
                }
-               charon->bus->add_logger(charon->bus, &sys_logger->logger);
+               if (sys_logger)
+               {
+                       charon->bus->add_logger(charon->bus, &sys_logger->logger);
+               }
                charon->bus->add_logger(charon->bus, &file_logger->logger);
 
                sys_logger = add_sys_logger(this, "auth", current_loggers);
-               sys_logger->set_level(sys_logger, DBG_ANY, LEVEL_AUDIT);
-               charon->bus->add_logger(charon->bus, &sys_logger->logger);
+               if (sys_logger)
+               {
+                       sys_logger->set_level(sys_logger, DBG_ANY, LEVEL_AUDIT);
+                       charon->bus->add_logger(charon->bus, &sys_logger->logger);
+               }
        }
        /* unregister and destroy any unused remaining loggers */
        current_loggers->destroy_function(current_loggers,