swtpm_setup: Forward --logfile option to swtpm

Whenever swtpm_setup is executed with --logfile option, forward the
option to swtpm (--log file=...). This helps debugging swtpm
initialization issues.

Signed-off-by: Eiichi Tsukata <eiichi.tsukata@nutanix.com>
This commit is contained in:
Eiichi Tsukata 2021-09-22 15:22:28 +09:00 committed by Stefan Berger
parent 15ff0d967a
commit 7b7dcbb8d8
2 changed files with 26 additions and 0 deletions

View File

@ -61,6 +61,7 @@ static int swtpm_start(struct swtpm *self)
g_autofree gchar *server_fd = NULL;
g_autofree gchar *ctrl_fd = NULL;
g_autofree gchar *keyopts = NULL;
g_autofree gchar *logop = NULL;
g_autofree gchar **argv = NULL;
struct stat statbuf;
gboolean success;
@ -90,6 +91,11 @@ static int swtpm_start(struct swtpm *self)
argv = concat_arrays(argv, (gchar*[]){"--key", keyopts, NULL}, TRUE);
}
if (gl_LOGFILE != NULL) {
logop = g_strdup_printf("file=%s", gl_LOGFILE);
argv = concat_arrays(argv, (gchar*[]){"--log", logop, NULL}, TRUE);
}
if (socketpair(AF_UNIX, SOCK_STREAM, 0, self->ctrl_fds) != 0) {
logerr(self->logfile, "Could not create socketpair: %s\n", strerror(errno));
return 1;

View File

@ -704,6 +704,7 @@ static int check_state_overwrite(gchar **swtpm_prg_l, unsigned int flags,
g_autoptr(GError) error = NULL;
g_autofree gchar **argv = NULL;
g_autofree gchar *dirop = g_strdup_printf("dir=%s", tpm_state_path);
g_autofree gchar *logop = NULL;
g_autofree gchar **my_argv = NULL;
my_argv = concat_arrays((gchar*[]) {
@ -716,7 +717,13 @@ static int check_state_overwrite(gchar **swtpm_prg_l, unsigned int flags,
if (flags & SETUP_TPM2_F)
my_argv = concat_arrays(my_argv, (gchar*[]) { "--tpm2", NULL }, TRUE);
if (gl_LOGFILE != NULL) {
logop = g_strdup_printf("file=%s", gl_LOGFILE);
my_argv = concat_arrays(my_argv, (gchar*[]){"--log", logop, NULL}, TRUE);
}
argv = concat_arrays(swtpm_prg_l, my_argv, FALSE);
success = g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
&standard_output, NULL, &exit_status, &error);
if (!success) {
@ -911,8 +918,15 @@ static int get_supported_tpm_versions(gchar **swtpm_prg_l, gboolean *swtpm_has_t
g_autoptr(GError) error = NULL;
g_autofree gchar **argv = NULL;
gchar *my_argv[] = { "--print-capabilities", NULL };
g_autofree gchar *logop = NULL;
argv = concat_arrays(swtpm_prg_l, my_argv, FALSE);
if (gl_LOGFILE != NULL) {
logop = g_strdup_printf("file=%s", gl_LOGFILE);
argv = concat_arrays(argv, (gchar*[]){"--log", logop, NULL}, TRUE);
}
success = g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
&standard_output, NULL, &exit_status, &error);
if (!success) {
@ -944,6 +958,7 @@ static int get_rsa_keysizes(unsigned long flags, gchar **swtpm_prg_l,
gchar **argv = NULL;
char *p;
int n;
g_autofree gchar *logop = NULL;
*n_keysizes = 0;
@ -952,6 +967,11 @@ static int get_rsa_keysizes(unsigned long flags, gchar **swtpm_prg_l,
argv = concat_arrays(swtpm_prg_l, my_argv, FALSE);
if (gl_LOGFILE != NULL) {
logop = g_strdup_printf("file=%s", gl_LOGFILE);
argv = concat_arrays(argv, (gchar*[]){"--log", logop, NULL}, TRUE);
}
success = g_spawn_sync(NULL, argv, NULL, G_SPAWN_STDERR_TO_DEV_NULL, NULL, NULL,
&standard_output, NULL, &exit_status, &error);
if (!success) {