]> sourceware.org Git - lvm2.git/commitdiff
libdm: support for DM_DEBUG_WITH_LINE_NUMBERS
authorZdenek Kabelac <zkabelac@redhat.com>
Wed, 14 Mar 2018 17:08:16 +0000 (18:08 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Thu, 15 Mar 2018 09:49:24 +0000 (10:49 +0100)
For any libdm tool using default debugging function allow
to show source filename and code line number when this
functionality is available.

WHATS_NEW_DM
libdm/libdm-common.c
man/lvm.8_main

index 5c1f4a11678cfcfc338d8f964d7c3e68c15bf5e5..09e6fc00a161ecb90dcddf6febf4cd59ee709ff2 100644 (file)
@@ -1,5 +1,6 @@
 Version 1.02.147 - 
 =====================================
+  Support DM_DEBUG_WITH_LINE_NUMBERS envvar for debug msg with source:line.
   Configured command for thin pool threshold handling gets whole environment.
   Fix tests for failing dm_snprintf() in stats code.
   Parsing mirror status accepts 'userspace' keyword in status.
index 2ab5bd121d091ecfa0be81211673c4b2ffe1826a..99cf0c8a611df4cba957ebd02d838c823322c704 100644 (file)
@@ -108,12 +108,12 @@ void dm_lib_init(void)
  */
 
 __attribute__((format(printf, 5, 0)))
-static void _default_log_line(int level,
-           const char *file __attribute__((unused)),
-           int line __attribute__((unused)), int dm_errno_or_class,
-           const char *f, va_list ap)
+static void _default_log_line(int level, const char *file,
+                             int line, int dm_errno_or_class,
+                             const char *f, va_list ap)
 {
        static int _abort_on_internal_errors = -1;
+       static int _debug_with_line_numbers = -1;
        FILE *out = log_stderr(level) ? stderr : stdout;
 
        level = log_level(level);
@@ -121,6 +121,15 @@ static void _default_log_line(int level,
        if (level <= _LOG_WARN || _verbose) {
                if (level < _LOG_WARN)
                        out = stderr;
+
+               if (_debug_with_line_numbers < 0)
+                       /* Set when env DM_DEBUG_WITH_LINE_NUMBERS is not "0" */
+                       _debug_with_line_numbers =
+                               strcmp(getenv("DM_DEBUG_WITH_LINE_NUMBERS") ? : "0", "0");
+
+               if (_debug_with_line_numbers)
+                       fprintf(out, "%s:%d     ", file, line);
+
                vfprintf(out, f, ap);
                fputc('\n', out);
        }
index bd5d8a74fb7ac8a3ddd56c7595ea14cc2de46cb4..7bbf44abd4587d301fae29a17744b898b1151f2a 100644 (file)
@@ -481,6 +481,9 @@ Abort processing if the code detects a non-fatal internal error.
 .B DM_DISABLE_UDEV
 Avoid interaction with udev.  LVM will manage the relevant nodes in /dev
 directly.
+.TP
+.B DM_DEBUG_WITH_LINE_NUMBERS
+Prepends source file name and code line number with libdm debugging.
 .
 .SH FILES
 .
This page took 0.046048 seconds and 5 git commands to generate.