[SCM] Samba Shared Repository - branch master updated

Volker Lendecke vlendec at samba.org
Thu Jan 4 17:07:01 UTC 2024


The branch, master has been updated
       via  f2dbcea6f04 lib: Confine the copy_no_nl memcpy to debug_gpfs_log()
       via  c3399cd46f7 lib: Avoid memcpy in debug_lttng_log()
       via  f8a75f83077 lib: Avoid memcpy in debug_systemd_log()
      from  16d802f9c1f script/autobuild.py: add some --private-libraries=ALL testing

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f2dbcea6f0499e81cf5b3215459925bb1dffd4a8
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 19 15:34:50 2023 +0100

    lib: Confine the copy_no_nl memcpy to debug_gpfs_log()
    
    gpfswrap_add_trace() seems not to have a format string that could
    understand the %.*s notation.
    
    While there this removes >4k of r/w memory from every smbd.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    
    Autobuild-User(master): Volker Lendecke <vl at samba.org>
    Autobuild-Date(master): Thu Jan  4 17:06:19 UTC 2024 on atb-devel-224

commit c3399cd46f7a33db516b5716a2ce0ebf50fd117a
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 19 14:47:24 2023 +0100

    lib: Avoid memcpy in debug_lttng_log()
    
    tracef() understands the %.*s format.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit f8a75f830774a6f32ed834cd3d17ba8804fddb82
Author: Volker Lendecke <vl at samba.org>
Date:   Tue Dec 19 14:44:12 2023 +0100

    lib: Avoid memcpy in debug_systemd_log()
    
    sd_journal_send() understands the %.*s format.
    
    Signed-off-by: Volker Lendecke <vl at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/util/debug.c | 145 ++++++++++++++++++++++++-------------------------------
 1 file changed, 62 insertions(+), 83 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/util/debug.c b/lib/util/debug.c
index f1f91ebe7a7..86f13f181cf 100644
--- a/lib/util/debug.c
+++ b/lib/util/debug.c
@@ -100,9 +100,7 @@ static struct {
 	debug_callback_fn callback;
 	void *callback_private;
 	char header_str[300];
-	char header_str_no_nl[300];
 	size_t hs_len;
-	char msg_no_nl[FORMAT_BUFR_SIZE];
 } state = {
 	.settings = {
 		.timestamp_logs = true
@@ -244,48 +242,6 @@ static int debug_level_to_priority(int level)
 }
 #endif
 
-/* -------------------------------------------------------------------------- **
- * Produce a version of the given buffer without any trailing newlines.
- */
-#if defined(HAVE_LIBSYSTEMD_JOURNAL) || defined(HAVE_LIBSYSTEMD) || \
-	defined(HAVE_LTTNG_TRACEF) || defined(HAVE_GPFS)
-static void copy_no_nl(char *out,
-		       size_t out_size,
-		       const char *in,
-		       size_t in_len)
-{
-	size_t len;
-	/*
-	 * Some backends already add an extra newline, so also provide
-	 * a buffer without the newline character.
-	 */
-	len = MIN(in_len, out_size - 1);
-	if ((len > 0) && (in[len - 1] == '\n')) {
-		len--;
-	}
-
-	memcpy(out, in, len);
-	out[len] = '\0';
-}
-
-static void ensure_copy_no_nl(char *out,
-			      size_t out_size,
-			      const char *in,
-			      size_t in_len)
-{
-	/*
-	 * Assume out is a static buffer that is reused as a cache.
-	 * If it isn't empty then this has already been done with the
-	 * same input.
-	 */
-	if (out[0] != '\0') {
-		return;
-	}
-
-	copy_no_nl(out, out_size, in, in_len);
-}
-#endif
-
 /* -------------------------------------------------------------------------- **
  * Debug backends. When logging to DEBUG_FILE, send the log entries to
  * all active backends.
@@ -366,24 +322,33 @@ static void debug_syslog_log(int msg_level, const char *msg, size_t msg_len)
 static void debug_systemd_log(int msg_level, const char *msg, size_t msg_len)
 {
 	if (state.hs_len > 0) {
-		ensure_copy_no_nl(state.header_str_no_nl,
-				  sizeof(state.header_str_no_nl),
-				  state.header_str,
-				  state.hs_len);
-		sd_journal_send("MESSAGE=%s",
-				state.header_str_no_nl,
+		size_t len = state.hs_len;
+
+		if (state.header_str[len - 1] == '\n') {
+			len -= 1;
+		}
+
+		sd_journal_send("MESSAGE=%.*s",
+				(int)len,
+				state.header_str,
 				"PRIORITY=%d",
 				debug_level_to_priority(msg_level),
 				"LEVEL=%d",
 				msg_level,
 				NULL);
 	}
-	ensure_copy_no_nl(state.msg_no_nl,
-			  sizeof(state.msg_no_nl),
-			  msg, msg_len);
-	sd_journal_send("MESSAGE=%s", state.msg_no_nl,
-			"PRIORITY=%d", debug_level_to_priority(msg_level),
-			"LEVEL=%d", msg_level,
+
+	if ((msg_len > 0) && (msg[msg_len - 1] == '\n')) {
+		msg_len -= 1;
+	}
+
+	sd_journal_send("MESSAGE=%.*s",
+			(int)msg_len,
+			msg,
+			"PRIORITY=%d",
+			debug_level_to_priority(msg_level),
+			"LEVEL=%d",
+			msg_level,
 			NULL);
 }
 #endif
@@ -393,16 +358,19 @@ static void debug_systemd_log(int msg_level, const char *msg, size_t msg_len)
 static void debug_lttng_log(int msg_level, const char *msg, size_t msg_len)
 {
 	if (state.hs_len > 0) {
-		ensure_copy_no_nl(state.header_str_no_nl,
-				  sizeof(state.header_str_no_nl),
-				  state.header_str,
-				  state.hs_len);
-		tracef(state.header_str_no_nl);
+		size_t len = state.hs_len;
+
+		if (state.header_str[len - 1] == '\n') {
+			len -= 1;
+		}
+
+		tracef("%.*s", (int)len, state.header_str);
+	}
+
+	if ((msg_len > 0) && (msg[msg_len - 1] == '\n')) {
+		msg_len -= 1;
 	}
-	ensure_copy_no_nl(state.msg_no_nl,
-			  sizeof(state.msg_no_nl),
-			  msg, msg_len);
-	tracef(state.msg_no_nl);
+	tracef("%.*s", (int)msg_len, msg);
 }
 #endif /* WITH_LTTNG_TRACEF */
 
@@ -433,19 +401,39 @@ static void debug_gpfs_reload(bool enabled, bool previously_enabled,
 	}
 }
 
