>From b2370c2d44ed2d44ed9fc0b81ffc5ef5ea8e2e1c Mon Sep 17 00:00:00 2001 From: Jakub Hrozek Date: Thu, 5 Sep 2013 06:52:15 +0200 Subject: [PATCH 1/2] Add journald support --- Makefile.am | 6 ++++++ configure.ac | 6 ++++++ src/conf_macros.m4 | 20 ++++++++++++++++++++ src/external/systemd.m4 | 13 +++++++++++++ src/util/sss_log.c | 35 +++++++++++++++++++++++++++++++++++ 5 files changed, 80 insertions(+) diff --git a/Makefile.am b/Makefile.am index 5aba760375de59c4203300376e2d6fcd8e90c53f..67f5652f7d8373da21773ecc488960631f3a86bc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -279,6 +279,7 @@ AM_CPPFLAGS = \ $(LIBNL_CFLAGS) \ $(OPENLDAP_CFLAGS) \ $(GLIB2_CFLAGS) \ + $(JOURNALD_CFLAGS) \ -DLIBDIR=\"$(libdir)\" \ -DVARDIR=\"$(localstatedir)\" \ -DSHLIBEXT=\"$(SHLIBEXT)\" \ @@ -517,6 +518,10 @@ if HAVE_PTHREAD CLIENT_LIBS += -lpthread endif +if WITH_JOURNALD +SYSLOG_LIBS = $(JOURNALD_LIBS) +endif + ##################### # Utility libraries # ##################### @@ -525,6 +530,7 @@ libsss_debug_la_SOURCES = \ src/util/debug.c \ src/util/sss_log.c libsss_debug_la_LDFLAGS = \ + $(SYSLOG_LIBS) \ -avoid-version pkglib_LTLIBRARIES += libsss_child.la diff --git a/configure.ac b/configure.ac index c389bec4f2600568e73be4034d29ebcc44bb047f..d28d55f3b0eb35cc4ecc02ae9b1fafbcb9588dcf 100644 --- a/configure.ac +++ b/configure.ac @@ -125,6 +125,7 @@ WITH_SUDO_LIB_PATH WITH_AUTOFS WITH_SSH WITH_CRYPTO +WITH_SYSLOG m4_include([src/external/pkg.m4]) m4_include([src/external/libpopt.m4]) @@ -245,6 +246,11 @@ if test x$HAVE_SYSTEMD_UNIT != x; then AM_CHECK_SYSTEMD fi +dnl If journald was selected for logging, configure journald +if test x$syslog = xjournald; then + AM_CHECK_JOURNALD +fi + if test x$cryptolib = xnss; then AM_CHECK_NSS fi diff --git a/src/conf_macros.m4 b/src/conf_macros.m4 index b4db0b4a2b34e69734402f2f4a4c2ccadbf94fb8..1aecaea4d60140f9f99d6f6038a4f77205d2e1bd 100644 --- a/src/conf_macros.m4 +++ b/src/conf_macros.m4 @@ -152,6 +152,26 @@ AC_DEFUN([WITH_INITSCRIPT], AC_MSG_NOTICE([Will use init script type: $initscript]) ]) +AC_DEFUN([WITH_SYSLOG], + [ AC_ARG_WITH([syslog], + [AC_HELP_STRING([--with-syslog=SYSLOG_TYPE], + [Type of your system logger (syslog|journald). [syslog]] + ) + ], + [], + [with_syslog="syslog"] + ) + + if test x"$with_syslog" = xsyslog || \ + test x"$with_syslog" = xjournald; then + syslog=$with_syslog + else + AC_MSG_ERROR([Uknown syslog type, supported types are syslog and journald]) + fi + + AM_CONDITIONAL([WITH_JOURNALD], [test x"$syslog" = xjournald]) + ]) + AC_DEFUN([WITH_ENVIRONMENT_FILE], [ AC_ARG_WITH([environment_file], [AC_HELP_STRING([--with-environment-file=PATH], [Path to environment file [/etc/sysconfig/sssd]]) diff --git a/src/external/systemd.m4 b/src/external/systemd.m4 index 9afb65def6abb9bfd5b58402c12cf160612cff3b..dbced0d66aa19e064f998648675a5a9c080eaab8 100644 --- a/src/external/systemd.m4 +++ b/src/external/systemd.m4 @@ -6,7 +6,20 @@ AC_DEFUN([AM_CHECK_SYSTEMD], [AC_MSG_ERROR([Could not detect systemd presence])] ) ]) + AM_COND_IF([HAVE_SYSTEMD], [PKG_CHECK_MODULES([SYSTEMD_LOGIN], [libsystemd-login], [AC_DEFINE_UNQUOTED(HAVE_SYSTEMD_LOGIN, 1, [Build with libsystemdlogin support])], [AC_MSG_NOTICE([Build without libsystemd-login support])])]) + +dnl A macro to check presence of journald on the system +AC_DEFUN([AM_CHECK_JOURNALD], +[ + PKG_CHECK_MODULES(JOURNALD, + libsystemd-journal, + [AC_DEFINE_UNQUOTED([WITH_JOURNALD], 1, [journald is available])]) + dnl Some older versions of pkg-config might not set these automatically + dnl while setting CFLAGS and LIBS manually twice doesn't hurt. + AC_SUBST([JOURNALD_CFLAGS]) + AC_SUBST([JOURNALD_LIBS]) +]) diff --git a/src/util/sss_log.c b/src/util/sss_log.c index 45e883109a0a45a146b62dcedf43113147e78c28..6b78c9d4baa6ee9bc15d461ad8136c7bcfca579a 100644 --- a/src/util/sss_log.c +++ b/src/util/sss_log.c @@ -23,7 +23,12 @@ */ #include "util/util.h" + +#ifdef WITH_JOURNALD +#include +#else /* WITH_JOURNALD */ #include +#endif /* WITH_JOURNALD */ static int sss_to_syslog(int priority) { @@ -52,6 +57,34 @@ static int sss_to_syslog(int priority) } } +#ifdef WITH_JOURNALD + +void sss_log(int priority, const char *format, ...) +{ + va_list ap; + int syslog_priority; + int ret; + char *message; + + va_start(ap, format); + ret = vasprintf(&message, format, ap); + va_end(ap); + + if (ret == -1) { + /* ENOMEM */ + return; + } + + syslog_priority = sss_to_syslog(priority); + sd_journal_send("MESSAGE=%s", message, + "PRIORITY=%i", syslog_priority, + "SYSLOG_FACILITY=%i", LOG_FAC(LOG_DAEMON), + "SYSLOG_IDENTIFIER=%s", debug_prg_name, + NULL); +} + +#else /* WITH_JOURNALD */ + void sss_log(int priority, const char *format, ...) { va_list ap; @@ -67,3 +100,5 @@ void sss_log(int priority, const char *format, ...) closelog(); } + +#endif /* WITH_JOURNALD */ -- 1.8.3.1