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
}
#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.
}
}
+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 */
{
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);
state.hs_len = sizeof(state.header_str) - 1;
}
- state.header_str_no_nl[0] = '\0';
-
errno = old_errno;
return( true );
}