+static void copy_no_nl(char *out,
+		       size_t out_size,
+		       const char *in,
+		       size_t in_len)
+{
+	size_t len;
+	/*
+	 * Some backends already add an extra newline, so also provide
+	 * a buffer without the newline character.
+	 */
+	len = MIN(in_len, out_size - 1);
+	if ((len > 0) && (in[len - 1] == '\n')) {
+		len--;
+	}
+
+	memcpy(out, in, len);
+	out[len] = '\0';
+}
+
 static void debug_gpfs_log(int msg_level, const char *msg, size_t msg_len)
 {
+	char no_nl[FORMAT_BUFR_SIZE];
+
 	if (state.hs_len > 0) {
-		ensure_copy_no_nl(state.header_str_no_nl,
-				  sizeof(state.header_str_no_nl),
-				  state.header_str,
-				  state.hs_len);
-		gpfswrap_add_trace(msg_level, state.header_str_no_nl);
+		copy_no_nl(no_nl,
+			   sizeof(no_nl),
+			   state.header_str,
+			   state.hs_len);
+		gpfswrap_add_trace(msg_level, no_nl);
 	}
-	ensure_copy_no_nl(state.msg_no_nl,
-			  sizeof(state.msg_no_nl),
-			  msg, msg_len);
-	gpfswrap_add_trace(msg_level, state.msg_no_nl);
+
+	copy_no_nl(no_nl, sizeof(no_nl), msg, msg_len);
+	gpfswrap_add_trace(msg_level, no_nl);
 }
 #endif /* HAVE_GPFS */
 
@@ -700,13 +688,6 @@ static void debug_backends_log(const char *msg, size_t msg_len, int msg_level)
 {
 	size_t i;
 
-	/*
-	 * Some backends already add an extra newline, so initialize a
-	 * buffer without the newline character.  It will be filled by
-	 * the first backend that needs it.
-	 */
-	state.msg_no_nl[0] = '\0';
-
 	for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
 		if (msg_level <= debug_backends[i].log_level) {
 			debug_backends[i].log(msg_level, msg, msg_len);
@@ -1931,8 +1912,6 @@ full:
 		state.hs_len = sizeof(state.header_str) - 1;
 	}
 
-	state.header_str_no_nl[0] = '\0';
-
 	errno = old_errno;
 	return( true );
 }


-- 
Samba Shared Repository



More information about the samba-cvs mailing list