3 Pavel Březina <pbrezina@redhat.com>
5 Copyright (C) 2021 Red Hat
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "lib/util/debug.h"
22 #include "winbindd_traceid.h"
25 static void debug_traceid_trace_fde(struct tevent_fd
*fde
,
26 enum tevent_event_trace_point point
,
30 case TEVENT_EVENT_TRACE_ATTACH
:
31 /* Assign the current traceid id when the event is created. */
32 tevent_fd_set_tag(fde
, debug_traceid_get());
34 case TEVENT_EVENT_TRACE_BEFORE_HANDLER
:
35 /* Set the traceid id when a handler is being called. */
36 debug_traceid_set(tevent_fd_get_tag(fde
));
44 static void debug_traceid_trace_signal(struct tevent_signal
*se
,
45 enum tevent_event_trace_point point
,
49 case TEVENT_EVENT_TRACE_ATTACH
:
50 /* Assign the current traceid id when the event is created. */
51 tevent_signal_set_tag(se
, debug_traceid_get());
53 case TEVENT_EVENT_TRACE_BEFORE_HANDLER
:
54 /* Set the traceid id when a handler is being called. */
55 debug_traceid_set(tevent_signal_get_tag(se
));
63 static void debug_traceid_trace_timer(struct tevent_timer
*timer
,
64 enum tevent_event_trace_point point
,
68 case TEVENT_EVENT_TRACE_ATTACH
:
69 /* Assign the current traceid id when the event is created. */
70 tevent_timer_set_tag(timer
, debug_traceid_get());
72 case TEVENT_EVENT_TRACE_BEFORE_HANDLER
:
73 /* Set the traceid id when a handler is being called. */
74 debug_traceid_set(tevent_timer_get_tag(timer
));
82 static void debug_traceid_trace_immediate(struct tevent_immediate
*im
,
83 enum tevent_event_trace_point point
,
87 case TEVENT_EVENT_TRACE_ATTACH
:
88 /* Assign the current traceid id when the event is created. */
89 tevent_immediate_set_tag(im
, debug_traceid_get());
91 case TEVENT_EVENT_TRACE_BEFORE_HANDLER
:
92 /* Set the traceid id when a handler is being called. */
93 debug_traceid_set(tevent_immediate_get_tag(im
));
101 static void debug_traceid_trace_queue(struct tevent_queue_entry
*qe
,
102 enum tevent_event_trace_point point
,
106 case TEVENT_EVENT_TRACE_ATTACH
:
107 /* Assign the current traceid id when the event is created. */
108 tevent_queue_entry_set_tag(qe
, debug_traceid_get());
110 case TEVENT_EVENT_TRACE_BEFORE_HANDLER
:
111 /* Set the traceid id when a handler is being called. */
112 debug_traceid_set(tevent_queue_entry_get_tag(qe
));
120 static void debug_traceid_trace_loop(enum tevent_trace_point point
,
124 case TEVENT_TRACE_AFTER_LOOP_ONCE
:
125 /* Reset traceid id when we got back to the loop. An event handler
126 * that set traceid id was fired. This tracepoint represents a place
127 * after the event handler was finished, we need to restore traceid
128 * id to 1 (out of request). 0 means not initialized.
130 debug_traceid_set(1);
138 void winbind_debug_traceid_setup(struct tevent_context
*ev
)
140 tevent_set_trace_callback(ev
, debug_traceid_trace_loop
, NULL
);
141 tevent_set_trace_fd_callback(ev
, debug_traceid_trace_fde
, NULL
);
142 tevent_set_trace_signal_callback(ev
, debug_traceid_trace_signal
, NULL
);
143 tevent_set_trace_timer_callback(ev
, debug_traceid_trace_timer
, NULL
);
144 tevent_set_trace_immediate_callback(ev
, debug_traceid_trace_immediate
, NULL
);
145 tevent_set_trace_queue_callback(ev
, debug_traceid_trace_queue
, NULL
);
146 debug_traceid_set(1);