Skip to content

Commit

Permalink
swtpm: Display stderr in case swtpm --print-capabilities failed
Browse files Browse the repository at this point in the history
When swtpm --print-capabilities for example fails to be able to access
the log file that swtpm_setup logs into, then it may fail to run. In
this case log the stderr output of swtpm.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
  • Loading branch information
stefanberger committed Sep 30, 2024
1 parent 2e21249 commit aa78a30
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/swtpm_setup/swtpm_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,7 @@ static int get_swtpm_capabilities(const gchar **swtpm_prg_l, gboolean is_tpm2,
gchar **standard_output)
{
const gchar *my_argv[] = { "--print-capabilities", is_tpm2 ? "--tpm2" : NULL, NULL };
g_autofree gchar *standard_error = NULL;
g_autofree gchar *logop = NULL;
g_autoptr(GError) error = NULL;
g_autofree const gchar **argv = NULL;
Expand All @@ -1081,12 +1082,17 @@ static int get_swtpm_capabilities(const gchar **swtpm_prg_l, gboolean is_tpm2,
argv = concat_arrays(argv, (const gchar*[]){"--log", logop, NULL}, TRUE);
}

success = spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
standard_output, NULL, &exit_status, &error);
success = spawn_sync(NULL, argv, NULL, 0, NULL, NULL,
standard_output, &standard_error, &exit_status, &error);
if (!success) {
logerr(gl_LOGFILE, "Could not start swtpm '%s': %s\n", swtpm_prg_l[0], error->message);
goto error;
}
if (exit_status != 0) {
/* possible: failure to access log file */
logerr(gl_LOGFILE, "Failed to run swtpm '%s': %s\n", swtpm_prg_l[0], standard_error);
goto error;
}
ret = 0;

error:
Expand Down

0 comments on commit aa78a30

Please sign in to comment.