Skip to content

Commit

Permalink
tpm: Make tss2 log into /dev/null
Browse files Browse the repository at this point in the history
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] tpm2-software/tpm2-tss#2087
  • Loading branch information
jadahl committed Aug 5, 2022
1 parent 23494ee commit 053431b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/grd-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

static const GDebugKey grd_debug_keys[] = {
{ "vnc", GRD_DEBUG_VNC },
{ "tpm", GRD_DEBUG_TPM },
};

static GrdDebugFlags debug_flags;
Expand Down
1 change: 1 addition & 0 deletions src/grd-debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/grd-tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ control_sources = ([

ctl_sources = ([
'grd-ctl.c',
'grd-debug.c',
'grd-debug.h',
credentials_sources,
])

Expand Down
2 changes: 2 additions & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
Expand Down

0 comments on commit 053431b

Please sign in to comment.