LCOV - code coverage report
Current view: top level - lib/tevent - tevent_debug.c (source / functions) Hit Total Coverage
Test: coverage report for master 98b443d9 Lines: 99 144 68.8 %
Date: 2024-05-31 13:13:24 Functions: 22 29 75.9 %

          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             : #define TEVENT_DEPRECATED
      27             : #include "tevent.h"
      28             : #include "tevent_internal.h"
      29             : 
      30             : #undef tevent_thread_call_depth_reset_from_req
      31             : 
      32             : /********************************************************************
      33             :  * Debug wrapper functions, modeled (with lot's of code copied as is)
      34             :  * after the ev debug wrapper functions
      35             :  ********************************************************************/
      36             : 
      37             : /*
      38             :   this allows the user to choose their own debug function
      39             : */
      40    83488729 : int tevent_set_debug(struct tevent_context *ev,
      41             :                      void (*debug)(void *context,
      42             :                                    enum tevent_debug_level level,
      43             :                                    const char *fmt,
      44             :                                    va_list ap) PRINTF_ATTRIBUTE(3,0),
      45             :                      void *context)
      46             : {
      47    83488729 :         if (ev->wrapper.glue != NULL) {
      48           0 :                 ev = tevent_wrapper_main_ev(ev);
      49           0 :                 tevent_abort(ev, "tevent_set_debug() on wrapper");
      50           0 :                 errno = EINVAL;
      51           0 :                 return -1;
      52             :         }
      53    83488729 :         if (debug != NULL) {
      54             :                 /*
      55             :                  * tevent_set_max_debug_level(ev, TEVENT_DEBUG_TRACE)
      56             :                  * can be used to get full tracing, but we can to
      57             :                  * avoid overhead by default.
      58             :                  */
      59    83488729 :                 ev->debug_ops.max_level = TEVENT_DEBUG_WARNING;
      60             :         } else {
      61           0 :                 ev->debug_ops.max_level = TEVENT_DEBUG_FATAL;
      62             :         }
      63    83488729 :         ev->debug_ops.debug = debug;
      64    83488729 :         ev->debug_ops.context = context;
      65    83488729 :         return 0;
      66             : }
      67             : 
      68             : enum tevent_debug_level
      69    83488729 : tevent_set_max_debug_level(struct tevent_context *ev,
      70             :                            enum tevent_debug_level max_level)
      71             : {
      72     3093806 :         enum tevent_debug_level old_level;
      73    83488729 :         old_level = ev->debug_ops.max_level;
      74    83488729 :         ev->debug_ops.max_level = max_level;
      75    83488729 :         return old_level;
      76             : }
      77             : 
      78             : /*
      79             :   debug function for ev_set_debug_stderr
      80             : */
      81             : static void tevent_debug_stderr(void *private_data,
      82             :                                 enum tevent_debug_level level,
      83             :                                 const char *fmt,
      84             :                                 va_list ap) PRINTF_ATTRIBUTE(3,0);
      85           0 : static void tevent_debug_stderr(void *private_data,
      86             :                                 enum tevent_debug_level level,
      87             :                                 const char *fmt, va_list ap)
      88             : {
      89           0 :         if (level <= TEVENT_DEBUG_WARNING) {
      90           0 :                 vfprintf(stderr, fmt, ap);
      91             :         }
      92           0 : }
      93             : 
      94             : /*
      95             :   convenience function to setup debug messages on stderr
      96             :   messages of level TEVENT_DEBUG_WARNING and higher are printed
      97             : */
      98           0 : int tevent_set_debug_stderr(struct tevent_context *ev)
      99             : {
     100           0 :         return tevent_set_debug(ev, tevent_debug_stderr, ev);
     101             : }
     102             : 
     103             : /*
     104             :  * log a message
     105             :  *
     106             :  * The default debug action is to ignore debugging messages.
     107             :  * This is the most appropriate action for a library.
     108             :  * Applications using the library must decide where to
     109             :  * redirect debugging messages
     110             : */
     111  1039049928 : void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
     112             :                   const char *fmt, ...)
     113             : {
     114    28716226 :         va_list ap;
     115  1039049928 :         if (!ev) {
     116          21 :                 return;
     117             :         }
     118  1039049928 :         if (ev->wrapper.glue != NULL) {
     119           0 :                 ev = tevent_wrapper_main_ev(ev);
     120             :         }
     121  1039049928 :         if (level > ev->debug_ops.max_level) {
     122           6 :                 return;
     123             :         }
     124  1039049907 :         if (ev->debug_ops.debug == NULL) {
     125           0 :                 return;
     126             :         }
     127  1039049907 :         va_start(ap, fmt);
     128  1039049907 :         ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
     129  1039049907 :         va_end(ap);
     130             : }
     131             : 
     132      145475 : void tevent_set_trace_callback(struct tevent_context *ev,
     133             :                                tevent_trace_callback_t cb,
     134             :                                void *private_data)
     135             : {
     136      145475 :         if (ev->wrapper.glue != NULL) {
     137           0 :                 ev = tevent_wrapper_main_ev(ev);
     138           0 :                 tevent_abort(ev, "tevent_set_trace_callback() on wrapper");
     139           0 :                 return;
     140             :         }
     141             : 
     142      145475 :         ev->tracing.point.callback = cb;
     143      145475 :         ev->tracing.point.private_data = private_data;
     144             : }
     145             : 
     146           4 : void tevent_get_trace_callback(struct tevent_context *ev,
     147             :                                tevent_trace_callback_t *cb,
     148             :                                void *private_data)
     149             : {
     150           4 :         *cb = ev->tracing.point.callback;
     151           4 :         *(void**)private_data = ev->tracing.point.private_data;
     152           4 : }
     153             : 
     154  1267487562 : void tevent_trace_point_callback(struct tevent_context *ev,
     155             :                                  enum tevent_trace_point tp)
     156             : {
     157  1267487562 :         if (ev->tracing.point.callback != NULL) {
     158   622462075 :                 ev->tracing.point.callback(tp, ev->tracing.point.private_data);
     159             :         }
     160  1267487562 : }
     161             : 
     162       64213 : void tevent_set_trace_fd_callback(struct tevent_context *ev,
     163             :                                   tevent_trace_fd_callback_t cb,
     164             :                                   void *private_data)
     165             : {
     166       64213 :         if (ev->wrapper.glue != NULL) {
     167           0 :                 ev = tevent_wrapper_main_ev(ev);
     168           0 :                 tevent_abort(ev, "tevent_set_trace_fd_callback() on wrapper");
     169           0 :                 return;
     170             :         }
     171             : 
     172       64213 :         ev->tracing.fde.callback = cb;
     173       64213 :         ev->tracing.fde.private_data = private_data;
     174             : }
     175             : 
     176           3 : void tevent_get_trace_fd_callback(struct tevent_context *ev,
     177             :                                   tevent_trace_fd_callback_t *cb,
     178             :                                   void *p_private_data)
     179             : {
     180           3 :         *cb = ev->tracing.fde.callback;
     181           3 :         *(void**)p_private_data = ev->tracing.fde.private_data;
     182           3 : }
     183             : 
     184   193709533 : void tevent_trace_fd_callback(struct tevent_context *ev,
     185             :                               struct tevent_fd *fde,
     186             :                               enum tevent_event_trace_point tp)
     187             : {
     188   193709533 :         if (ev->tracing.fde.callback != NULL) {
     189     2130648 :                 ev->tracing.fde.callback(fde, tp, ev->tracing.fde.private_data);
     190             :         }
     191   193709533 : }
     192             : 
     193       64213 : void tevent_set_trace_signal_callback(struct tevent_context *ev,
     194             :                                       tevent_trace_signal_callback_t cb,
     195             :                                       void *private_data)
     196             : {
     197       64213 :         if (ev->wrapper.glue != NULL) {
     198           0 :                 ev = tevent_wrapper_main_ev(ev);
     199           0 :                 tevent_abort(ev, "tevent_set_trace_signal_callback() "
     200             :                              "on wrapper");
     201           0 :                 return;
     202             :         }
     203             : 
     204       64213 :         ev->tracing.se.callback = cb;
     205       64213 :         ev->tracing.se.private_data = private_data;
     206             : }
     207             : 
     208           3 : void tevent_get_trace_signal_callback(struct tevent_context *ev,
     209             :                                       tevent_trace_signal_callback_t *cb,
     210             :                                       void *p_private_data)
     211             : {
     212           3 :         *cb = ev->tracing.se.callback;
     213           3 :         *(void**)p_private_data = ev->tracing.se.private_data;
     214           3 : }
     215             : 
     216    37463487 : void tevent_trace_signal_callback(struct tevent_context *ev,
     217             :                                   struct tevent_signal *se,
     218             :                                   enum tevent_event_trace_point tp)
     219             : {
     220    37463487 :         if (ev->tracing.se.callback != NULL) {
     221         389 :                 ev->tracing.se.callback(se, tp, ev->tracing.se.private_data);
     222             :         }
     223    37463487 : }
     224             : 
     225       64213 : void tevent_set_trace_timer_callback(struct tevent_context *ev,
     226             :                                      tevent_trace_timer_callback_t cb,
     227             :                                      void *private_data)
     228             : {
     229       64213 :         if (ev->wrapper.glue != NULL) {
     230           0 :                 ev = tevent_wrapper_main_ev(ev);
     231           0 :                 tevent_abort(ev, "tevent_set_trace_timer_callback() "
     232             :                              "on wrapper");
     233           0 :                 return;
     234             :         }
     235             : 
     236       64213 :         ev->tracing.te.callback = cb;
     237       64213 :         ev->tracing.te.private_data = private_data;
     238             : }
     239             : 
     240           3 : void tevent_get_trace_timer_callback(struct tevent_context *ev,
     241             :                                      tevent_trace_timer_callback_t *cb,
     242             :                                      void *p_private_data)
     243             : {
     244           3 :         *cb = ev->tracing.te.callback;
     245           3 :         *(void**)p_private_data = ev->tracing.te.private_data;
     246           3 : }
     247             : 
     248  1123636195 : void tevent_trace_timer_callback(struct tevent_context *ev,
     249             :                                  struct tevent_timer *te,
     250             :                                  enum tevent_event_trace_point tp)
     251             : {
     252  1123636195 :         if (ev->tracing.te.callback != NULL) {
     253      260317 :                 ev->tracing.te.callback(te, tp, ev->tracing.te.private_data);
     254             :         }
     255  1123636195 : }
     256             : 
     257       64214 : void tevent_set_trace_immediate_callback(struct tevent_context *ev,
     258             :                                          tevent_trace_immediate_callback_t cb,
     259             :                                          void *private_data)
     260             : {
     261       64214 :         if (ev->wrapper.glue != NULL) {
     262           0 :                 ev = tevent_wrapper_main_ev(ev);
     263           0 :                 tevent_abort(ev, "tevent_set_trace_immediate_callback() "
     264             :                              "on wrapper");
     265           0 :                 return;
     266             :         }
     267             : 
     268       64214 :         ev->tracing.im.callback = cb;
     269       64214 :         ev->tracing.im.private_data = private_data;
     270             : }
     271             : 
     272           3 : void tevent_get_trace_immediate_callback(struct tevent_context *ev,
     273             :                                          tevent_trace_immediate_callback_t *cb,
     274             :                                          void *p_private_data)
     275             : {
     276           3 :         *cb = ev->tracing.im.callback;
     277           3 :         *(void**)p_private_data = ev->tracing.im.private_data;
     278           3 : }
     279             : 
     280    97316949 : void tevent_trace_immediate_callback(struct tevent_context *ev,
     281             :                                      struct tevent_immediate *im,
     282             :                                      enum tevent_event_trace_point tp)
     283             : {
     284    97316949 :         if (ev->tracing.im.callback != NULL) {
     285     2728961 :                 ev->tracing.im.callback(im, tp, ev->tracing.im.private_data);
     286             :         }
     287    97316949 : }
     288             : 
     289       64187 : void tevent_set_trace_queue_callback(struct tevent_context *ev,
     290             :                                      tevent_trace_queue_callback_t cb,
     291             :                                      void *private_data)
     292             : {
     293       64187 :         if (ev->wrapper.glue != NULL) {
     294           0 :                 ev = tevent_wrapper_main_ev(ev);
     295           0 :                 tevent_abort(ev, "tevent_set_trace_queue_callback() "
     296             :                              "on wrapper");
     297           0 :                 return;
     298             :         }
     299             : 
     300       64187 :         ev->tracing.qe.callback = cb;
     301       64187 :         ev->tracing.qe.private_data = private_data;
     302             : }
     303             : 
     304           3 : void tevent_get_trace_queue_callback(struct tevent_context *ev,
     305             :                                      tevent_trace_queue_callback_t *cb,
     306             :                                      void *p_private_data)
     307             : {
     308           3 :         *cb = ev->tracing.qe.callback;
     309           3 :         *(void**)p_private_data = ev->tracing.qe.private_data;
     310           3 : }
     311             : 
     312    38455238 : void tevent_trace_queue_callback(struct tevent_context *ev,
     313             :                                  struct tevent_queue_entry *qe,
     314             :                                  enum tevent_event_trace_point tp)
     315             : {
     316    38455238 :         if (ev->tracing.qe.callback != NULL) {
     317     1053323 :                 ev->tracing.qe.callback(qe, tp, ev->tracing.qe.private_data);
     318             :         }
     319    38455238 : }
     320             : 
     321             : _PRIVATE_ __thread
     322             : struct tevent_thread_call_depth_state tevent_thread_call_depth_state_g;
     323             : 
     324           0 : void tevent_thread_call_depth_activate(size_t *ptr)
     325             : {
     326           0 : }
     327             : 
     328           0 : void tevent_thread_call_depth_deactivate(void)
     329             : {
     330           0 : }
     331             : 
     332           0 : void tevent_thread_call_depth_start(struct tevent_req *req)
     333             : {
     334           0 : }
     335             : 
     336           0 : void tevent_thread_call_depth_reset_from_req(struct tevent_req *req)
     337             : {
     338           0 :         _tevent_thread_call_depth_reset_from_req(req, NULL);
     339           0 : }
     340             : 
     341           0 : void _tevent_thread_call_depth_reset_from_req(struct tevent_req *req,
     342             :                                              const char *fname)
     343             : {
     344           0 :         if (tevent_thread_call_depth_state_g.cb != NULL) {
     345           0 :                 tevent_thread_call_depth_state_g.cb(
     346             :                         tevent_thread_call_depth_state_g.cb_private,
     347             :                         TEVENT_CALL_FLOW_REQ_RESET,
     348             :                         req,
     349             :                         req->internal.call_depth,
     350             :                         fname);
     351             :         }
     352           0 : }
     353             : 
     354         143 : void tevent_thread_call_depth_set_callback(tevent_call_depth_callback_t f,
     355             :                                            void *private_data)
     356             : {
     357             :         /* In case of deactivation, make sure that call depth is set to 0 */
     358         143 :         if (tevent_thread_call_depth_state_g.cb != NULL) {
     359           0 :                 tevent_thread_call_depth_state_g.cb(
     360             :                         tevent_thread_call_depth_state_g.cb_private,
     361             :                         TEVENT_CALL_FLOW_REQ_RESET,
     362             :                         NULL,
     363             :                         0,
     364             :                         "tevent_thread_call_depth_set_callback");
     365             :         }
     366         143 :         tevent_thread_call_depth_state_g = (struct tevent_thread_call_depth_state)
     367             :         {
     368             :                 .cb = f,
     369             :                 .cb_private = private_data,
     370             :         };
     371         143 : }

Generated by: LCOV version 1.14