tpm_extendpcr: Support platforms not having syslog()
authorTobias Brunner <tobias@strongswan.org>
Mon, 23 Aug 2021 09:30:15 +0000 (11:30 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 23 Aug 2021 09:30:15 +0000 (11:30 +0200)
src/tpm_extendpcr/tpm_extendpcr.c

index 23d652f..02e0eef 100644 (file)
 #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 */
 }
 
 /**