ctdb-server: Use find_public_ip_vnn() in a couple of extra places
[samba4-gss.git] / lib / util / tevent_debug.c
blob996f49598ea163c1a4d223fa2976c431a65ad8de
1 /*
2 Unix SMB/CIFS implementation.
3 Copyright (C) Andrew Tridgell 2003
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "replace.h"
20 #include <tevent.h>
21 #include "lib/util/debug.h"
22 #include "lib/util/samba_util.h"
24 #undef DBGC_CLASS
25 #define DBGC_CLASS DBGC_TEVENT
27 static void samba_tevent_debug(void *context,
28 enum tevent_debug_level level,
29 const char *fmt,
30 va_list ap) PRINTF_ATTRIBUTE(3,0);
32 static void samba_tevent_debug(void *context,
33 enum tevent_debug_level level,
34 const char *fmt,
35 va_list ap)
37 int samba_level = -1;
39 switch (level) {
40 case TEVENT_DEBUG_FATAL:
41 samba_level = 0;
42 break;
43 case TEVENT_DEBUG_ERROR:
44 samba_level = 1;
45 break;
46 case TEVENT_DEBUG_WARNING:
47 samba_level = 2;
48 break;
49 case TEVENT_DEBUG_TRACE:
50 samba_level = 50;
51 break;
54 if (CHECK_DEBUGLVL(samba_level)) {
55 const char *name = (const char *)context;
56 char *message = NULL;
57 int ret;
59 ret = vasprintf(&message, fmt, ap);
60 if (ret == -1) {
61 return;
64 if (name == NULL) {
65 name = "samba_tevent";
68 DEBUG(samba_level, ("%s: %s", name, message));
69 free(message);
73 static void samba_tevent_abort_fn(const char *reason)
75 smb_panic(reason);
78 static void samba_tevent_setup_abort_fn(void)
80 static bool abort_fn_done;
82 if (!abort_fn_done) {
83 tevent_set_abort_fn(samba_tevent_abort_fn);
84 abort_fn_done = true;
88 void samba_tevent_set_debug(struct tevent_context *ev, const char *name)
90 void *p = discard_const(name);
91 samba_tevent_setup_abort_fn();
92 tevent_set_debug(ev, samba_tevent_debug, p);
94 /* these values should match samba_tevent_debug() */
95 if (CHECK_DEBUGLVL(50)) {
96 tevent_set_max_debug_level(ev, TEVENT_DEBUG_TRACE);
97 } else if (CHECK_DEBUGLVL(2)) {
98 tevent_set_max_debug_level(ev, TEVENT_DEBUG_WARNING);
99 } else if (CHECK_DEBUGLVL(1)) {
100 tevent_set_max_debug_level(ev, TEVENT_DEBUG_ERROR);
101 } else {
102 tevent_set_max_debug_level(ev, TEVENT_DEBUG_FATAL);
106 struct tevent_context *samba_tevent_context_init(TALLOC_CTX *mem_ctx)
108 struct tevent_context *ev;
110 samba_tevent_setup_abort_fn();
112 ev = tevent_context_init(mem_ctx);
113 if (ev) {
114 samba_tevent_set_debug(ev, NULL);
117 return ev;