summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2013-09-05 06:52:15 +0200
committerJakub Hrozek <jhrozek@redhat.com>2013-09-18 18:56:40 +0200
commit77c0d1f6074059dafd2293f9c42ea0f9d60f8aad (patch)
tree4a6c5fcc27adb75a0dd84464fbf1ab0ffc183c1c /src
parent11a044514e3799c4e685cf98ed5c058aa02b5fdb (diff)
downloadsssd-77c0d1f6074059dafd2293f9c42ea0f9d60f8aad.tar.gz
sssd-77c0d1f6074059dafd2293f9c42ea0f9d60f8aad.tar.bz2
sssd-77c0d1f6074059dafd2293f9c42ea0f9d60f8aad.zip
Add journald support
Diffstat (limited to 'src')
-rw-r--r--src/conf_macros.m420
-rw-r--r--src/external/systemd.m413
-rw-r--r--src/util/sss_log.c35
3 files changed, 68 insertions, 0 deletions
diff --git a/src/conf_macros.m4 b/src/conf_macros.m4
index b4db0b4a..1aecaea4 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 9afb65de..dbced0d6 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 45e88310..6b78c9d4 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 <systemd/sd-journal.h>
+#else /* WITH_JOURNALD */
#include <syslog.h>
+#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 */