LCOV - code coverage report
Current view: top level - lib/tevent - tevent_debug.c (source / functions) Hit Total Coverage
Test: coverage report for v4-17-test 1498b464 Lines: 82 115 71.3 %
Date: 2024-06-13 04:01:37 Functions: 19 22 86.4 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Copyright (C) Andrew Tridgell 2005
       5             :    Copyright (C) Jelmer Vernooij 2005
       6             : 
       7             :      ** NOTE! The following LGPL license applies to the tevent
       8             :      ** library. This does NOT imply that all of Samba is released
       9             :      ** under the LGPL
      10             : 
      11             :    This library is free software; you can redistribute it and/or
      12             :    modify it under the terms of the GNU Lesser General Public
      13             :    License as published by the Free Software Foundation; either
      14             :    version 3 of the License, or (at your option) any later version.
      15             : 
      16             :    This library is distributed in the hope that it will be useful,
      17             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      18             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      19             :    Lesser General Public License for more details.
      20             : 
      21             :    You should have received a copy of the GNU Lesser General Public
      22             :    License along with this library; if not, see <http://www.gnu.org/licenses/>.
      23             : */
      24             : 
      25             : #include "replace.h"
      26             : #include "tevent.h"
      27             : #include "tevent_internal.h"
      28             : 
      29             : /********************************************************************
      30             :  * Debug wrapper functions, modeled (with lot's of code copied as is)
      31             :  * after the ev debug wrapper functions
      32             :  ********************************************************************/
      33             : 
      34             : /*
      35             :   this allows the user to choose their own debug function
      36             : */
      37    54546741 : int tevent_set_debug(struct tevent_context *ev,
      38             :                      void (*debug)(void *context,
      39             :                                    enum tevent_debug_level level,
      40             :                                    const char *fmt,
      41             :                                    va_list ap) PRINTF_ATTRIBUTE(3,0),
      42             :                      void *context)
      43             : {
      44    54546741 :         if (ev->wrapper.glue != NULL) {
      45           0 :                 ev = tevent_wrapper_main_ev(ev);
      46           0 :                 tevent_abort(ev, "tevent_set_debug() on wrapper");
      47           0 :                 errno = EINVAL;
      48           0 :                 return -1;
      49             :         }
      50             : 
      51    54546741 :         ev->debug_ops.debug = debug;
      52    54546741 :         ev->debug_ops.context = context;
      53    54546741 :         return 0;
      54             : }
      55             : 
      56             : /*
      57             :   debug function for ev_set_debug_stderr
      58             : */
      59             : static void tevent_debug_stderr(void *private_data,
      60             :                                 enum tevent_debug_level level,
      61             :                                 const char *fmt,
      62             :                                 va_list ap) PRINTF_ATTRIBUTE(3,0);
      63           0 : static void tevent_debug_stderr(void *private_data,
      64             :                                 enum tevent_debug_level level,
      65             :                                 const char *fmt, va_list ap)
      66             : {
      67           0 :         if (level <= TEVENT_DEBUG_WARNING) {
      68           0 :                 vfprintf(stderr, fmt, ap);
      69             :         }
      70           0 : }
      71             : 
      72             : /*
      73             :   convenience function to setup debug messages on stderr
      74             :   messages of level TEVENT_DEBUG_WARNING and higher are printed
      75             : */
      76           0 : int tevent_set_debug_stderr(struct tevent_context *ev)
      77             : {
      78           0 :         return tevent_set_debug(ev, tevent_debug_stderr, ev);
      79             : }
      80             : 
      81             : /*
      82             :  * log a message
      83             :  *
      84             :  * The default debug action is to ignore debugging messages.
      85             :  * This is the most appropriate action for a library.
      86             :  * Applications using the library must decide where to
      87             :  * redirect debugging messages
      88             : */
      89   860626414 : void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
      90             :                   const char *fmt, ...)
      91             : {
      92             :         va_list ap;
      93   860626414 :         if (!ev) {
      94   257624230 :                 return;
      95             :         }
      96   724005406 :         if (ev->wrapper.glue != NULL) {
      97           0 :                 ev = tevent_wrapper_main_ev(ev);
      98             :         }
      99   724005406 :         if (ev->debug_ops.debug == NULL) {
     100        1134 :                 return;
     101             :         }
     102   724004272 :         va_start(ap, fmt);
     103   724004272 :         ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
     104   724004272 :         va_end(ap);
     105             : }
     106             : 
     107       35447 : void tevent_set_trace_callback(struct tevent_context *ev,
     108             :                                tevent_trace_callback_t cb,
     109             :                                void *private_data)
     110             : {
     111       35447 :         if (ev->wrapper.glue != NULL) {
     112           0 :                 ev = tevent_wrapper_main_ev(ev);
     113           0 :                 tevent_abort(ev, "tevent_set_trace_callback() on wrapper");
     114           0 :                 return;
     115             :         }
     116             : 
     117       35447 :         ev->tracing.point.callback = cb;
     118       35447 :         ev->tracing.point.private_data = private_data;
     119             : }
     120             : 
     121           0 : void tevent_get_trace_callback(struct tevent_context *ev,
     122             :                                tevent_trace_callback_t *cb,
     123             :                                void *private_data)
     124             : {
     125           0 :         *cb = ev->tracing.point.callback;
     126           0 :         *(void**)private_data = ev->tracing.point.private_data;
     127           0 : }
     128             : 
     129   496201572 : void tevent_trace_point_callback(struct tevent_context *ev,
     130             :                                  enum tevent_trace_point tp)
     131             : {
     132   496201572 :         if (ev->tracing.point.callback != NULL) {
     133   148825322 :                 ev->tracing.point.callback(tp, ev->tracing.point.private_data);
     134             :         }
     135   496201572 : }
     136             : 
     137       10663 : void tevent_set_trace_fd_callback(struct tevent_context *ev,
     138             :                                   tevent_trace_fd_callback_t cb,
     139             :                                   void *private_data)
     140             : {
     141       10663 :         if (ev->wrapper.glue != NULL) {
     142           0 :                 ev = tevent_wrapper_main_ev(ev);
     143           0 :                 tevent_abort(ev, "tevent_set_trace_fd_callback() on wrapper");
     144           0 :                 return;
     145             :         }
     146             : 
     147       10663 :         ev->tracing.fde.callback = cb;
     148       10663 :         ev->tracing.fde.private_data = private_data;
     149             : }
     150             : 
     151           3 : void tevent_get_trace_fd_callback(struct tevent_context *ev,
     152             :                                   tevent_trace_fd_callback_t *cb,
     153             :                                   void *p_private_data)
     154             : {
     155           3 :         *cb = ev->tracing.fde.callback;
     156           3 :         *(void**)p_private_data = ev->tracing.fde.private_data;
     157           3 : }
     158             : 
     159    64117259 : void tevent_trace_fd_callback(struct tevent_context *ev,
     160             :                               struct tevent_fd *fde,
     161             :                               enum tevent_event_trace_point tp)
     162             : {
     163    64117259 :         if (ev->tracing.fde.callback != NULL) {
     164          10 :                 ev->tracing.fde.callback(fde, tp, ev->tracing.fde.private_data);
     165             :         }
     166    64117259 : }
     167             : 
     168       10663 : void tevent_set_trace_signal_callback(struct tevent_context *ev,
     169             :                                       tevent_trace_signal_callback_t cb,
     170             :                                       void *private_data)
     171             : {
     172       10663 :         if (ev->wrapper.glue != NULL) {
     173           0 :                 ev = tevent_wrapper_main_ev(ev);
     174           0 :                 tevent_abort(ev, "tevent_set_trace_signal_callback() "
     175             :                              "on wrapper");
     176           0 :                 return;
     177             :         }
     178             : 
     179       10663 :         ev->tracing.se.callback = cb;
     180       10663 :         ev->tracing.se.private_data = private_data;
     181             : }
     182             : 
     183           3 : void tevent_get_trace_signal_callback(struct tevent_context *ev,
     184             :                                       tevent_trace_signal_callback_t *cb,
     185             :                                       void *p_private_data)
     186             : {
     187           3 :         *cb = ev->tracing.se.callback;
     188           3 :         *(void**)p_private_data = ev->tracing.se.private_data;
     189           3 : }
     190             : 
     191     1388443 : void tevent_trace_signal_callback(struct tevent_context *ev,
     192             :                                   struct tevent_signal *se,
     193             :                                   enum tevent_event_trace_point tp)
     194             : {
     195     1388443 :         if (ev->tracing.se.callback != NULL) {
     196          10 :                 ev->tracing.se.callback(se, tp, ev->tracing.se.private_data);
     197             :         }
     198     1388443 : }
     199             : 
     200       10663 : void tevent_set_trace_timer_callback(struct tevent_context *ev,
     201             :                                      tevent_trace_timer_callback_t cb,
     202             :                                      void *private_data)
     203             : {
     204       10663 :         if (ev->wrapper.glue != NULL) {
     205           0 :                 ev = tevent_wrapper_main_ev(ev);
     206           0 :                 tevent_abort(ev, "tevent_set_trace_timer_callback() "
     207             :                              "on wrapper");
     208           0 :                 return;
     209             :         }
     210             : 
     211       10663 :         ev->tracing.te.callback = cb;
     212       10663 :         ev->tracing.te.private_data = private_data;
     213             : }
     214             : 
     215           3 : void tevent_get_trace_timer_callback(struct tevent_context *ev,
     216             :                                      tevent_trace_timer_callback_t *cb,
     217             :                                      void *p_private_data)
     218             : {
     219           3 :         *cb = ev->tracing.te.callback;
     220           3 :         *(void**)p_private_data = ev->tracing.te.private_data;
     221           3 : }
     222             : 
     223   691527718 : void tevent_trace_timer_callback(struct tevent_context *ev,
     224             :                                  struct tevent_timer *te,
     225             :                                  enum tevent_event_trace_point tp)
     226             : {
     227   691527718 :         if (ev->tracing.te.callback != NULL) {
     228          12 :                 ev->tracing.te.callback(te, tp, ev->tracing.te.private_data);
     229             :         }
     230   691527718 : }
     231             : 
     232       10664 : void tevent_set_trace_immediate_callback(struct tevent_context *ev,
     233             :                                          tevent_trace_immediate_callback_t cb,
     234             :                                          void *private_data)
     235             : {
     236       10664 :         if (ev->wrapper.glue != NULL) {
     237           0 :                 ev = tevent_wrapper_main_ev(ev);
     238           0 :                 tevent_abort(ev, "tevent_set_trace_immediate_callback() "
     239             :                              "on wrapper");
     240           0 :                 return;
     241             :         }
     242             : 
     243       10664 :         ev->tracing.im.callback = cb;
     244       10664 :         ev->tracing.im.private_data = private_data;
     245             : }
     246             : 
     247           3 : void tevent_get_trace_immediate_callback(struct tevent_context *ev,
     248             :                                          tevent_trace_immediate_callback_t *cb,
     249             :                                          void *p_private_data)
     250             : {
     251           3 :         *cb = ev->tracing.im.callback;
     252           3 :         *(void**)p_private_data = ev->tracing.im.private_data;
     253           3 : }
     254             : 
     255    50788871 : void tevent_trace_immediate_callback(struct tevent_context *ev,
     256             :                                      struct tevent_immediate *im,
     257             :                                      enum tevent_event_trace_point tp)
     258             : {
     259    50788871 :         if (ev->tracing.im.callback != NULL) {
     260          20 :                 ev->tracing.im.callback(im, tp, ev->tracing.im.private_data);
     261             :         }
     262    50788871 : }
     263             : 
     264       10637 : void tevent_set_trace_queue_callback(struct tevent_context *ev,
     265             :                                      tevent_trace_queue_callback_t cb,
     266             :                                      void *private_data)
     267             : {
     268       10637 :         if (ev->wrapper.glue != NULL) {
     269           0 :                 ev = tevent_wrapper_main_ev(ev);
     270           0 :                 tevent_abort(ev, "tevent_set_trace_queue_callback() "
     271             :                              "on wrapper");
     272           0 :                 return;
     273             :         }
     274             : 
     275       10637 :         ev->tracing.qe.callback = cb;
     276       10637 :         ev->tracing.qe.private_data = private_data;
     277             : }
     278             : 
     279           3 : void tevent_get_trace_queue_callback(struct tevent_context *ev,
     280             :                                      tevent_trace_queue_callback_t *cb,
     281             :                                      void *p_private_data)
     282             : {
     283           3 :         *cb = ev->tracing.qe.callback;
     284           3 :         *(void**)p_private_data = ev->tracing.qe.private_data;
     285           3 : }
     286             : 
     287    20139000 : void tevent_trace_queue_callback(struct tevent_context *ev,
     288             :                                  struct tevent_queue_entry *qe,
     289             :                                  enum tevent_event_trace_point tp)
     290             : {
     291    20139000 :         if (ev->tracing.qe.callback != NULL) {
     292          24 :                 ev->tracing.qe.callback(qe, tp, ev->tracing.qe.private_data);
     293             :         }
     294    20139000 : }

Generated by: LCOV version 1.13