tpm_extendpcr: Support platforms not having syslog()
This commit is contained in:
@@ -19,14 +19,18 @@
|
||||
#include <crypto/hashers/hasher.h>
|
||||
#include <utils/debug.h>
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
/* logging */
|
||||
static bool log_to_stderr = TRUE;
|
||||
#ifdef HAVE_SYSLOG
|
||||
static bool log_to_syslog = TRUE;
|
||||
#endif
|
||||
static level_t default_loglevel = 1;
|
||||
|
||||
/* global variables */
|
||||
@@ -39,8 +43,6 @@ chunk_t pcr_value;
|
||||
*/
|
||||
static void tpm_extendpcr_dbg(debug_t group, level_t level, char *fmt, ...)
|
||||
{
|
||||
char buffer[8192];
|
||||
char *current = buffer, *next;
|
||||
va_list args;
|
||||
|
||||
if (level <= default_loglevel)
|
||||
@@ -52,8 +54,12 @@ static void tpm_extendpcr_dbg(debug_t group, level_t level, char *fmt, ...)
|
||||
va_end(args);
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (log_to_syslog)
|
||||
{
|
||||
char buffer[8192];
|
||||
char *current = buffer, *next;
|
||||
|
||||
/* write in memory buffer first */
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
||||
@@ -71,6 +77,7 @@ static void tpm_extendpcr_dbg(debug_t group, level_t level, char *fmt, ...)
|
||||
current = next;
|
||||
}
|
||||
}
|
||||
#endif /* HAVE_SYSLOG*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,10 +92,12 @@ static void init_log(const char *program)
|
||||
{
|
||||
setbuf(stderr, NULL);
|
||||
}
|
||||
#ifdef HAVE_SYSLOG
|
||||
if (log_to_syslog)
|
||||
{
|
||||
openlog(program, LOG_CONS | LOG_NDELAY | LOG_PID, LOG_AUTHPRIV);
|
||||
}
|
||||
#endif /* HAVE_SYSLOG */
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user