[gnome-remote-desktop] tpm: Make tss2 log into /dev/null



commit 053431bb3a4c6f81ab88f13f39d2a093180d7e3f
Author: Jonas Ådahl <jadahl gmail com>
Date:   Fri Aug 5 21:25:24 2022 +0200

    tpm: Make tss2 log into /dev/null
    
    There is no way yet[1] to control how much tss2 logs and to where, from the C
    API. The problem with that is if there is no TPM 2.0 module, it'll very
    verbosely tell about it via ERROR and WARNING log entries directly to
    stderr, which isn't really what we want.
    
    Change this by setting the env var controlling the log target to
    /dev/null unless the tpm debug key is enabled.
    
    [1] https://github.com/tpm2-software/tpm2-tss/pull/2087

 src/grd-debug.c   | 1 +
 src/grd-debug.h   | 1 +
 src/grd-tpm.c     | 5 +++++
 src/meson.build   | 2 ++
 tests/meson.build | 2 ++
 5 files changed, 11 insertions(+)
---
diff --git a/src/grd-debug.c b/src/grd-debug.c
index c556f10d..3e0c6675 100644
--- a/src/grd-debug.c
+++ b/src/grd-debug.c
@@ -26,6 +26,7 @@
 
 static const GDebugKey grd_debug_keys[] = {
   { "vnc", GRD_DEBUG_VNC },
+  { "tpm", GRD_DEBUG_TPM },
 };
 
 static GrdDebugFlags debug_flags;
diff --git a/src/grd-debug.h b/src/grd-debug.h
index a88fdfe7..47ac28fb 100644
--- a/src/grd-debug.h
+++ b/src/grd-debug.h
@@ -25,6 +25,7 @@ typedef enum _GrdDebugFlags
 {
   GRD_DEBUG_NONE = 0,
   GRD_DEBUG_VNC = 1 << 0,
+  GRD_DEBUG_TPM = 1 << 1,
 } GrdDebugFlags;
 
 GrdDebugFlags grd_get_debug_flags (void);
diff --git a/src/grd-tpm.c b/src/grd-tpm.c
index 06624f88..ff88c607 100644
--- a/src/grd-tpm.c
+++ b/src/grd-tpm.c
@@ -32,6 +32,8 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 #include <tss2_tctildr.h>
 G_GNUC_END_IGNORE_DEPRECATIONS
 
+#include "grd-debug.h"
+
 struct _GrdTpm
 {
   GObject parent;
@@ -722,6 +724,9 @@ grd_tpm_new (GrdTpmMode   mode,
 
   tpm = g_object_new (GRD_TYPE_TPM, NULL);
 
+  if (!(grd_get_debug_flags () & GRD_DEBUG_TPM))
+    g_setenv ("TSS2_LOGFILE", "/dev/null", TRUE);
+
   if (!init_transmission_interface (tpm, error))
     return NULL;
 
diff --git a/src/meson.build b/src/meson.build
index b5be2c34..6506d92f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -176,6 +176,8 @@ control_sources = ([
 
 ctl_sources = ([
   'grd-ctl.c',
+  'grd-debug.c',
+  'grd-debug.h',
   credentials_sources,
 ])
 
diff --git a/tests/meson.build b/tests/meson.build
index 31247291..3dd360d2 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -72,6 +72,8 @@ tpm_test = executable(
   'tpm-test',
   sources: [
     'tpm-test.c',
+    '../src/grd-debug.c',
+    '../src/grd-debug.h',
     '../src/grd-tpm.c',
     '../src/grd-tpm.h',
   ],


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]