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 57087083 : 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 57087083 : 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 57087083 : ev->debug_ops.debug = debug;
52 57087083 : ev->debug_ops.context = context;
53 57087083 : 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 896054165 : void tevent_debug(struct tevent_context *ev, enum tevent_debug_level level,
90 : const char *fmt, ...)
91 : {
92 : va_list ap;
93 896054165 : if (!ev) {
94 142417505 : return;
95 : }
96 753637794 : if (ev->wrapper.glue != NULL) {
97 0 : ev = tevent_wrapper_main_ev(ev);
98 : }
99 753637794 : if (ev->debug_ops.debug == NULL) {
100 1134 : return;
101 : }
102 753636660 : va_start(ap, fmt);
103 753636660 : ev->debug_ops.debug(ev->debug_ops.context, level, fmt, ap);
104 753636660 : va_end(ap);
105 : }
106 :
107 37595 : void tevent_set_trace_callback(struct tevent_context *ev,
108 : tevent_trace_callback_t cb,
109 : void *private_data)
110 : {
111 37595 : 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 37595 : ev->tracing.point.callback = cb;
118 37595 : 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 555587596 : void tevent_trace_point_callback(struct tevent_context *ev,
130 : enum tevent_trace_point tp)
131 : {
132 555587596 : if (ev->tracing.point.callback != NULL) {
133 170481892 : ev->tracing.point.callback(tp, ev->tracing.point.private_data);
134 : }
135 555587596 : }
136 :
137 10625 : void tevent_set_trace_fd_callback(struct tevent_context *ev,
138 : tevent_trace_fd_callback_t cb,
139 : void *private_data)
140 : {
141 10625 : 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 10625 : ev->tracing.fde.callback = cb;
148 10625 : 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 81754311 : void tevent_trace_fd_callback(struct tevent_context *ev,
160 : struct tevent_fd *fde,
161 : enum tevent_event_trace_point tp)
162 : {
163 81754311 : if (ev->tracing.fde.callback != NULL) {
164 10 : ev->tracing.fde.callback(fde, tp, ev->tracing.fde.private_data);
165 : }
166 81754311 : }
167 :
168 10625 : void tevent_set_trace_signal_callback(struct tevent_context *ev,
169 : tevent_trace_signal_callback_t cb,
170 : void *private_data)
171 : {
172 10625 : 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 10625 : ev->tracing.se.callback = cb;
180 10625 : 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 1411711 : void tevent_trace_signal_callback(struct tevent_context *ev,
192 : struct tevent_signal *se,
193 : enum tevent_event_trace_point tp)
194 : {
195 1411711 : if (ev->tracing.se.callback != NULL) {
196 10 : ev->tracing.se.callback(se, tp, ev->tracing.se.private_data);
197 : }
198 1411711 : }
199 :
200 10625 : void tevent_set_trace_timer_callback(struct tevent_context *ev,
201 : tevent_trace_timer_callback_t cb,
202 : void *private_data)
203 : {
204 10625 : 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 10625 : ev->tracing.te.callback = cb;
212 10625 : 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 721095484 : void tevent_trace_timer_callback(struct tevent_context *ev,
224 : struct tevent_timer *te,
225 : enum tevent_event_trace_point tp)
226 : {
227 721095484 : if (ev->tracing.te.callback != NULL) {
228 12 : ev->tracing.te.callback(te, tp, ev->tracing.te.private_data);
229 : }
230 721095484 : }
231 :
232 10626 : void tevent_set_trace_immediate_callback(struct tevent_context *ev,
233 : tevent_trace_immediate_callback_t cb,
234 : void *private_data)
235 : {
236 10626 : 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 10626 : ev->tracing.im.callback = cb;
244 10626 : 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 50975698 : void tevent_trace_immediate_callback(struct tevent_context *ev,
256 : struct tevent_immediate *im,
257 : enum tevent_event_trace_point tp)
258 : {
259 50975698 : if (ev->tracing.im.callback != NULL) {
260 20 : ev->tracing.im.callback(im, tp, ev->tracing.im.private_data);
261 : }
262 50975698 : }
263 :
264 10599 : void tevent_set_trace_queue_callback(struct tevent_context *ev,
265 : tevent_trace_queue_callback_t cb,
266 : void *private_data)
267 : {
268 10599 : 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 10599 : ev->tracing.qe.callback = cb;
276 10599 : 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 20134578 : void tevent_trace_queue_callback(struct tevent_context *ev,
288 : struct tevent_queue_entry *qe,
289 : enum tevent_event_trace_point tp)
290 : {
291 20134578 : if (ev->tracing.qe.callback != NULL) {
292 24 : ev->tracing.qe.callback(qe, tp, ev->tracing.qe.private_data);
293 : }
294 20134578 : }
295 :
296 : static __thread size_t *tevent_thread_call_depth_ptr = NULL;
297 :
298 0 : void tevent_thread_call_depth_activate(size_t *ptr)
299 : {
300 0 : tevent_thread_call_depth_ptr = ptr;
301 0 : *tevent_thread_call_depth_ptr = 0;
302 0 : }
303 :
304 0 : void tevent_thread_call_depth_deactivate(void)
305 : {
306 : /* Reset the previous storage */
307 0 : if (tevent_thread_call_depth_ptr != NULL) {
308 0 : *tevent_thread_call_depth_ptr = 0;
309 : }
310 0 : tevent_thread_call_depth_ptr = NULL;
311 0 : }
312 :
313 0 : void tevent_thread_call_depth_start(struct tevent_req *req)
314 : {
315 0 : if (tevent_thread_call_depth_ptr != NULL) {
316 0 : *tevent_thread_call_depth_ptr = req->internal.call_depth = 1;
317 : }
318 0 : }
319 :
320 0 : void tevent_thread_call_depth_reset_from_req(struct tevent_req *req)
321 : {
322 0 : if (tevent_thread_call_depth_ptr != NULL) {
323 0 : *tevent_thread_call_depth_ptr = req->internal.call_depth;
324 : }
325 0 : }
326 :
327 294728987 : _PRIVATE_ void tevent_thread_call_depth_set(size_t depth)
328 : {
329 294728987 : if (tevent_thread_call_depth_ptr != NULL) {
330 0 : *tevent_thread_call_depth_ptr = depth;
331 : }
332 294728987 : }
|