LCOV - code coverage report
Current view: top level - lib/tevent - tevent_debug.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 99 144 68.8 %
Date: 2024-04-21 15:09:00 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    83604344 : 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    83604344 :         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    83604344 :         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    83604344 :                 ev->debug_ops.max_level = TEVENT_DEBUG_WARNING;
      60             :         } else {
      61           0 :                 ev->debug_ops.max_level = TEVENT_DEBUG_FATAL;
      62             :         }
      63    83604344 :         ev->debug_ops.debug = debug;
      64    83604344 :         ev->debug_ops.context = context;
      65    83604344 :         return 0;
      66             : }
      67             : 
      68             : enum tevent_debug_level
      69    83604344 : tevent_set_max_debug_level(struct tevent_context *ev,
      70             :                            enum tevent_debug_level max_level)
      71             : {
      72     3113494 :         enum tevent_debug_level old_level;
      73    83604344 :         old_level = ev->debug_ops.max_level;
      74    83604344 :         ev->debug_ops.max_level = max_level;
      75    83604344 :         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  1032138100 : void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
     112             :                   const char *fmt, ...)
     113             : {
     114    28738664 :         va_list ap;
     115  1032138100 :         if (!ev) {
     116          21 :                 return;
     117             :         }
     118  1032138100 :         if (ev->wrapper.glue != NULL) {
     119           0 :                 ev = tevent_wrapper_main_ev(ev);
     120             :         }
     121  1032138100 :         if (level > ev->debug_ops.max_level) {
     122           6 :                 return;
     123             :         }
     124  1032138079 :         if (ev->debug_ops.debug == NULL) {
     125           0 :                 return;
     126             :         }
     127  1032138079 :         va_start(ap, fmt);
     128  1032138079 :         ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
     129  1032138079 :         va_end(ap);
     130             : }
     131             : 
     132      143834 : void tevent_set_trace_callback(struct tevent_context *ev,
     133             :                                tevent_trace_callback_t cb,
     134             :                                void *private_data)
     135             : {
     136      143834 :         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      143834 :         ev->tracing.point.callback = cb;
     143      143834 :         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  1282756523 : void tevent_trace_point_callback(struct tevent_context *ev,
     155             :                                  enum tevent_trace_point tp)
     156             : {
     157  1282756523 :         if (ev->tracing.point.callback != NULL) {
     158   600293801 :                 ev->tracing.point.callback(tp, ev->tracing.point.private_data);
     159             :         }
     160  1282756523 : }
     161             : 
     162       63480 : void tevent_set_trace_fd_callback(struct tevent_context *ev,
     163             :                                   tevent_trace_fd_callback_t cb,
     164             :                                   void *private_data)
     165             : {
     166       63480 :         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       63480 :         ev->tracing.fde.callback = cb;
     173       63480 :         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   199928612 : void tevent_trace_fd_callback(struct tevent_context *ev,
     185             :                               struct tevent_fd *fde,
     186             :                               enum tevent_event_trace_point tp)
     187             : {
     188   199928612 :         if (ev->tracing.fde.callback != NULL) {
     189     2498388 :                 ev->tracing.fde.callback(fde, tp, ev->tracing.fde.private_data);
     190             :         }
     191   199928612 : }
     192             : 
     193       63480 : void tevent_set_trace_signal_callback(struct tevent_context *ev,
     194             :                                       tevent_trace_signal_callback_t cb,
     195             :                                       void *private_data)
     196             : {
     197       63480 :         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       63480 :         ev->tracing.se.callback = cb;
     205       63480 :         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    36792022 : void tevent_trace_signal_callback(struct tevent_context *ev,
     217             :                                   struct tevent_signal *se,
     218             :                                   enum tevent_event_trace_point tp)
     219             : {
     220    36792022 :         if (ev->tracing.se.callback != NULL) {
     221         387 :                 ev->tracing.se.callback(se, tp, ev->tracing.se.private_data);
     222             :         }
     223    36792022 : }
     224             : 
     225       63480 : void tevent_set_trace_timer_callback(struct tevent_context *ev,
     226             :                                      tevent_trace_timer_callback_t cb,
     227             :                                      void *private_data)
     228             : {
     229       63480 :         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       63480 :         ev->tracing.te.callback = cb;
     237       63480 :         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  1113695496 : void tevent_trace_timer_callback(struct tevent_context *ev,
     249             :                                  struct tevent_timer *te,
     250             :                                  enum tevent_event_trace_point tp)
     251             : {
     252  1113695496 :         if (ev->tracing.te.callback != NULL) {
     253      284555 :                 ev->tracing.te.callback(te, tp, ev->tracing.te.private_data);
     254             :         }
     255  1113695496 : }
     256             : 
     257       63481 : void tevent_set_trace_immediate_callback(struct tevent_context *ev,
     258             :                                          tevent_trace_immediate_callback_t cb,
     259             :                                          void *private_data)
     260             : {
     261       63481 :         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       63481 :         ev->tracing.im.callback = cb;
     269       63481 :         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    95797625 : void tevent_trace_immediate_callback(struct tevent_context *ev,
     281             :                                      struct tevent_immediate *im,
     282             :                                      enum tevent_event_trace_point tp)
     283             : {
     284    95797625 :         if (ev->tracing.im.callback != NULL) {
     285     3159634 :                 ev->tracing.im.callback(im, tp, ev->tracing.im.private_data);
     286             :         }
     287    95797625 : }
     288             : 
     289       63454 : void tevent_set_trace_queue_callback(struct tevent_context *ev,
     290             :                                      tevent_trace_queue_callback_t cb,
     291             :                                      void *private_data)
     292             : {
     293       63454 :         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       63454 :         ev->tracing.qe.callback = cb;
     301       63454 :         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    39332921 : void tevent_trace_queue_callback(struct tevent_context *ev,
     313             :                                  struct tevent_queue_entry *qe,
     314             :                                  enum tevent_event_trace_point tp)
     315             : {
     316    39332921 :         if (ev->tracing.qe.callback != NULL) {
     317     1230479 :                 ev->tracing.qe.callback(qe, tp, ev->tracing.qe.private_data);
     318             :         }
     319    39332921 : }
     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