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 11, 2025
1 parent fdf0b50 commit 13ac336
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 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
28 changes: 22 additions & 6 deletions src/util/sss_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@

#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.
#define LOG_DAEMON 0
#else
#include <syslog.h>

Check warning on line 33 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 All @@ -56,10 +60,12 @@ static int sss_to_syslog(int priority)
return LOG_EMERG;
}
}
#endif

static void sss_log_internal(int priority, int facility, const char *format,
va_list ap);


void sss_log(int priority, const char *format, ...)
{
va_list ap;
Expand All @@ -80,7 +86,7 @@ void sss_log_ext(int priority, int facility, const char *format, ...)



#ifdef WITH_JOURNALD
#if defined(WITH_JOURNALD)

static void sss_log_internal(int priority, int facility, const char *format,
va_list ap)
Expand Down Expand Up @@ -113,7 +119,17 @@ static void sss_log_internal(int priority, int facility, const char *format,
free(message);
}

#else /* WITH_JOURNALD */
#elif defined(WITH_STDERR_SYSLOG)

static void sss_log_internal(int, int, const char *format, va_list ap)
{
fprintf(stderr, "%s: ", debug_prg_name);
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
fflush(stderr);
}

#else /* SYSLOG */

static void sss_log_internal(int priority, int facility, const char *format,
va_list ap)
Expand All @@ -123,4 +139,4 @@ static void sss_log_internal(int priority, int facility, const char *format,
vsyslog(facility|syslog_priority, format, ap);
}

#endif /* WITH_JOURNALD */
#endif

0 comments on commit 13ac336

Please sign in to comment.