summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/util/debug.c (renamed from source3/lib/debug.c)511
-rw-r--r--lib/util/debug.h (renamed from source3/include/debug.h)169
-rw-r--r--lib/util/debug_s3.c105
-rw-r--r--lib/util/debug_s3.h23
-rw-r--r--lib/util/debug_s4.c273
-rw-r--r--lib/util/debug_s4.h150
-rw-r--r--lib/util/wscript_build8
-rw-r--r--source3/Makefile.in2
-rw-r--r--source3/include/includes.h2
-rw-r--r--source3/include/local.h5
-rw-r--r--source3/include/smb.h3
-rw-r--r--source3/pam_smbpass/pam_smb_auth.c2
-rw-r--r--source3/param/loadparm.c1
-rw-r--r--source3/wscript_build2
-rw-r--r--source4/include/includes.h2
-rw-r--r--source4/param/loadparm.c30
16 files changed, 462 insertions, 826 deletions
diff --git a/source3/lib/debug.c b/lib/util/debug.c
index 1ec79cd25b..d2f3d922ae 100644
--- a/source3/lib/debug.c
+++ b/lib/util/debug.c
@@ -20,7 +20,14 @@
*/
#include "includes.h"
-#include "librpc/gen_ndr/messaging.h"
+#include "system/filesys.h"
+#include "system/syslog.h"
+#include "lib/util/time.h"
+
+/* define what facility to use for syslog */
+#ifndef SYSLOG_FACILITY
+#define SYSLOG_FACILITY LOG_DAEMON
+#endif
/* -------------------------------------------------------------------------- **
* Defines...
@@ -72,11 +79,20 @@
/* state variables for the debug system */
static struct {
+ bool initialized;
int fd; /* The log file handle */
enum debug_logtype logtype; /* The type of logging we are doing: eg stdout, file, stderr */
const char *prog_name;
bool reopening_logs;
-} state;
+ bool schedule_reopen_logs;
+
+ struct debug_settings settings;
+ char *debugf;
+} state = {
+ .settings = {
+ .timestamp_logs = true
+ }
+};
/* -------------------------------------------------------------------------- **
* External variables.
@@ -86,10 +102,6 @@ static struct {
* levels higher than DEBUGLEVEL will not be processed.
*/
-static char *debugf = NULL;
-bool debug_warn_unknown_class = true;
-bool debug_auto_add_unknown_class = true;
-
/*
used to check if the user specified a
logfile on the command line
@@ -97,18 +109,13 @@ bool debug_auto_add_unknown_class = true;
bool override_logfile;
/*
- * This is to allow assignment to DEBUGLEVEL before the debug
+ * This is to allow reading of DEBUGLEVEL_CLASS before the debug
* system has been initialized.
*/
-static int debug_all_class_hack = 1;
-static bool debug_all_class_isset_hack = true;
+static const int debug_class_list_initial[DBGC_MAX_FIXED + 1];
static int debug_num_classes = 0;
-int *DEBUGLEVEL_CLASS = &debug_all_class_hack;
-bool *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack;
-
-/* DEBUGLEVEL is #defined to *debug_level */
-int DEBUGLEVEL = &debug_all_class_hack;
+int *DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
/* -------------------------------------------------------------------------- **
@@ -126,7 +133,7 @@ int DEBUGLEVEL = &debug_all_class_hack;
* to build the formatted output.
*
* format_pos - Marks the first free byte of the format_bufr.
- *
+ *
*
* log_overflow - When this variable is true, never attempt to check the
* size of the log. This is a hack, so that we can write
@@ -143,9 +150,9 @@ static size_t format_pos = 0;
static bool log_overflow = false;
/*
- * Define all the debug class selection names here. Names *MUST NOT* contain
- * white space. There must be one name for each DBGC_<class name>, and they
- * must be in the table in the order of DBGC_<class name>..
+ * Define all the debug class selection names here. Names *MUST NOT* contain
+ * white space. There must be one name for each DBGC_<class name>, and they
+ * must be in the table in the order of DBGC_<class name>..
*/
static const char *default_classname_table[] = {
"all", /* DBGC_ALL; index refs traditional DEBUGLEVEL */
@@ -178,116 +185,48 @@ static char **classname_table = NULL;
* Functions...
*/
+static void debug_init(void);
+
/***************************************************************************
Free memory pointed to by global pointers.
****************************************************************************/
-static bool initialized;
-
void gfree_debugsyms(void)
{
- int i;
-
- if ( classname_table ) {
- for ( i = 0; i < debug_num_classes; i++ ) {
- SAFE_FREE( classname_table[i] );
- }
- SAFE_FREE( classname_table );
- }
-
- if ( DEBUGLEVEL_CLASS != &debug_all_class_hack ) {
- SAFE_FREE( DEBUGLEVEL_CLASS );
- DEBUGLEVEL_CLASS = &debug_all_class_hack;
- }
+ TALLOC_FREE(classname_table);
- if ( DEBUGLEVEL_CLASS_ISSET != &debug_all_class_isset_hack ) {
- SAFE_FREE( DEBUGLEVEL_CLASS_ISSET );
- DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack;
+ if ( DEBUGLEVEL_CLASS != debug_class_list_initial ) {
+ TALLOC_FREE( DEBUGLEVEL_CLASS );
+ DEBUGLEVEL_CLASS = discard_const_p(int, debug_class_list_initial);
}
- SAFE_FREE(format_bufr);
+ TALLOC_FREE(format_bufr);
- debug_num_classes = 0;
+ debug_num_classes = DBGC_MAX_FIXED;
- debug_level = DEBUGLEVEL_CLASS;
-
- initialized = false;
+ state.initialized = false;
}
/****************************************************************************
utility lists registered debug class names's
****************************************************************************/
-#define MAX_CLASS_NAME_SIZE 1024
-
-static char *debug_list_class_names_and_levels(void)
+char *debug_list_class_names_and_levels(void)
{
- int i, dim;
- char **list;
char *buf = NULL;
- char *b;
- bool err = false;
-
- if (DEBUGLEVEL_CLASS == &debug_all_class_hack) {
- return NULL;
- }
-
- list = SMB_CALLOC_ARRAY(char *, debug_num_classes + 1);
- if (!list) {
- return NULL;
- }
-
+ unsigned int i;
/* prepare strings */
- for (i = 0, dim = 0; i < debug_num_classes; i++) {
- int l = asprintf(&list[i],
- "%s:%d ",
- classname_table[i],
- DEBUGLEVEL_CLASS_ISSET[i]?DEBUGLEVEL_CLASS[i]:DEBUGLEVEL);
- if (l < 0 || l > MAX_CLASS_NAME_SIZE) {
- err = true;
- goto done;
- }
- dim += l;
- }
-
- /* create single string list - add space for newline */
- b = buf = (char *)SMB_MALLOC(dim+1);
- if (!buf) {
- err = true;
- goto done;
- }
- for (i = 0; i < debug_num_classes; i++) {
- int l = strlen(list[i]);
- strncpy(b, list[i], l);
- b = b + l;
- }
- b[-1] = '\n'; /* replace last space with newline */
- b[0] = '\0'; /* null terminate string */
-
-done:
- /* free strings list */
for (i = 0; i < debug_num_classes; i++) {
- SAFE_FREE(list[i]);
- }
- SAFE_FREE(list);
-
- if (err) {
- return NULL;
- } else {
- return buf;
+ buf = talloc_asprintf_append(buf,
+ "%s:%d%s",
+ classname_table[i],
+ DEBUGLEVEL_CLASS[i],
+ i == (debug_num_classes - 1) ? "\n" : " ");
+ if (buf == NULL) {
+ return NULL;
+ }
}
-}
-
-/****************************************************************************
- Utility access to debug class names's.
-****************************************************************************/
-
-const char *debug_classname_from_index(int ndx)
-{
- if (ndx < 0 || ndx >= debug_num_classes)
- return NULL;
- else
- return classname_table[ndx];
+ return buf;
}
/****************************************************************************
@@ -314,7 +253,8 @@ static int debug_lookup_classname_int(const char* classname)
int debug_add_class(const char *classname)
{
int ndx;
- void *new_ptr;
+ int *new_class_list;
+ char **new_name_list;
if (!classname)
return -1;
@@ -327,44 +267,30 @@ int debug_add_class(const char *classname)
return ndx;
ndx = debug_num_classes;
- new_ptr = DEBUGLEVEL_CLASS;
- if (DEBUGLEVEL_CLASS == &debug_all_class_hack) {
+ if (DEBUGLEVEL_CLASS == debug_class_list_initial) {
/* Initial loading... */
- new_ptr = NULL;
- }
- new_ptr = SMB_REALLOC_ARRAY(new_ptr, int, debug_num_classes + 1);
- if (!new_ptr)
- return -1;
- DEBUGLEVEL_CLASS = (int *)new_ptr;
- DEBUGLEVEL_CLASS[ndx] = 0;
-
- /* debug_level is the pointer used for the DEBUGLEVEL-thingy */
- if (ndx==0) {
- /* Transfer the initial level from debug_all_class_hack */
- DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL;
+ new_class_list = NULL;
+ } else {
+ new_class_list = DEBUGLEVEL_CLASS;
}
- debug_level = DEBUGLEVEL_CLASS;
- new_ptr = DEBUGLEVEL_CLASS_ISSET;
- if (new_ptr == &debug_all_class_isset_hack) {
- new_ptr = NULL;
- }
- new_ptr = SMB_REALLOC_ARRAY(new_ptr, bool, debug_num_classes + 1);
- if (!new_ptr)
+ new_class_list = talloc_realloc(NULL, new_class_list, int, ndx + 1);
+ if (!new_class_list)
return -1;
- DEBUGLEVEL_CLASS_ISSET = (bool *)new_ptr;
- DEBUGLEVEL_CLASS_ISSET[ndx] = false;
+ DEBUGLEVEL_CLASS = new_class_list;
- new_ptr = SMB_REALLOC_ARRAY(classname_table, char *, debug_num_classes + 1);
- if (!new_ptr)
+ DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL_CLASS[DBGC_ALL];
+
+ new_name_list = talloc_realloc(NULL, classname_table, char *, ndx + 1);
+ if (!new_name_list)
return -1;
- classname_table = (char **)new_ptr;
+ classname_table = new_name_list;
- classname_table[ndx] = SMB_STRDUP(classname);
+ classname_table[ndx] = talloc_strdup(classname_table, classname);
if (! classname_table[ndx])
return -1;
-
- debug_num_classes++;
+
+ debug_num_classes = ndx + 1;
return ndx;
}
@@ -376,7 +302,7 @@ int debug_add_class(const char *classname)
int debug_lookup_classname(const char *classname)
{
int ndx;
-
+
if (!classname || !*classname)
return -1;
@@ -385,14 +311,9 @@ int debug_lookup_classname(const char *classname)
if (ndx != -1)
return ndx;
- if (debug_warn_unknown_class) {
- DEBUG(0, ("debug_lookup_classname(%s): Unknown class\n",
- classname));
- }
- if (debug_auto_add_unknown_class) {
- return debug_add_class(classname);
- }
- return -1;
+ DEBUG(0, ("debug_lookup_classname(%s): Unknown class\n",
+ classname));
+ return debug_add_class(classname);
}
/****************************************************************************
@@ -405,10 +326,9 @@ static void debug_dump_status(int level)
DEBUG(level, ("INFO: Current debug levels:\n"));
for (q = 0; q < debug_num_classes; q++) {
- DEBUGADD(level, (" %s: %s/%d\n",
- classname_table[q],
- (DEBUGLEVEL_CLASS_ISSET[q]
- ? "True" : "False"),
+ const char *classname = classname_table[q];
+ DEBUGADD(level, (" %s: %d\n",
+ classname,
DEBUGLEVEL_CLASS[q]));
}
}
@@ -427,17 +347,22 @@ static bool debug_parse_params(char **params)
if (!params)
return false;
- /* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10"
- * v.s. "all:10", this is the traditional way to set DEBUGLEVEL
+ /* Allow DBGC_ALL to be specified w/o requiring its class name e.g."10"
+ * v.s. "all:10", this is the traditional way to set DEBUGLEVEL
*/
if (isdigit((int)params[0][0])) {
DEBUGLEVEL_CLASS[DBGC_ALL] = atoi(params[0]);
- DEBUGLEVEL_CLASS_ISSET[DBGC_ALL] = true;
i = 1; /* start processing at the next params */
} else {
+ DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
i = 0; /* DBGC_ALL not specified OR class name was included */
}
+ /* Array is debug_num_classes long */
+ for (ndx = DBGC_ALL; ndx < debug_num_classes; ndx++) {
+ DEBUGLEVEL_CLASS[ndx] = DEBUGLEVEL_CLASS[DBGC_ALL];
+ }
+
/* Fill in new debug class levels */
for (; i < debug_num_classes && params[i]; i++) {
char *saveptr;
@@ -445,7 +370,6 @@ static bool debug_parse_params(char **params)
(class_level = strtok_r(NULL, "\0", &saveptr)) &&
((ndx = debug_lookup_classname(class_name)) != -1)) {
DEBUGLEVEL_CLASS[ndx] = atoi(class_level);
- DEBUGLEVEL_CLASS_ISSET[ndx] = true;
} else {
DEBUG(0,("debug_parse_params: unrecognized debug class name or format [%s]\n", params[i]));
return false;
@@ -468,7 +392,7 @@ bool debug_parse_levels(const char *params_str)
/* Just in case */
debug_init();
- params = str_list_make_v3(talloc_tos(), params_str, NULL);
+ params = str_list_make(NULL, params_str, NULL);
if (debug_parse_params(params)) {
debug_dump_status(5);
@@ -480,85 +404,48 @@ bool debug_parse_levels(const char *params_str)
}
}
-/****************************************************************************
- Receive a "set debug level" message.
-****************************************************************************/
-
-void debug_message(struct messaging_context *msg_ctx,
- void *private_data,
- uint32_t msg_type,
- struct server_id src,
- DATA_BLOB *data)
+/* setup for logging of talloc warnings */
+static void talloc_log_fn(const char *msg)
{
- const char *params_str = (const char *)data->data;
-
- /* Check, it's a proper string! */
- if (params_str[(data->length)-1] != '\0') {
- DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
- (unsigned int)procid_to_pid(&src),
- (unsigned int)getpid()));
- return;
- }
-
- DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n",
- params_str, (unsigned int)getpid(),
- (unsigned int)procid_to_pid(&src)));
-
- debug_parse_levels(params_str);
+ DEBUG(0,("%s", msg));
}
-/****************************************************************************
- Return current debug level.
-****************************************************************************/
-
-static void debuglevel_message(struct messaging_context *msg_ctx,
- void *private_data,
- uint32_t msg_type,
- struct server_id src,
- DATA_BLOB *data)
+void debug_setup_talloc_log(void)
{
- char *message = debug_list_class_names_and_levels();
-
- if (!message) {
- DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
- return;
- }
-
- DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %s\n",
- procid_str_static(&src)));
- messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL,
- (uint8 *)message, strlen(message) + 1);
-
- SAFE_FREE(message);
+ talloc_set_log_fn(talloc_log_fn);
}
+
/****************************************************************************
Init debugging (one time stuff)
****************************************************************************/
-void debug_init(void)
+static void debug_init(void)
{
const char **p;
- if (initialized)
+ if (state.initialized)
return;
- initialized = true;
+ state.initialized = true;
+
+ debug_setup_talloc_log();
for(p = default_classname_table; *p; p++) {
debug_add_class(*p);
}
- format_bufr = (char *)SMB_MALLOC(FORMAT_BUFR_SIZE);
+ format_bufr = talloc_array(NULL, char, FORMAT_BUFR_SIZE);
if (!format_bufr) {
smb_panic("debug_init: unable to create buffer");
}
}
-void debug_register_msgs(struct messaging_context *msg_ctx)
+/* This forces in some smb.conf derived values into the debug system.
+ * There are no pointers in this structure, so we can just
+ * structure-assign it in */
+void debug_set_settings(struct debug_settings *settings)
{
- messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
- messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
- debuglevel_message);
+ state.settings = *settings;
}
/**
@@ -580,7 +467,7 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
if (prog_name) {
state.prog_name = prog_name;
}
- reopen_logs();
+ reopen_logs_internal();
if (state.logtype == DEBUG_FILE) {
#ifdef WITH_SYSLOG
@@ -603,8 +490,8 @@ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
void debug_set_logfile(const char *name)
{
- SAFE_FREE(debugf);
- debugf = SMB_STRDUP(name);
+ TALLOC_FREE(state.debugf);
+ state.debugf = talloc_strdup(NULL, name);
}
static void debug_close_fd(int fd)
@@ -630,7 +517,7 @@ bool debug_get_output_is_stderr(void)
/**
reopen the log file (usually called because the log file name might have changed)
*/
-bool reopen_logs(void)
+bool reopen_logs_internal(void)
{
mode_t oldumask;
int new_fd = 0;
@@ -642,6 +529,9 @@ bool reopen_logs(void)
return true;
}
+ /* Now clear the SIGHUP induced flag */
+ state.schedule_reopen_logs = false;
+
switch (state.logtype) {
case DEBUG_STDOUT:
debug_close_fd(state.fd);
@@ -660,31 +550,18 @@ bool reopen_logs(void)
oldumask = umask( 022 );
- fname = debugf;
+ fname = state.debugf;
if (!fname) {
return false;
}
- debugf = NULL;
-
- if (lp_loaded()) {
- char *logfname;
- logfname = lp_logfile();
- if (*logfname) {
- SAFE_FREE(fname);
- fname = SMB_STRDUP(logfname);
- if (!fname) {
- return false;
- }
- }
- }
+ state.reopening_logs = true;
- debugf = fname;
- new_fd = open( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644);
+ new_fd = open( state.debugf, O_WRONLY|O_APPEND|O_CREAT, 0644);
if (new_fd == -1) {
log_overflow = true;
- DEBUG(0, ("Unable to open new log file %s: %s\n", debugf, strerror(errno)));
+ DEBUG(0, ("Unable to open new log file %s: %s\n", state.debugf, strerror(errno)));
log_overflow = false;
ret = false;
} else {
@@ -706,6 +583,8 @@ bool reopen_logs(void)
at the logfile */
}
+ state.reopening_logs = false;
+
return ret;
}
@@ -718,6 +597,12 @@ void force_check_log_size( void )
debug_count = 100;
}
+_PUBLIC_ void debug_schedule_reopen_logs(void)
+{
+ state.schedule_reopen_logs = true;
+}
+
+
/***************************************************************************
Check to see if there is any need to check if the logfile has grown too big.
**************************************************************************/
@@ -726,11 +611,11 @@ bool need_to_check_log_size( void )
{
int maxlog;
- if( debug_count < 100 )
+ if( debug_count < 100)
return( false );
- maxlog = lp_max_log_size() * 1024;
- if ( state.fd > 0 || maxlog <= 0 ) {
+ maxlog = state.settings.max_log_size * 1024;
+ if ( state.fd <=2 || maxlog <= 0 ) {
debug_count = 0;
return(false);
}
@@ -744,37 +629,46 @@ bool need_to_check_log_size( void )
void check_log_size( void )
{
int maxlog;
- SMB_STRUCT_STAT st;
+ struct stat st;
/*
* We need to be root to check/change log-file, skip this and let the main
* loop check do a new check as root.
*/
- if( geteuid() != sec_initial_uid() )
+ if( geteuid() != 0) {
+ /* We don't check sec_initial_uid() here as it isn't
+ * available in common code and we don't generally
+ * want to rotate and the possibly lose logs in
+ * make test or the build farm */
return;
+ }
- if(log_overflow || !need_to_check_log_size() )
+ if(log_overflow || (!state.schedule_reopen_logs && !need_to_check_log_size())) {
return;
+ }
- maxlog = lp_max_log_size() * 1024;
-
- if(sys_fstat(state.fd, &st, false) == 0
- && st.st_ex_size > maxlog ) {
- (void)reopen_logs();
- if( state.fd > 0 && get_file_size( debugf ) > maxlog ) {
- char *name = NULL;
-
- if (asprintf(&name, "%s.old", debugf ) < 0) {
- return;
- }
- (void)rename(debugf, name);
-
- if (!reopen_logs()) {
- /* We failed to reopen a log - continue using the old name. */
- (void)rename(name, debugf);
+ maxlog = state.settings.max_log_size * 1024;
+
+ if (state.schedule_reopen_logs ||
+ (fstat(state.fd, &st) == 0
+ && st.st_size > maxlog )) {
+ (void)reopen_logs_internal();
+ if (state.fd > 0 && fstat(state.fd, &st) == 0) {
+ if (st.st_size > maxlog) {
+ char *name = NULL;
+
+ if (asprintf(&name, "%s.old", state.debugf ) < 0) {
+ return;
+ }
+ (void)rename(state.debugf, name);
+
+ if (!reopen_logs_internal()) {
+ /* We failed to reopen a log - continue using the old name. */
+ (void)rename(name, state.debugf);
+ }
+ SAFE_FREE(name);
}
- SAFE_FREE(name);
}
}
@@ -794,7 +688,7 @@ void check_log_size( void )
if (fd != -1) {
state.fd = fd;
DEBUG(0,("check_log_size: open of debug file %s failed - using console.\n",
- debugf ));
+ state.debugf ));
} else {
/*
* We cannot continue without a debug file handle.
@@ -826,18 +720,13 @@ void check_log_size( void )
goto done;
}
- /* prevent recursion by checking if reopen_logs() has temporaily
- set the debugf string to NULL */
- if( debugf == NULL)
- goto done;
-
#ifdef WITH_SYSLOG
- if( !lp_syslog_only() )
+ if( !state.settings.syslog_only)
#endif
{
if( state.fd <= 0 ) {
mode_t oldumask = umask( 022 );
- int fd = open( debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 );
+ int fd = open( state.debugf, O_WRONLY|O_APPEND|O_CREAT, 0644 );
(void)umask( oldumask );
if(fd == -1) {
errno = old_errno;
@@ -848,7 +737,7 @@ void check_log_size( void )
}
#ifdef WITH_SYSLOG
- if( syslog_level < lp_syslog() ) {
+ if( syslog_level < state.settings.syslog ) {
/* map debug levels to syslog() priorities
* note that not all DEBUG(0, ...) calls are
* necessarily errors */
@@ -887,7 +776,7 @@ void check_log_size( void )
check_log_size();
#ifdef WITH_SYSLOG
- if( !lp_syslog_only() )
+ if( !state.settings.syslog_only)
#endif
{
va_start( ap, format_str );
@@ -935,7 +824,7 @@ static void bufr_print( void )
static void format_debug_text( const char *msg )
{
size_t i;
- bool timestamp = (state.logtype == DEBUG_FILE && (lp_timestamp_logs() || !(lp_loaded())));
+ bool timestamp = (state.logtype == DEBUG_FILE && (state.settings.timestamp_logs));
if (!format_bufr) {
debug_init();
@@ -1035,42 +924,46 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
/* Print the header if timestamps are turned on. If parameters are
* not yet loaded, then default to timestamps on.
*/
- if( lp_timestamp_logs() || lp_debug_prefix_timestamp() || !(lp_loaded()) ) {
+ if( state.settings.timestamp_logs || state.settings.debug_prefix_timestamp) {
char header_str[200];
header_str[0] = '\0';
- if( lp_debug_pid())
- slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)sys_getpid());
+ if( state.settings.debug_pid)
+ slprintf(header_str,sizeof(header_str)-1,", pid=%u",(unsigned int)getpid());
- if( lp_debug_uid()) {
+ if( state.settings.debug_uid) {
size_t hs_len = strlen(header_str);
slprintf(header_str + hs_len,
sizeof(header_str) - 1 - hs_len,
", effective(%u, %u), real(%u, %u)",
(unsigned int)geteuid(), (unsigned int)getegid(),
- (unsigned int)getuid(), (unsigned int)getgid());
+ (unsigned int)getuid(), (unsigned int)getgid());
}
- if (lp_debug_class() && (cls != DBGC_ALL)) {
+ if (state.settings.debug_class && (cls != DBGC_ALL)) {
size_t hs_len = strlen(header_str);
slprintf(header_str + hs_len,
sizeof(header_str) -1 - hs_len,
", class=%s",
default_classname_table[cls]);
}
-
+
/* Print it all out at once to prevent split syslog output. */
- if( lp_debug_prefix_timestamp() ) {
- (void)Debug1( "[%s, %2d%s] ",
- current_timestring(talloc_tos(),
- lp_debug_hires_timestamp()),
- level, header_str);
+ if( state.settings.debug_prefix_timestamp ) {
+ char *time_str = current_timestring(NULL,
+ state.settings.debug_hires_timestamp);
+ (void)Debug1( "[%s, %2d%s] ",
+ time_str,
+ level, header_str);
+ talloc_free(time_str);
} else {
- (void)Debug1( "[%s, %2d%s] %s(%s)\n",
- current_timestring(talloc_tos(),
- lp_debug_hires_timestamp()),
- level, header_str, location, func );
+ char *time_str = current_timestring(NULL,
+ state.settings.debug_hires_timestamp);
+ (void)Debug1( "[%s, %2d%s] %s(%s)\n",
+ time_str,
+ level, header_str, location, func );
+ talloc_free(time_str);
}
}
@@ -1078,12 +971,6 @@ bool dbghdrclass(int level, int cls, const char *location, const char *func)
return( true );
}
-bool dbghdr(int level, const char *location, const char *func)
-{
- /* For compatibility with Samba 4, which doesn't have debug classes */
- return dbghdrclass(level, 0, location, func);
-}
-
/***************************************************************************
Add text to the body of the "current" debug message via the format buffer.
@@ -1116,3 +1003,57 @@ bool dbghdr(int level, const char *location, const char *func)
SAFE_FREE(msgbuf);
return ret;
}
+
+
+/* the registered mutex handlers */
+static struct {
+ const char *name;
+ struct debug_ops ops;
+} debug_handlers;
+
+/**
+ log suspicious usage - print comments and backtrace
+*/
+_PUBLIC_ void log_suspicious_usage(const char *from, const char *info)
+{
+ if (!debug_handlers.ops.log_suspicious_usage) return;
+
+ debug_handlers.ops.log_suspicious_usage(from, info);
+}
+
+
+/**
+ print suspicious usage - print comments and backtrace
+*/
+_PUBLIC_ void print_suspicious_usage(const char* from, const char* info)
+{
+ if (!debug_handlers.ops.print_suspicious_usage) return;
+
+ debug_handlers.ops.print_suspicious_usage(from, info);
+}
+
+_PUBLIC_ uint32_t get_task_id(void)
+{
+ if (debug_handlers.ops.get_task_id) {
+ return debug_handlers.ops.get_task_id();
+ }
+ return getpid();
+}
+
+_PUBLIC_ void log_task_id(void)
+{
+ if (!debug_handlers.ops.log_task_id) return;
+
+ if (!reopen_logs_internal()) return;
+
+ debug_handlers.ops.log_task_id(state.fd);
+}
+
+/**
+ register a set of debug handlers.
+*/
+_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops)
+{
+ debug_handlers.name = name;
+ debug_handlers.ops = *ops;
+}
diff --git a/source3/include/debug.h b/lib/util/debug.h
index 328bfb63b9..c01fa928b5 100644
--- a/source3/include/debug.h
+++ b/lib/util/debug.h
@@ -36,48 +36,16 @@
#define MAX_DEBUG_LEVEL 1000
#endif
-/* mkproto.awk has trouble with ifdef'd function definitions (it ignores
- * the #ifdef directive and will read both definitions, thus creating two
- * diffferent prototype declarations), so we must do these by hand.
- */
-/* I know the __attribute__ stuff is ugly, but it does ensure we get the
- arguments to DEBUG() right. We have got them wrong too often in the
- past.
- The PRINTFLIKE comment does the equivalent for SGI MIPSPro.
- */
-/* PRINTFLIKE1 */
int Debug1( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
-/* PRINTFLIKE1 */
bool dbgtext( const char *, ... ) PRINTF_ATTRIBUTE(1,2);
bool dbghdrclass( int level, int cls, const char *location, const char *func);
bool dbghdr( int level, const char *location, const char *func);
-#if defined(sgi) && (_COMPILER_VERSION >= 730)
-#pragma mips_frequency_hint NEVER Debug1
-#pragma mips_frequency_hint NEVER dbgtext
-#pragma mips_frequency_hint NEVER dbghdrclass
-#pragma mips_frequency_hint NEVER dbghdr
-#endif
-
-/* If we have these macros, we can add additional info to the header. */
-
-#ifdef HAVE_FUNCTION_MACRO
-#define FUNCTION_MACRO (__FUNCTION__)
-#else
-#define FUNCTION_MACRO ("")
-#endif
-
-/*
+/*
* Redefine DEBUGLEVEL because so we don't have to change every source file
- * that *unnecessarily* references it. Source files neeed not extern reference
- * DEBUGLEVEL, as it's extern in includes.h (which all source files include).
- * Eventually, all these references should be removed, and all references to
- * DEBUGLEVEL should be references to DEBUGLEVEL_CLASS[DBGC_ALL]. This could
- * still be through a macro still called DEBUGLEVEL. This cannot be done now
- * because some references would expand incorrectly.
+ * that *unnecessarily* references it.
*/
-#define DEBUGLEVEL *debug_level
-extern int DEBUGLEVEL;
+#define DEBUGLEVEL DEBUGLEVEL_CLASS[DBGC_ALL]
/*
* Define all new debug classes here. A class is represented by an entry in
@@ -88,7 +56,7 @@ extern int DEBUGLEVEL;
* #define DBGC_CLASS DBGC_<your class name here>
*
* at the start of the file (after #include "includes.h") will default to
- * using index zero, so it will behaive just like it always has.
+ * using index zero, so it will behaive just like it always has.
*/
#define DBGC_ALL 0 /* index equivalent to DEBUGLEVEL */
@@ -112,47 +80,41 @@ extern int DEBUGLEVEL;
#define DBGC_DMAPI 18
#define DBGC_REGISTRY 19
+/* Always ensure this is updated when new fixed classes area added, to ensure the array in debug.c is the right size */
+#define DBGC_MAX_FIXED 19
+
/* So you can define DBGC_CLASS before including debug.h */
#ifndef DBGC_CLASS
#define DBGC_CLASS 0 /* override as shown above */
#endif
extern int *DEBUGLEVEL_CLASS;
-extern bool *DEBUGLEVEL_CLASS_ISSET;
/* Debugging macros
*
* DEBUGLVL()
- * If the 'file specific' debug class level >= level OR the system-wide
+ * If the 'file specific' debug class level >= level OR the system-wide
* DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
- * generate a header using the default macros for file, line, and
+ * generate a header using the default macros for file, line, and
* function name. Returns True if the debug level was <= DEBUGLEVEL.
- *
- * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
*
- * DEBUGLVLC()
- * If the 'macro specified' debug class level >= level OR the system-wide
- * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
- * generate a header using the default macros for file, line, and
- * function name. Returns True if the debug level was <= DEBUGLEVEL.
- *
- * Example: if( DEBUGLVLC( DBGC_TDB, 2 ) ) dbgtext( "Some text.\n" );
+ * Example: if( DEBUGLVL( 2 ) ) dbgtext( "Some text.\n" );
*
* DEBUG()
- * If the 'file specific' debug class level >= level OR the system-wide
- * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
- * generate a header using the default macros for file, line, and
- * function name. Each call to DEBUG() generates a new header *unless* the
+ * If the 'file specific' debug class level >= level OR the system-wide
+ * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
+ * generate a header using the default macros for file, line, and
+ * function name. Each call to DEBUG() generates a new header *unless* the
* previous debug output was unterminated (i.e. no '\n').
* See debug.c:dbghdr() for more info.
*
* Example: DEBUG( 2, ("Some text and a value %d.\n", value) );
*
* DEBUGC()
- * If the 'macro specified' debug class level >= level OR the system-wide
- * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
- * generate a header using the default macros for file, line, and
- * function name. Each call to DEBUG() generates a new header *unless* the
+ * If the 'macro specified' debug class level >= level OR the system-wide
+ * DEBUGLEVEL (synomym for DEBUGLEVEL_CLASS[ DBGC_ALL ]) >= level then
+ * generate a header using the default macros for file, line, and
+ * function name. Each call to DEBUG() generates a new header *unless* the
* previous debug output was unterminated (i.e. no '\n').
* See debug.c:dbghdr() for more info.
*
@@ -160,13 +122,13 @@ extern bool *DEBUGLEVEL_CLASS_ISSET;
*
* DEBUGADD(), DEBUGADDC()
* Same as DEBUG() and DEBUGC() except the text is appended to the previous
- * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
+ * DEBUG(), DEBUGC(), DEBUGADD(), DEBUGADDC() with out another interviening
* header.
*
* Example: DEBUGADD( 2, ("Some text and a value %d.\n", value) );
* DEBUGADDC( DBGC_TDB, 2, ("Some text and a value %d.\n", value) );
*
- * Note: If the debug class has not be redeined (see above) then the optimizer
+ * Note: If the debug class has not be redeined (see above) then the optimizer
* will remove the extra conditional test.
*/
@@ -195,51 +157,33 @@ extern bool *DEBUGLEVEL_CLASS_ISSET;
#define CHECK_DEBUGLVL( level ) \
( ((level) <= MAX_DEBUG_LEVEL) && \
- unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
- (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
- DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) )
+ unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)))
#define DEBUGLVL( level ) \
( CHECK_DEBUGLVL(level) \
- && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO ) )
-
-
-#define DEBUGLVLC( dbgc_class, level ) \
- ( ((level) <= MAX_DEBUG_LEVEL) && \
- unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
- (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
- DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
- && dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO) )
+ && dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ ) )
#define DEBUG( level, body ) \
(void)( ((level) <= MAX_DEBUG_LEVEL) && \
- unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
- (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
- DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
- && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO )) \
+ unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
+ && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
&& (dbgtext body) )
#define DEBUGC( dbgc_class, level, body ) \
(void)( ((level) <= MAX_DEBUG_LEVEL) && \
- unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
- (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
- DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
- && (dbghdrclass( level, DBGC_CLASS, __location__, FUNCTION_MACRO)) \
+ unlikely(DEBUGLEVEL_CLASS[ dbgc_class ] >= (level)) \
+ && (dbghdrclass( level, DBGC_CLASS, __location__, __FUNCTION__ )) \
&& (dbgtext body) )
#define DEBUGADD( level, body ) \
(void)( ((level) <= MAX_DEBUG_LEVEL) && \
- unlikely((DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level))|| \
- (!DEBUGLEVEL_CLASS_ISSET[ DBGC_CLASS ] && \
- DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
+ unlikely(DEBUGLEVEL_CLASS[ DBGC_CLASS ] >= (level)) \
&& (dbgtext body) )
#define DEBUGADDC( dbgc_class, level, body ) \
(void)( ((level) <= MAX_DEBUG_LEVEL) && \
- unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))|| \
- (!DEBUGLEVEL_CLASS_ISSET[ dbgc_class ] && \
- DEBUGLEVEL_CLASS[ DBGC_ALL ] >= (level)) ) \
+ unlikely((DEBUGLEVEL_CLASS[ dbgc_class ] >= (level))) \
&& (dbgtext body) )
/* Print a separator to the debug log. */
@@ -255,19 +199,29 @@ extern bool *DEBUGLEVEL_CLASS_ISSET;
* file-based logging */
enum debug_logtype {DEBUG_DEFAULT_STDERR = 0, DEBUG_STDOUT = 1, DEBUG_FILE = 2, DEBUG_STDERR = 3};
+struct debug_settings {
+ size_t max_log_size;
+ bool syslog;
+ bool syslog_only;
+ bool timestamp_logs;
+ bool debug_prefix_timestamp;
+ bool debug_hires_timestamp;
+ bool debug_pid;
+ bool debug_uid;
+ bool debug_class;
+};
+
void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
void debug_close_dbf(void);
void gfree_debugsyms(void);
-const char *debug_classname_from_index(int ndx);
int debug_add_class(const char *classname);
int debug_lookup_classname(const char *classname);
bool debug_parse_levels(const char *params_str);
-void debug_message(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data);
-void debug_init(void);
-void debug_register_msgs(struct messaging_context *msg_ctx);
+void debug_setup_talloc_log(void);
void debug_set_logfile(const char *name);
-bool reopen_logs( void );
+void debug_set_settings(struct debug_settings *settings);
+bool reopen_logs_internal( void );
void force_check_log_size( void );
bool need_to_check_log_size( void );
void check_log_size( void );
@@ -275,6 +229,41 @@ void dbgflush( void );
bool dbghdrclass(int level, int cls, const char *location, const char *func);
bool dbghdr(int level, const char *location, const char *func);
bool debug_get_output_is_stderr(void);
+void debug_schedule_reopen_logs(void);
+char *debug_list_class_names_and_levels(void);
+
+/**
+ log suspicious usage - print comments and backtrace
+*/
+_PUBLIC_ void log_suspicious_usage(const char *from, const char *info);
+
+/**
+ print suspicious usage - print comments and backtrace
+*/
+_PUBLIC_ void print_suspicious_usage(const char* from, const char* info);
+_PUBLIC_ uint32_t get_task_id(void);
+_PUBLIC_ void log_task_id(void);
+
+/* the debug operations structure - contains function pointers to
+ various debug implementations of each operation */
+struct debug_ops {
+ /* function to log (using DEBUG) suspicious usage of data structure */
+ void (*log_suspicious_usage)(const char* from, const char* info);
+
+ /* function to log (using printf) suspicious usage of data structure.
+ * To be used in circumstances when using DEBUG would cause loop. */
+ void (*print_suspicious_usage)(const char* from, const char* info);
+
+ /* function to return process/thread id */
+ uint32_t (*get_task_id)(void);
+
+ /* function to log process/thread id */
+ void (*log_task_id)(int fd);
+};
+
+/**
+ register a set of debug handlers.
+*/
+_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops);
#endif
-
diff --git a/lib/util/debug_s3.c b/lib/util/debug_s3.c
new file mode 100644
index 0000000000..b81daea5a7
--- /dev/null
+++ b/lib/util/debug_s3.c
@@ -0,0 +1,105 @@
+/*
+ Unix SMB/CIFS implementation.
+ Samba utility functions
+ Copyright (C) Andrew Bartlett 2011
+ Copyright (C) Andrew Tridgell 1992-2002
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "librpc/gen_ndr/messaging.h"
+
+/* This is the Samba3-specific implementation of reopen_logs(), which
+ * calls out to the s3 loadparm code, and means that we don't depend
+ * on loadparm directly. */
+
+bool reopen_logs(void)
+{
+ if (lp_loaded()) {
+ struct debug_settings settings;
+ debug_set_logfile(lp_logfile());
+
+ ZERO_STRUCT(settings);
+ settings.max_log_size = lp_max_log_size();
+ settings.syslog = lp_syslog();
+ settings.syslog_only = lp_syslog_only();
+ settings.timestamp_logs = lp_timestamp_logs();
+ settings.debug_prefix_timestamp = lp_debug_prefix_timestamp();
+ settings.debug_hires_timestamp = lp_debug_hires_timestamp();
+ settings.debug_pid = lp_debug_pid();
+ settings.debug_uid = lp_debug_uid();
+ settings.debug_class = lp_debug_class();
+ debug_set_settings(&settings);
+ }
+ return reopen_logs_internal();
+}
+
+/****************************************************************************
+ Receive a "set debug level" message.
+****************************************************************************/
+
+void debug_message(struct messaging_context *msg_ctx,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id src,
+ DATA_BLOB *data)
+{
+ const char *params_str = (const char *)data->data;
+
+ /* Check, it's a proper string! */
+ if (params_str[(data->length)-1] != '\0') {
+ DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
+ (unsigned int)procid_to_pid(&src),
+ (unsigned int)getpid()));
+ return;
+ }
+
+ DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n",
+ params_str, (unsigned int)getpid(),
+ (unsigned int)procid_to_pid(&src)));
+
+ debug_parse_levels(params_str);
+}
+
+/****************************************************************************
+ Return current debug level.
+****************************************************************************/
+
+static void debuglevel_message(struct messaging_context *msg_ctx,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id src,
+ DATA_BLOB *data)
+{
+ char *message = debug_list_class_names_and_levels();
+
+ if (!message) {
+ DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
+ return;
+ }
+
+ DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %s\n",
+ procid_str_static(&src)));
+ messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL,
+ (uint8 *)message, strlen(message) + 1);
+
+ TALLOC_FREE(message);
+}
+void debug_register_msgs(struct messaging_context *msg_ctx)
+{
+ messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
+ messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
+ debuglevel_message);
+}
diff --git a/lib/util/debug_s3.h b/lib/util/debug_s3.h
new file mode 100644
index 0000000000..ce8869d64c
--- /dev/null
+++ b/lib/util/debug_s3.h
@@ -0,0 +1,23 @@
+/*
+ Unix SMB/CIFS implementation.
+ SMB debug stuff
+ Copyright (C) Andrew Tridgell 2002
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+struct messaging_context;
+void debug_message(struct messaging_context *msg_ctx, void *private_data, uint32_t msg_type, struct server_id src, DATA_BLOB *data);
+void debug_register_msgs(struct messaging_context *msg_ctx);
+bool reopen_logs( void );
diff --git a/lib/util/debug_s4.c b/lib/util/debug_s4.c
deleted file mode 100644
index 845240fdb7..0000000000
--- a/lib/util/debug_s4.c
+++ /dev/null
@@ -1,273 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Samba debug functions
- Copyright (C) Andrew Tridgell 2003
- Copyright (C) James J Myers 2003
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#include "includes.h"
-#include "system/filesys.h"
-#include "system/time.h"
-#include "dynconfig/dynconfig.h"
-
-/**
- * @file
- * @brief Debug logging
- **/
-
-/**
- * this global variable determines what messages are printed
- */
-int _debug_level = 0;
-_PUBLIC_ int *debug_level = &_debug_level;
-static int debug_all_class_hack = 1;
-int *DEBUGLEVEL_CLASS = &debug_all_class_hack; /* For samba 3 */
-static bool debug_all_class_isset_hack = true;
-bool *DEBUGLEVEL_CLASS_ISSET = &debug_all_class_isset_hack; /* For samba 3 */
-
-/* the registered mutex handlers */
-static struct {
- const char *name;
- struct debug_ops ops;
-} debug_handlers;
-
-/* state variables for the debug system */
-static struct {
- int fd; /* The log file handle */
- enum debug_logtype logtype; /* The type of logging we are doing: eg stdout, file, stderr */
- const char *prog_name;
- bool reopening_logs;
-} state;
-
-static bool reopen_logs_scheduled;
-static bool check_reopen_logs(void)
-{
- if (state.fd == 0 || reopen_logs_scheduled) {
- reopen_logs_scheduled = false;
- reopen_logs();
- }
-
- if (state.fd <= 0)
- return false;
-
- return true;
-}
-
-_PUBLIC_ void debug_schedule_reopen_logs(void)
-{
- reopen_logs_scheduled = true;
-}
-
-static void log_timestring(int level, const char *location, const char *func)
-{
- char *t = NULL;
- char *s = NULL;
-
- if (!check_reopen_logs()) return;
-
- if (state.logtype != DEBUG_FILE) return;
-
- t = timestring(NULL, time(NULL));
- if (!t) return;
-
- asprintf(&s, "[%s, %d %s:%s()]\n", t, level, location, func);
- talloc_free(t);
- if (!s) return;
-
- write(state.fd, s, strlen(s));
- free(s);
-}
-
-/**
- the backend for debug messages. Note that the DEBUG() macro has already
- ensured that the log level has been met before this is called
-*/
-_PUBLIC_ void dbghdr(int level, const char *location, const char *func)
-{
- log_timestring(level, location, func);
- log_task_id();
-}
-
-
-_PUBLIC_ void dbghdrclass(int level, int dclass, const char *location, const char *func)
-{
- /* Simple wrapper, Samba 4 doesn't do debug classes */
- dbghdr(level, location, func);
-}
-
-/**
- the backend for debug messages. Note that the DEBUG() macro has already
- ensured that the log level has been met before this is called
-
- @note You should never have to call this function directly. Call the DEBUG()
- macro instead.
-*/
-_PUBLIC_ void dbgtext(const char *format, ...)
-{
- va_list ap;
-
- if (!check_reopen_logs()) return;
-
- va_start(ap, format);
- vdprintf(state.fd, format, ap);
- va_end(ap);
-}
-
-_PUBLIC_ const char *logfile = NULL;
-
-/**
- reopen the log file (usually called because the log file name might have changed)
-*/
-_PUBLIC_ void reopen_logs(void)
-{
- char *fname = NULL;
- int old_fd = state.fd;
- if (state.reopening_logs) {
- return;
- }
-
- switch (state.logtype) {
- case DEBUG_STDOUT:
- case DEBUG_DEFAULT_STDOUT:
- state.fd = 1;
- break;
-
- case DEBUG_STDERR:
- case DEBUG_DEFAULT_STDERR:
- state.fd = 2;
- break;
-
- case DEBUG_FILE:
- state.reopening_logs = true;
- if (logfile && (*logfile) == '/') {
- fname = strdup(logfile);
- } else {
- asprintf(&fname, "%s/%s.log", dyn_LOGFILEBASE, state.prog_name);
- }
- if (fname) {
- int newfd = open(fname, O_CREAT|O_APPEND|O_WRONLY, 0600);
- if (newfd == -1) {
- DEBUG(1, ("Failed to open new logfile: %s\n", fname));
- old_fd = -1;
- } else {
- state.fd = newfd;
- }
- free(fname);
- } else {
- DEBUG(1, ("Failed to find name for file-based logfile!\n"));
- }
- state.reopening_logs = false;
-
- break;
- }
-
- if (old_fd > 2) {
- close(old_fd);
- }
-}
-
-/* setup for logging of talloc warnings */
-static void talloc_log_fn(const char *msg)
-{
- DEBUG(0,("%s", msg));
-}
-
-void debug_setup_talloc_log(void)
-{
- talloc_set_log_fn(talloc_log_fn);
-}
-
-/**
- control the name of the logfile and whether logging will be to stdout, stderr
- or a file, and set up syslog
-
- new_log indicates the destination for the debug log (an enum in
- order of precedence - once set to DEBUG_FILE, it is not possible to
- reset to DEBUG_STDOUT for example. This makes it easy to override
- for debug to stderr on the command line, as the smb.conf cannot
- reset it back to file-based logging
-*/
-_PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype)
-{
- debug_setup_talloc_log();
- if (state.logtype < new_logtype) {
- state.logtype = new_logtype;
- }
- if (prog_name) {
- state.prog_name = prog_name;
- }
- reopen_logs();
-}
-
-/**
- return a string constant containing n tabs
- no more than 10 tabs are returned
-*/
-_PUBLIC_ const char *do_debug_tab(int n)
-{
- const char *tabs[] = {"", "\t", "\t\t", "\t\t\t", "\t\t\t\t", "\t\t\t\t\t",
- "\t\t\t\t\t\t", "\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t",
- "\t\t\t\t\t\t\t\t\t", "\t\t\t\t\t\t\t\t\t\t"};
- return tabs[MIN(n, 10)];
-}
-
-
-/**
- log suspicious usage - print comments and backtrace
-*/
-_PUBLIC_ void log_suspicious_usage(const char *from, const char *info)
-{
- if (!debug_handlers.ops.log_suspicious_usage) return;
-
- debug_handlers.ops.log_suspicious_usage(from, info);
-}
-
-
-/**
- print suspicious usage - print comments and backtrace
-*/
-_PUBLIC_ void print_suspicious_usage(const char* from, const char* info)
-{
- if (!debug_handlers.ops.print_suspicious_usage) return;
-
- debug_handlers.ops.print_suspicious_usage(from, info);
-}
-
-_PUBLIC_ uint32_t get_task_id(void)
-{
- if (debug_handlers.ops.get_task_id) {
- return debug_handlers.ops.get_task_id();
- }
- return getpid();
-}
-
-_PUBLIC_ void log_task_id(void)
-{
- if (!debug_handlers.ops.log_task_id) return;
-
- if (!check_reopen_logs()) return;
-
- debug_handlers.ops.log_task_id(state.fd);
-}
-
-/**
- register a set of debug handlers.
-*/
-_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops)
-{
- debug_handlers.name = name;
- debug_handlers.ops = *ops;
-}
diff --git a/lib/util/debug_s4.h b/lib/util/debug_s4.h
deleted file mode 100644
index 055edcb3c4..0000000000
--- a/lib/util/debug_s4.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- Unix SMB/CIFS implementation.
- Samba debug defines
- Copyright (C) Andrew Tridgell 2003
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-#ifndef _SAMBA_DEBUG_H_
-#define _SAMBA_DEBUG_H_
-
-/**
- * @file
- * @brief Debugging macros
- */
-
-/* the debug operations structure - contains function pointers to
- various debug implementations of each operation */
-struct debug_ops {
- /* function to log (using DEBUG) suspicious usage of data structure */
- void (*log_suspicious_usage)(const char* from, const char* info);
-
- /* function to log (using printf) suspicious usage of data structure.
- * To be used in circumstances when using DEBUG would cause loop. */
- void (*print_suspicious_usage)(const char* from, const char* info);
-
- /* function to return process/thread id */
- uint32_t (*get_task_id)(void);
-
- /* function to log process/thread id */
- void (*log_task_id)(int fd);
-};
-
-#define DEBUGLEVEL *debug_level
-extern int DEBUGLEVEL;
-
-#define DEBUGLVL(level) ((level) <= DEBUGLEVEL)
-#define _DEBUG(level, body, header) do { \
- if (DEBUGLVL(level)) { \
- if (header) { \
- dbghdr(level, __location__, __FUNCTION__); \
- } \
- dbgtext body; \
- } \
-} while (0)
-/**
- * Write to the debug log.
- */
-#define DEBUG(level, body) _DEBUG(level, body, true)
-/**
- * Add data to an existing debug log entry.
- */
-#define DEBUGADD(level, body) _DEBUG(level, body, false)
-
-/* Compatiblity macros for the source3 calling convention */
-#define DEBUGC(class, level, body) _DEBUG(level, body, true)
-#define DEBUGADDC(class, level, body) _DEBUG(level, body, false)
-
-/**
- * Obtain indentation string for the debug log.
- *
- * Level specified by n.
- */
-#define DEBUGTAB(n) do_debug_tab(n)
-
-/** Possible destinations for the debug log (in order of precedence -
- * once set to DEBUG_FILE, it is not possible to reset to DEBUG_STDOUT
- * for example. This makes it easy to override for debug to stderr on
- * the command line, as the smb.conf cannot reset it back to
- * file-based logging */
-enum debug_logtype {DEBUG_DEFAULT_STDOUT = 0,
- DEBUG_DEFAULT_STDERR,
- DEBUG_STDOUT,
- DEBUG_FILE,
- DEBUG_STDERR};
-
-/**
- the backend for debug messages. Note that the DEBUG() macro has already
- ensured that the log level has been met before this is called
-*/
-_PUBLIC_ void dbghdr(int level, const char *location, const char *func);
-
-_PUBLIC_ void dbghdrclass(int level, int cls, const char *location, const char *func);
-
-/**
- reopen the log file (usually called because the log file name might have changed)
-*/
-_PUBLIC_ void reopen_logs(void);
-
-/**
- * this global variable determines what messages are printed
- */
-_PUBLIC_ void debug_schedule_reopen_logs(void);
-
-/**
- control the name of the logfile and whether logging will be to stdout, stderr
- or a file
-*/
-_PUBLIC_ void setup_logging(const char *prog_name, enum debug_logtype new_logtype);
-
-/**
- return a string constant containing n tabs
- no more than 10 tabs are returned
-*/
-_PUBLIC_ const char *do_debug_tab(int n);
-
-/**
- log suspicious usage - print comments and backtrace
-*/
-_PUBLIC_ void log_suspicious_usage(const char *from, const char *info);
-
-/**
- print suspicious usage - print comments and backtrace
-*/
-_PUBLIC_ void print_suspicious_usage(const char* from, const char* info);
-_PUBLIC_ uint32_t get_task_id(void);
-_PUBLIC_ void log_task_id(void);
-
-/**
- register a set of debug handlers.
-*/
-_PUBLIC_ void register_debug_handlers(const char *name, struct debug_ops *ops);
-
-/**
- the backend for debug messages. Note that the DEBUG() macro has already
- ensured that the log level has been met before this is called
-
- @note You should never have to call this function directly. Call the DEBUG()
- macro instead.
-*/
-_PUBLIC_ void dbgtext(const char *format, ...) PRINTF_ATTRIBUTE(1,2);
-
-struct _XFILE;
-extern struct _XFILE *dbf;
-
-/* setup talloc logging */
-void debug_setup_talloc_log(void);
-
-#endif
diff --git a/lib/util/wscript_build b/lib/util/wscript_build
index cc53dd3f75..0468b74546 100644
--- a/lib/util/wscript_build
+++ b/lib/util/wscript_build
@@ -7,23 +7,25 @@ bld.SAMBA_LIBRARY('samba-util-common',
util_file.c time.c rbtree.c rfc1738.c select.c
genrand.c fsusage.c blocking.c become_daemon.c
data_blob.c signal.c system.c params.c util.c util_id.c util_net.c
- util_strlist.c idtree.c''',
+ util_strlist.c idtree.c debug.c''',
public_deps='talloc pthread',
# until we get all the dependencies in this library in common
# we need to allow this library to be built with unresolved symbols
allow_undefined_symbols=True,
local_include=False,
+ public_headers='debug.h',
+ header_path= [('*', 'util') ],
private_library=True
)
if bld.env._SAMBA_BUILD_ == 4:
bld.SAMBA_LIBRARY('samba-util',
- source='''debug_s4.c dprintf.c fault.c
+ source='''dprintf.c fault.c
ms_fnmatch.c parmlist.c substitute.c util_str.c
''',
deps='samba-util-common',
public_deps='talloc LIBCRYPTO CHARSET execinfo uid_wrapper',
- public_headers='attr.h byteorder.h data_blob.h debug.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h util.h',
+ public_headers='attr.h byteorder.h data_blob.h memory.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h util.h',
header_path= [ ('dlinklist.h util.h', '.'), ('*', 'util') ],
local_include=False,
vnum='0.0.1',
diff --git a/source3/Makefile.in b/source3/Makefile.in
index b7a7a7858b..5ec44245d7 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -442,7 +442,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
lib/util_transfer_file.o ../lib/async_req/async_sock.o \
lib/addrchange.o \
$(TDB_LIB_OBJ) \
- $(VERSION_OBJ) lib/charcnv.o lib/debug.o lib/fault.o \
+ $(VERSION_OBJ) lib/charcnv.o ../lib/util/debug.o ../lib/util/debug_s3.o lib/fault.o \
lib/interface.o lib/pidfile.o \
lib/system.o lib/sendfile.o lib/recvfile.o lib/time.o \
lib/username.o \
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 2d6e1e7551..18b53879ad 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -739,8 +739,6 @@ enum flush_reason_enum {
#endif
#endif
-extern int DEBUGLEVEL;
-
#define MAX_SEC_CTX_DEPTH 8 /* Maximum number of security contexts */
diff --git a/source3/include/local.h b/source3/include/local.h
index bb73840757..680631c1c5 100644
--- a/source3/include/local.h
+++ b/source3/include/local.h
@@ -42,11 +42,6 @@
/* maximum number of file caches per smbd */
#define MAX_WRITE_CACHES 10
-/* define what facility to use for syslog */
-#ifndef SYSLOG_FACILITY
-#define SYSLOG_FACILITY LOG_DAEMON
-#endif
-
/*
* Fudgefactor required for open tdb's, etc.
*/
diff --git a/source3/include/smb.h b/source3/include/smb.h
index 49c653e8f3..7c9f60d2fe 100644
--- a/source3/include/smb.h
+++ b/source3/include/smb.h
@@ -69,7 +69,8 @@
#define SMB_SECONDARY_WAIT (60*1000)
/* Debugging stuff */
-#include "debug.h"
+#include "lib/util/debug.h"
+#include "lib/util/debug_s3.h"
/* this defines the error codes that receive_smb can put in smb_read_error */
enum smb_read_errors {
diff --git a/source3/pam_smbpass/pam_smb_auth.c b/source3/pam_smbpass/pam_smb_auth.c
index 24702131b4..d63f0806c3 100644
--- a/source3/pam_smbpass/pam_smb_auth.c
+++ b/source3/pam_smbpass/pam_smb_auth.c
@@ -18,7 +18,7 @@
#define PAM_SM_AUTH
#include "includes.h"
-#include "debug.h"
+#include "lib/util/debug.h"
#ifndef LINUX
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c
index 284f40acc0..245c60a07a 100644
--- a/source3/param/loadparm.c
+++ b/source3/param/loadparm.c
@@ -9458,7 +9458,6 @@ static bool lp_load_ex(const char *pszFname,
bAllowIncludeRegistry = allow_include_registry;
init_globals(initialize_globals);
- debug_init();
free_file_list();
diff --git a/source3/wscript_build b/source3/wscript_build
index a7023fe2b5..e4511daf37 100644
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -59,7 +59,7 @@ LIB_SRC = '''
lib/util_transfer_file.c
lib/addrchange.c
${TDB_LIB_SRC}
- lib/debug.c lib/fault.c
+ ../lib/util/debug_s3.c lib/fault.c
lib/interface.c lib/pidfile.c
lib/system.c lib/sendfile.c lib/recvfile.c lib/time.c
lib/username.c
diff --git a/source4/include/includes.h b/source4/include/includes.h
index a4ef19a042..d0a97020c6 100644
--- a/source4/include/includes.h
+++ b/source4/include/includes.h
@@ -57,7 +57,7 @@
#endif
#include "../lib/util/xfile.h"
#include "../lib/util/attr.h"
-#include "../lib/util/debug_s4.h"
+#include "../lib/util/debug.h"
#include "../lib/util/util.h"
#include "libcli/util/error.h"
diff --git a/source4/param/loadparm.c b/source4/param/loadparm.c
index 31157b2833..186443662a 100644
--- a/source4/param/loadparm.c
+++ b/source4/param/loadparm.c
@@ -133,6 +133,7 @@ struct loadparm_global
char *tls_crlfile;
char *tls_dhpfile;
char *logfile;
+ char *loglevel;
char *panic_action;
int max_mux;
int debuglevel;
@@ -396,8 +397,8 @@ static struct parm_struct parm_table[] = {
{"hosts allow", P_LIST, P_LOCAL, LOCAL_VAR(szHostsallow), NULL, NULL},
{"hosts deny", P_LIST, P_LOCAL, LOCAL_VAR(szHostsdeny), NULL, NULL},
- {"log level", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
- {"debuglevel", P_INTEGER, P_GLOBAL, GLOBAL_VAR(debuglevel), handle_debuglevel, NULL},
+ {"log level", P_STRING, P_GLOBAL, GLOBAL_VAR(loglevel), handle_debuglevel, NULL},
+ {"debuglevel", P_STRING, P_GLOBAL, GLOBAL_VAR(loglevel), handle_debuglevel, NULL},
{"log file", P_STRING, P_GLOBAL, GLOBAL_VAR(logfile), handle_logfile, NULL},
{"smb ports", P_LIST, P_GLOBAL, GLOBAL_VAR(smb_ports), NULL, NULL},
@@ -1524,22 +1525,15 @@ static bool handle_copy(struct loadparm_context *lp_ctx,
static bool handle_debuglevel(struct loadparm_context *lp_ctx,
const char *pszParmValue, char **ptr)
{
- DEBUGLEVEL = atoi(pszParmValue);
- /* also set in the loadparm table, so querying debug level
- works */
- *(int *)ptr = DEBUGLEVEL;
-
- return true;
+ string_set(lp_ctx, ptr, pszParmValue);
+ return debug_parse_levels(pszParmValue);
}
static bool handle_logfile(struct loadparm_context *lp_ctx,
const char *pszParmValue, char **ptr)
{
- if (logfile != NULL) {
- free(discard_const_p(char, logfile));
- }
- logfile = strdup(pszParmValue);
+ debug_set_logfile(pszParmValue);
string_set(lp_ctx, ptr, pszParmValue);
return true;
}
@@ -2371,6 +2365,11 @@ struct loadparm_context *loadparm_init(TALLOC_CTX *mem_ctx)
}
}
+
+ lpcfg_do_global_parameter(lp_ctx, "log level", "0");
+
+ lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
+
lpcfg_do_global_parameter(lp_ctx, "share backend", "classic");
lpcfg_do_global_parameter(lp_ctx, "server role", "standalone");
@@ -2560,6 +2559,7 @@ const char *lp_default_path(void)
*/
static bool lpcfg_update(struct loadparm_context *lp_ctx)
{
+ struct debug_settings settings;
lpcfg_add_auto_services(lp_ctx, lpcfg_auto_services(lp_ctx));
if (!lp_ctx->globals->szWINSservers && lp_ctx->globals->bWINSsupport) {
@@ -2570,6 +2570,12 @@ static bool lpcfg_update(struct loadparm_context *lp_ctx)
reload_charcnv(lp_ctx);
+ ZERO_STRUCT(settings);
+ /* Add any more debug-related smb.conf parameters created in
+ * future here */
+ settings.timestamp_logs = true;
+ debug_set_settings(&settings);
+
/* FIXME: ntstatus_check_dos_mapping = lpcfg_nt_status_support(lp_ctx); */
/* FIXME: This is a bit of a hack, but we can't use a global, since