Skip to content

Commit

Permalink
BUILD: introduce "--with-syslog=stderr" option
Browse files Browse the repository at this point in the history
to be used in containers-like environments where
no system wide logger is available.
  • Loading branch information
alexey-tikhonov committed Oct 25, 2024
1 parent 7cff73c commit 1e7ef28
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions src/conf_macros.m4
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,26 @@ 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]]
)
],
[],
[with_syslog="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],
Expand Down
21 changes: 19 additions & 2 deletions src/util/sss_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,15 @@

#ifdef WITH_JOURNALD
#include <systemd/sd-journal.h>
#else /* WITH_JOURNALD */
#else
#ifdef WITH_STDERR_SYSLOG
#include <stdio.h>
#else
#include <syslog.h>
#endif /* WITH_JOURNALD */
#endif
#endif

#if !defined(WITH_STDERR_SYSLOG)
static int sss_to_syslog(int priority)
{
switch(priority) {
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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)
Expand All @@ -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 */

0 comments on commit 1e7ef28

Please sign in to comment.