2 Unix SMB/CIFS implementation.
4 Copyright (C) Andrew Tridgell 2003
5 Copyright (C) James J Myers 2003
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 2 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, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "system/filesys.h"
24 #include "dynconfig.h"
26 /* this global variable determines what messages are printed */
30 /* the registered mutex handlers */
36 /* state variables for the debug system */
39 enum debug_logtype logtype;
40 const char *prog_name;
44 the backend for debug messages. Note that the DEBUG() macro has already
45 ensured that the log level has been met before this is called
47 void do_debug(const char *format, ...)
56 if (state.fd <= 0) return;
59 vasprintf(&s, format, ap);
64 write(state.fd, s, strlen(s));
69 reopen the log file (usually called because the log file name might have changed)
71 void reopen_logs(void)
73 const char *logfile = lp_logfile();
75 int old_fd = state.fd;
79 switch (state.logtype) {
89 if ((*logfile) == '/') {
90 fname = strdup(logfile);
92 asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, logfile);
95 state.fd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0644);
107 control the name of the logfile and whether logging will be to stdout, stderr
110 void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
112 state.logtype = new_logtype;
113 state.prog_name = prog_name;
118 return a string constant containing n tabs
119 no more than 10 tabs are returned
121 const char *do_debug_tab(uint_t n)
123 const char *tabs[] = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t",
124 "\t\t\t\t\t\t", "\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t",
125 "\t\t\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t\t\t"};
126 return tabs[MIN(n, 10)];
131 log/print suspicious usage - print comments and backtrace
133 void log_suspicious_usage(const char *from, const char *info)
135 if (debug_handlers.ops.log_suspicious_usage) {
136 debug_handlers.ops.log_suspicious_usage(from, info);
139 void print_suspicious_usage(const char* from, const char* info)
141 if (debug_handlers.ops.print_suspicious_usage) {
142 debug_handlers.ops.print_suspicious_usage(from, info);
146 uint32_t get_task_id(void)
148 if (debug_handlers.ops.get_task_id) {
149 return debug_handlers.ops.get_task_id();
154 void log_task_id(void)
156 if (debug_handlers.ops.log_task_id) {
157 debug_handlers.ops.log_task_id(state.fd);
161 register a set of debug handlers.
163 void register_debug_handlers(const char *name, struct debug_ops *ops)
165 debug_handlers.name = name;
166 debug_handlers.ops = *ops;