]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm_setup: Forward --logfile option to swtpm
authorEiichi Tsukata <eiichi.tsukata@nutanix.com>
Wed, 22 Sep 2021 06:22:28 +0000 (15:22 +0900)
committerStefan Berger <stefanb@us.ibm.com>
Wed, 29 Sep 2021 16:48:30 +0000 (12:48 -0400)
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>
src/swtpm_setup/swtpm.c
src/swtpm_setup/swtpm_setup.c

index 3b37291d20a890d674fd0102fa12229286197940..687a915dbdd2095356212cc09a0986b12b784958 100644 (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;
index 0ab544fd67b23751084273ada0cb70d7e15f9584..ccbc56c656d1d0240f7196b3aa9b107221e17aa1 100644 (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) {