From 02db69c85ab90d4aea09772a8b1acb8bc246afe1 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Sat, 11 Nov 2017 10:43:14 -0500 Subject: [PATCH] Add unsuppressable internal logging using ~0 indent Signed-off-by: Stefan Berger --- src/tpm_library.c | 21 +++++++++++++++++---- src/tpm_library_intern.h | 3 +++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/tpm_library.c b/src/tpm_library.c index 333f7b16..1c274d8e 100644 --- a/src/tpm_library.c +++ b/src/tpm_library.c @@ -45,6 +45,7 @@ #include #include #include +#include #ifdef USE_FREEBL_CRYPTO_LIBRARY # include @@ -421,24 +422,36 @@ int TPMLIB_LogPrintf(const char *format, ...) /* * TPMLIB_LogPrintfA: Printf to the logfd without indentation check + * + * @indent: how many spaces to indent; indent of ~0 forces logging + * with indent 0 even if not debug_level is set + * @format: format to use for formatting the following parameters + * @...: varargs */ void TPMLIB_LogPrintfA(unsigned int indent, const char *format, ...) { va_list args; char spaces[20]; + int fd; - if (!debug_fd || !debug_level) - return; + if (indent != ~0) { + if (!debug_fd || !debug_level) + return; + fd = debug_fd; + } else { + indent = 0; + fd = (debug_fd >= 0) ? debug_fd : STDERR_FILENO; + } if (indent) { if (indent > sizeof(spaces) - 1) indent = sizeof(spaces) - 1; memset(spaces, ' ', indent); spaces[indent] = 0; - dprintf(debug_fd, "%s", spaces); + dprintf(fd, "%s", spaces); } va_start(args, format); - vdprintf(debug_fd, format, args); + vdprintf(fd, format, args); va_end(args); } diff --git a/src/tpm_library_intern.h b/src/tpm_library_intern.h index c084f3e2..e23b863a 100644 --- a/src/tpm_library_intern.h +++ b/src/tpm_library_intern.h @@ -80,4 +80,7 @@ TPM_RESULT TPM12_IO_TpmEstablished_Get(TPM_BOOL *tpmEstablished); int TPMLIB_LogPrintf(const char *format, ...); void TPMLIB_LogPrintfA(unsigned int indent, const char *format, ...); +#define TPMLIB_LogTPM12Error(format, ...) \ + TPMLIB_LogPrintfA(~0, "libtpms/tpm12: "format, __VA_ARGS__) + #endif /* TPM_LIBRARY_INTERN_H */