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 Feb 7, 2025
1 parent 7f1b7c9 commit af943cc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 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: 18 additions & 3 deletions src/util/sss_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

#include "util/util.h"

Check warning on line 25 in src/util/sss_log.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "util/util.h" not found.

#ifdef WITH_JOURNALD
#if defined(WITH_JOURNALD)
#include <systemd/sd-journal.h>

Check warning on line 28 in src/util/sss_log.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <systemd/sd-journal.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#else /* WITH_JOURNALD */
#elif defined(WITH_STDERR_SYSLOG)
#include <stdio.h>

Check warning on line 30 in src/util/sss_log.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <stdio.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#else
#include <syslog.h>

Check warning on line 32 in src/util/sss_log.c

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <syslog.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif /* WITH_JOURNALD */
#endif

#if !defined(WITH_STDERR_SYSLOG)
static int sss_to_syslog(int priority)
{
switch(priority) {
Expand Down Expand Up @@ -59,13 +62,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 +83,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 +127,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 +137,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 af943cc

Please sign in to comment.