increased `make test` logging in syslog with "debug syslog format = always"

Martin Schwenke martin at meltin.net
Wed Jul 26 10:33:52 UTC 2023


On Wed, 26 Jul 2023 16:42:47 +1200, Douglas Bagnall
<douglas.bagnall at catalyst.net.nz> wrote:

> So, seeing as I started this I feel like I should keep you posted.
> 
> > static void Debug1(const char *msg, size_t msg_len)
> > {
> > 	int old_errno = errno;
> > 	enum debug_logtype logtype = state.logtype;
> > 
> > 	debug_count++;
> > 
> > 	if (state.settings.debug_syslog_format == DEBUG_SYSLOG_FORMAT_ALWAYS) {
> > 		switch(state.logtype) {
> > 		case DEBUG_STDOUT:
> > 		case DEBUG_STDERR:
> > 		case DEBUG_DEFAULT_STDOUT:
> > 		case DEBUG_DEFAULT_STDERR:
> > 			/* Behave the same as logging to a file */
> > 			logtype = DEBUG_FILE;
> > 			break;  
> 
> By treating STDERR et. al. as DEBUG_FILE,...
> 
> 
> > 		default:
> > 			break;
> > 		}
> > 	}
> > 
> > 	switch(logtype) {
> > 	case DEBUG_CALLBACK:
> > 		debug_callback_log(msg, msg_len, current_msg_level);
> > 		break;
> > 	case DEBUG_STDOUT:
> > 	case DEBUG_STDERR:
> > 	case DEBUG_DEFAULT_STDOUT:
> > 	case DEBUG_DEFAULT_STDERR:  
> 
> ...we skip over this straightforward write to the fd...
> 
> > 		if (dbgc_config[DBGC_ALL].fd > 0) {
> > 			ssize_t ret;
> > 			do {
> > 				ret = write(dbgc_config[DBGC_ALL].fd,
> > 					    msg,
> > 					    msg_len);
> > 			} while (ret == -1 && errno == EINTR);
> > 		}
> > 		break;
> > 	case DEBUG_FILE:
> > 		debug_backends_log(msg, msg_len, current_msg_level);  
> 
> ...and loop through all the registered backends.
> 
> When "logging" is not set in smb.conf, the default backend configuration is 
> "syslog at 0 file at 1000" (via debug_set_settings), so we write to the file *and* 
> syslog (the file is stderr for the Kinit messages).

Well spotted!

Can we just call debug_file_log() directly when necessary, like this?

diff --git a/lib/util/debug.c b/lib/util/debug.c
index b83075cb239..0e13fa564e3 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -1559,25 +1559,10 @@ void check_log_size( void )
 static void Debug1(const char *msg, size_t msg_len)
 {
 	int old_errno = errno;
-	enum debug_logtype logtype = state.logtype;
 
 	debug_count++;
 
-	if (state.settings.debug_syslog_format == DEBUG_SYSLOG_FORMAT_ALWAYS) {
-		switch(state.logtype) {
-		case DEBUG_STDOUT:
-		case DEBUG_STDERR:
-		case DEBUG_DEFAULT_STDOUT:
-		case DEBUG_DEFAULT_STDERR:
-			/* Behave the same as logging to a file */
-			logtype = DEBUG_FILE;
-			break;
-		default:
-			break;
-		}
-	}
-
-	switch(logtype) {
+	switch(state.logtype) {
 	case DEBUG_CALLBACK:
 		debug_callback_log(msg, msg_len, current_msg_level);
 		break;
@@ -1585,13 +1570,18 @@ static void Debug1(const char *msg, size_t msg_len)
 	case DEBUG_STDERR:
 	case DEBUG_DEFAULT_STDOUT:
 	case DEBUG_DEFAULT_STDERR:
-		if (dbgc_config[DBGC_ALL].fd > 0) {
-			ssize_t ret;
-			do {
-				ret = write(dbgc_config[DBGC_ALL].fd,
-					    msg,
-					    msg_len);
-			} while (ret == -1 && errno == EINTR);
+		if (state.settings.debug_syslog_format ==
+		    DEBUG_SYSLOG_FORMAT_ALWAYS) {
+			debug_file_log(current_msg_level, msg, msg_len);
+		} else {
+			if (dbgc_config[DBGC_ALL].fd > 0) {
+				ssize_t ret;
+				do {
+					ret = write(dbgc_config[DBGC_ALL].fd,
+						    msg,
+						    msg_len);
+				} while (ret == -1 && errno == EINTR);
+			}
 		}
 		break;
 	case DEBUG_FILE:

I haven't tested this.

If it is OK, I think we could also revert the changes to
dbghdrclass(), though we would be generating a header for no
reason... but I think we did that before.

Thoughts?

peace & happiness,
martin



More information about the samba-technical mailing list