LCOV - code coverage report
Current view: top level - lib/util - tevent_debug.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 38 53 71.7 %
Date: 2023-11-21 12:31:41 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Copyright (C) Andrew Tridgell 2003
       4             : 
       5             :    This program is free software; you can redistribute it and/or modify
       6             :    it under the terms of the GNU General Public License as published by
       7             :    the Free Software Foundation; either version 3 of the License, or
       8             :    (at your option) any later version.
       9             : 
      10             :    This program is distributed in the hope that it will be useful,
      11             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      12             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13             :    GNU General Public License for more details.
      14             : 
      15             :    You should have received a copy of the GNU General Public License
      16             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      17             : */
      18             : 
      19             : #include "includes.h"
      20             : #include <tevent.h>
      21             : 
      22             : #undef DBGC_CLASS
      23             : #define DBGC_CLASS DBGC_TEVENT
      24             : 
      25             : static void samba_tevent_debug(void *context,
      26             :                                enum tevent_debug_level level,
      27             :                                const char *fmt,
      28             :                                va_list ap)  PRINTF_ATTRIBUTE(3,0);
      29             : 
      30          58 : static void samba_tevent_debug(void *context,
      31             :                                enum tevent_debug_level level,
      32             :                                const char *fmt,
      33             :                                va_list ap)
      34             : {
      35          58 :         int samba_level = -1;
      36             : 
      37          58 :         switch (level) {
      38           0 :         case TEVENT_DEBUG_FATAL:
      39           0 :                 samba_level = 0;
      40           0 :                 break;
      41          58 :         case TEVENT_DEBUG_ERROR:
      42          58 :                 samba_level = 1;
      43          58 :                 break;
      44           0 :         case TEVENT_DEBUG_WARNING:
      45           0 :                 samba_level = 2;
      46           0 :                 break;
      47           0 :         case TEVENT_DEBUG_TRACE:
      48           0 :                 samba_level = 50;
      49           0 :                 break;
      50             :         };
      51             : 
      52          58 :         if (CHECK_DEBUGLVL(samba_level)) {
      53          58 :                 const char *name = (const char *)context;
      54          58 :                 char *message = NULL;
      55           0 :                 int ret;
      56             : 
      57          58 :                 ret = vasprintf(&message, fmt, ap);
      58          58 :                 if (ret == -1) {
      59           0 :                         return;
      60             :                 }
      61             : 
      62          58 :                 if (name == NULL) {
      63           0 :                         name = "samba_tevent";
      64             :                 }
      65             : 
      66          58 :                 DEBUG(samba_level, ("%s: %s", name, message));
      67          58 :                 free(message);
      68             :         }
      69             : }
      70             : 
      71           0 : static void samba_tevent_abort_fn(const char *reason)
      72             : {
      73           0 :         smb_panic(reason);
      74             : }
      75             : 
      76     4010614 : static void samba_tevent_setup_abort_fn(void)
      77             : {
      78       23567 :         static bool abort_fn_done;
      79             : 
      80     4010614 :         if (!abort_fn_done) {
      81       26586 :                 tevent_set_abort_fn(samba_tevent_abort_fn);
      82       26586 :                 abort_fn_done = true;
      83             :         }
      84     3987047 : }
      85             : 
      86     2217783 : void samba_tevent_set_debug(struct tevent_context *ev, const char *name)
      87             : {
      88     2217783 :         void *p = discard_const(name);
      89     2217783 :         samba_tevent_setup_abort_fn();
      90     2217783 :         tevent_set_debug(ev, samba_tevent_debug, p);
      91             : 
      92             :         /* these values should match samba_tevent_debug() */
      93     2217783 :         if (CHECK_DEBUGLVL(50)) {
      94           0 :                 tevent_set_max_debug_level(ev, TEVENT_DEBUG_TRACE);
      95     2217783 :         } else if (CHECK_DEBUGLVL(2)) {
      96         138 :                 tevent_set_max_debug_level(ev, TEVENT_DEBUG_WARNING);
      97     2217645 :         } else if (CHECK_DEBUGLVL(1)) {
      98     2104615 :                 tevent_set_max_debug_level(ev, TEVENT_DEBUG_ERROR);
      99             :         } else {
     100      113030 :                 tevent_set_max_debug_level(ev, TEVENT_DEBUG_FATAL);
     101             :         }
     102     2217783 : }
     103             : 
     104     1792831 : struct tevent_context *samba_tevent_context_init(TALLOC_CTX *mem_ctx)
     105             : {
     106        8666 :         struct tevent_context *ev;
     107             : 
     108     1792831 :         samba_tevent_setup_abort_fn();
     109             : 
     110     1792831 :         ev = tevent_context_init(mem_ctx);
     111     1792831 :         if (ev) {
     112     1792831 :                 samba_tevent_set_debug(ev, NULL);
     113             :         }
     114             : 
     115     1792831 :         return ev;
     116             : }

Generated by: LCOV version 1.14