1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-05 12:22:11 +03:00

debug: Add systemd backend

Signed-off-by: Christof Schmitt <cs@samba.org>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Christof Schmitt
2015-03-20 14:36:58 -07:00
parent 409b5433d2
commit 4aaf270ea8
4 changed files with 36 additions and 1 deletions

View File

@ -29,6 +29,7 @@
<itemizedlist> <itemizedlist>
<listitem><para><parameter moreinfo="none">syslog</parameter></para></listitem> <listitem><para><parameter moreinfo="none">syslog</parameter></para></listitem>
<listitem><para><parameter moreinfo="none">file</parameter></para></listitem> <listitem><para><parameter moreinfo="none">file</parameter></para></listitem>
<listitem><para><parameter moreinfo="none">systemd</parameter></para></listitem>
</itemizedlist> </itemizedlist>
</description> </description>

View File

@ -102,7 +102,7 @@ static struct {
.fd = 2 /* stderr by default */ .fd = 2 /* stderr by default */
}; };
#ifdef WITH_SYSLOG #if defined(WITH_SYSLOG) || defined(HAVE_SYSTEMD_JOURNAL)
static int debug_level_to_priority(int level) static int debug_level_to_priority(int level)
{ {
/* /*
@ -174,6 +174,18 @@ static void debug_syslog_log(int msg_level,
} }
#endif /* WITH_SYSLOG */ #endif /* WITH_SYSLOG */
#ifdef HAVE_SYSTEMD_JOURNAL
#include <systemd/sd-journal.h>
static void debug_systemd_log(int msg_level,
const char *msg, const char *msg_no_nl)
{
sd_journal_send("MESSAGE=%s", msg_no_nl,
"PRIORITY=%d", debug_level_to_priority(msg_level),
"LEVEL=%d", msg_level,
NULL);
}
#endif
static struct debug_backend { static struct debug_backend {
const char *name; const char *name;
int log_level; int log_level;
@ -192,6 +204,13 @@ static struct debug_backend {
.log = debug_syslog_log, .log = debug_syslog_log,
}, },
#endif #endif
#ifdef HAVE_SYSTEMD_JOURNAL
{
.name = "systemd",
.log = debug_systemd_log,
},
#endif
}; };
static struct debug_backend *debug_find_backend(const char *name) static struct debug_backend *debug_find_backend(const char *name)

View File

@ -31,6 +31,7 @@ bld.SAMBA_SUBSYSTEM('close-low-fd',
bld.SAMBA_LIBRARY('samba-debug', bld.SAMBA_LIBRARY('samba-debug',
source='debug.c', source='debug.c',
deps='replace time-basic close-low-fd talloc socket-blocking', deps='replace time-basic close-low-fd talloc socket-blocking',
public_deps='systemd-journal',
local_include=False, local_include=False,
private_library=True) private_library=True)

View File

@ -113,3 +113,17 @@ if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_DAEMON_H') and
else: else:
conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY') conf.SET_TARGET_TYPE('systemd-daemon', 'EMPTY')
conf.undefine('HAVE_SYSTEMD') conf.undefine('HAVE_SYSTEMD')
if Options.options.enable_systemd != False:
conf.check_cfg(package='libsystemd-journal', args='--cflags --libs',
msg='Checking for libsystemd-journal',
uselib_store="SYSTEMD-JOURNAL")
conf.CHECK_HEADERS('systemd/sd-journal.h', lib='systemd-journal')
conf.CHECK_LIB('systemd-journal', shlib=True)
if (conf.CONFIG_SET('HAVE_SYSTEMD_SD_JOURNAL_H') and
conf.CONFIG_SET('HAVE_LIBSYSTEMD_JOURNAL')):
conf.DEFINE('HAVE_SYSTEMD_JOURNAL', '1')
else:
conf.SET_TARGET_TYPE('systemd-journal', 'EMPTY')
conf.undefine('HAVE_SYSTEMD_JOURNAL')