diff --git a/Makefile.am b/Makefile.am index 3e8c3f3c48..2e043a020e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,10 @@ if WITH_JOURNALD extra_distcheck_flags += --with-syslog=journald endif +if WITH_STDERR_SYSLOG + extra_distcheck_flags += --with-syslog=stderr +endif + DISTCHECK_CONFIGURE_FLAGS = --with-ldb-lib-dir="$$dc_install_base"/lib/ldb \ $(extra_distcheck_flags) \ $(AUX_DISTCHECK_CONFIGURE_FLAGS) diff --git a/src/conf_macros.m4 b/src/conf_macros.m4 index ded342213e..145362ec14 100644 --- a/src/conf_macros.m4 +++ b/src/conf_macros.m4 @@ -144,7 +144,7 @@ AC_DEFUN([WITH_INITSCRIPT], AC_DEFUN([WITH_SYSLOG], [ AC_ARG_WITH([syslog], [AC_HELP_STRING([--with-syslog=SYSLOG_TYPE], - [Type of your system logger (syslog|journald). [syslog]] + [Type of your system logger (syslog|journald|stderr). [syslog]] ) ], [], @@ -152,13 +152,18 @@ AC_DEFUN([WITH_SYSLOG], ) if test x"$with_syslog" = xsyslog || \ - test x"$with_syslog" = xjournald; then + test x"$with_syslog" = xjournald || \ + test x"$with_syslog" = xstderr; then syslog=$with_syslog else - AC_MSG_ERROR([Unknown syslog type, supported types are syslog and journald]) + AC_MSG_ERROR([Unknown syslog type, supported types are syslog, journald and stderr]) fi AM_CONDITIONAL([WITH_JOURNALD], [test x"$syslog" = xjournald]) + AM_CONDITIONAL([WITH_STDERR_SYSLOG], [test x"$syslog" = xstderr]) + if test x"$with_syslog" = xstderr; then + AC_DEFINE_UNQUOTED([WITH_STDERR_SYSLOG], 1, [Send syslog to stderr]) + fi ]) AC_DEFUN([WITH_ENVIRONMENT_FILE], diff --git a/src/util/sss_log.c b/src/util/sss_log.c index 3c415d4ff9..983455e8fd 100644 --- a/src/util/sss_log.c +++ b/src/util/sss_log.c @@ -26,10 +26,15 @@ #ifdef WITH_JOURNALD #include -#else /* WITH_JOURNALD */ +#else +#ifdef WITH_STDERR_SYSLOG +#include +#else #include -#endif /* WITH_JOURNALD */ +#endif +#endif +#if !defined(WITH_STDERR_SYSLOG) static int sss_to_syslog(int priority) { switch(priority) { @@ -59,13 +64,19 @@ static int sss_to_syslog(int priority) static void sss_log_internal(int priority, int facility, const char *format, va_list ap); +#endif + void sss_log(int priority, const char *format, ...) { va_list ap; va_start(ap, format); +#if !defined(WITH_STDERR_SYSLOG) sss_log_internal(priority, LOG_DAEMON, format, ap); +#else + vfprintf(stderr, format, ap); +#endif va_end(ap); } @@ -74,7 +85,11 @@ void sss_log_ext(int priority, int facility, const char *format, ...) va_list ap; va_start(ap, format); +#if !defined(WITH_STDERR_SYSLOG) sss_log_internal(priority, facility, format, ap); +#else + vfprintf(stderr, format, ap); +#endif va_end(ap); } @@ -114,6 +129,7 @@ static void sss_log_internal(int priority, int facility, const char *format, } #else /* WITH_JOURNALD */ +#if !defined(WITH_STDERR_SYSLOG) static void sss_log_internal(int priority, int facility, const char *format, va_list ap) @@ -123,4 +139,5 @@ static void sss_log_internal(int priority, int facility, const char *format, vsyslog(facility|syslog_priority, format, ap); } +#endif /* !WITH_STDERR_SYSLOG */ #endif /* WITH_JOURNALD */