LCOV - code coverage report
Current view: top level - plugins - dm_logging.c (source / functions) Coverage Total Hit
Test: libblockdev Coverage Report Lines: 81.2 % 16 13
Test Date: 2026-01-26 13:19:28 Functions: 100.0 % 1 1
Legend: Lines: hit not hit

            Line data    Source code
       1              : /*
       2              :  * Copyright (C) 2019 Red Hat, Inc.
       3              :  *
       4              :  * This library is free software; you can redistribute it and/or
       5              :  * modify it under the terms of the GNU Lesser General Public
       6              :  * License as published by the Free Software Foundation; either
       7              :  * version 2.1 of the License, or (at your option) any later version.
       8              :  *
       9              :  * This library is distributed in the hope that it will be useful,
      10              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      11              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      12              :  * Lesser General Public License for more details.
      13              :  *
      14              :  * You should have received a copy of the GNU Lesser General Public
      15              :  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
      16              :  *
      17              :  * Author: Vojtech Trefny <vtrefny@redhat.com>
      18              :  */
      19              : 
      20              : #include <glib/gprintf.h>
      21              : #include <syslog.h>
      22              : #include <stdarg.h>
      23              : #include <errno.h>
      24              : #include <blockdev/utils.h>
      25              : 
      26              : #include "dm_logging.h"
      27              : 
      28              : G_GNUC_INTERNAL void
      29           28 : redirect_dm_log (int level, const char *file G_GNUC_UNUSED, int line G_GNUC_UNUSED,
      30              :                              int dm_errno_or_class G_GNUC_UNUSED, const char *f, ...) {
      31           28 :     gchar *dm_msg = NULL;
      32           28 :     gchar *message = NULL;
      33           28 :     gint ret = 0;
      34              :     va_list args;
      35              : 
      36           28 :     va_start (args, f);
      37           28 :     ret = g_vasprintf (&dm_msg, f, args);
      38           28 :     va_end (args);
      39              : 
      40           28 :     if (ret < 0) {
      41            0 :         g_free (dm_msg);
      42            0 :         return;
      43              :     }
      44              : 
      45              : 
      46              : #ifdef DEBUG
      47              :     message = g_strdup_printf ("[libdevmapper] %s:%d %s", file, line, dm_msg);
      48              : #else
      49           28 :     message = g_strdup_printf ("[libdevmapper] %s", dm_msg);
      50              : #endif
      51              : 
      52              :     /* libdevmapper has some custom special log levels, these should be
      53              :        internal, but just to be sure mark everything weird as debug */
      54           28 :     if (level > LOG_DEBUG)
      55            0 :         level = LOG_DEBUG;
      56              : 
      57           28 :     bd_utils_log (level, message);
      58              : 
      59           28 :     g_free (dm_msg);
      60           28 :     g_free (message);
      61              : 
      62              : }
        

Generated by: LCOV version 2.0-1