1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-24 02:04:21 +03:00

debug: Optimise construction of msg_no_nl

If it isn't used then it isn't copied.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Volker Lendecke <vl@samba.org>

Autobuild-User(master): Volker Lendecke <vl@samba.org>
Autobuild-Date(master): Thu Oct 14 11:10:40 UTC 2021 on sn-devel-184
This commit is contained in:
Martin Schwenke 2021-10-14 11:08:38 +11:00 committed by Volker Lendecke
parent 62fd771aea
commit a9a3555b43

View File

@ -208,6 +208,8 @@ static int debug_level_to_priority(int level)
/* -------------------------------------------------------------------------- **
* 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,
@ -227,8 +229,6 @@ static void copy_no_nl(char *out,
out[len] = '\0';
}
#if defined(HAVE_LIBSYSTEMD_JOURNAL) || defined(HAVE_LIBSYSTEMD) || \
defined(HAVE_LTTNG_TRACEF) || defined(HAVE_GPFS)
static void ensure_copy_no_nl(char *out,
size_t out_size,
const char *in,
@ -339,6 +339,9 @@ static void debug_systemd_log(int msg_level, const char *msg, size_t msg_len)
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,
@ -357,6 +360,9 @@ static void debug_lttng_log(int msg_level, const char *msg, size_t msg_len)
state.hs_len);
tracef(state.header_str_no_nl);
}
ensure_copy_no_nl(state.msg_no_nl,
sizeof(state.msg_no_nl),
msg, msg_len);
tracef(state.msg_no_nl);
}
#endif /* WITH_LTTNG_TRACEF */
@ -395,6 +401,9 @@ static void debug_gpfs_log(int msg_level, const char *msg, size_t msg_len)
state.hs_len);
gpfswrap_add_trace(msg_level, state.header_str_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);
}
#endif /* HAVE_GPFS */
@ -651,10 +660,11 @@ 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 also provide
* a buffer without the newline character.
* 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.
*/
copy_no_nl(state.msg_no_nl, FORMAT_BUFR_SIZE, msg, msg_len);
state.msg_no_nl[0] = '\0';
for (i = 0; i < ARRAY_SIZE(debug_backends); i++) {
if (msg_level <= debug_backends[i].log_level) {