From 4b4d19e3aa1da061fed35edb979e1ca2a29fb7ed Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 3 Nov 2016 12:10:45 +0100 Subject: [PATCH] dmeventd: separate dm and dmeventd logging Ensure different logging function for dmeventd.c logging and dm and lvm library. We can recognize we want to show every log_info() and log_notice() message from dmeventd.c code while not exposing those from libdm/libdevmapper-event Also switch to use log with errno - it's not changing anything and doesn't bring any more features yet to dmeventd logging but we just properly pass dm_errno_or_class properly through the whole code stack for possible future use (i.e. support of class logging for dmeventd). --- WHATS_NEW_DM | 1 + daemons/dmeventd/dmeventd.c | 25 ++++++++++++++++---- daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 2 +- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM index 73a517177..d2d44acf4 100644 --- a/WHATS_NEW_DM +++ b/WHATS_NEW_DM @@ -1,5 +1,6 @@ Version 1.02.136 - ====================================== + Make log messages from dm and lvm library differnt from dmeventd. Notice and Info messages are again logged from dmeventd and its plugins. Dmeventd now also respects DM_ABORT_ON_INTERNAL_ERRORS as libdm based tool. Report as non default dm logging also when logging with errno was changed. diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index 6024e5604..58922ac84 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -99,13 +99,28 @@ static time_t _idle_since = 0; static char **_initial_registrations = 0; /* FIXME Make configurable at runtime */ -__attribute__((format(printf, 4, 5))) -static void _dmeventd_log(int level, const char *file, int line, - const char *format, ...) + +/* All libdm messages */ +__attribute__((format(printf, 5, 6))) +static void _libdm_log(int level, const char *file, int line, + int dm_errno_or_class, const char *format, ...) { va_list ap; va_start(ap, format); - dm_event_log("dm", level, file, line, 0, format, ap); + dm_event_log("#dm", level, file, line, dm_errno_or_class, format, ap); + va_end(ap); +} + +/* All dmeventd messages */ +#undef LOG_MESG +#define LOG_MESG(l, f, ln, e, x...) _dmeventd_log(l, f, ln, e, ## x) +__attribute__((format(printf, 5, 6))) +static void _dmeventd_log(int level, const char *file, int line, + int dm_errno_or_class, const char *format, ...) +{ + va_list ap; + va_start(ap, format); + dm_event_log("dmeventd", level, file, line, dm_errno_or_class, format, ap); va_end(ap); } @@ -2191,7 +2206,7 @@ int main(int argc, char *argv[]) openlog("dmeventd", LOG_PID, LOG_DAEMON); dm_event_log_set(_debug_level, _use_syslog); - dm_log_init(_dmeventd_log); + dm_log_with_errno_init(_libdm_log); (void) dm_prepare_selinux_context(DMEVENTD_PIDFILE, S_IFREG); if (dm_create_lockfile(DMEVENTD_PIDFILE) == 0) diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c index f36feb44b..0cca98f8e 100644 --- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c +++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c @@ -32,7 +32,7 @@ static int _register_count = 0; static struct dm_pool *_mem_pool = NULL; static void *_lvm_handle = NULL; -DM_EVENT_LOG_FN("lvm") +DM_EVENT_LOG_FN("#lvm") static void _lvm2_print_log(int level, const char *file, int line, int dm_errno_or_class, const char *msg)