Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUILD: introduce "--with-syslog=stderr" option #7827

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -22,14 +22,18 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#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 @@
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 @@



#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 @@
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 @@
vsyslog(facility|syslog_priority, format, ap);
}

#endif /* WITH_JOURNALD */
#endif
Loading