virt-sysprep: Trap ERR as well as EXIT.
[libguestfs.git] / src / launch.c
index db76885..8e171f7 100644 (file)
@@ -389,6 +389,8 @@ guestfs__launch (guestfs_h *g)
     return -1;
   }
 
+  TRACE0 (launch_start);
+
   /* Make the temporary directory. */
   if (!g->tmpdir) {
     TMP_TEMPLATE_ON_STACK (dir_template);
@@ -439,11 +441,15 @@ launch_appliance (guestfs_h *g)
   gettimeofday (&g->launch_t, NULL);
   guestfs___launch_send_progress (g, 0);
 
+  TRACE0 (launch_build_appliance_start);
+
   /* Locate and/or build the appliance. */
   char *kernel = NULL, *initrd = NULL, *appliance = NULL;
   if (guestfs___build_appliance (g, &kernel, &initrd, &appliance) == -1)
     return -1;
 
+  TRACE0 (launch_build_appliance_end);
+
   guestfs___launch_send_progress (g, 3);
 
   if (g->verbose)
@@ -555,6 +561,12 @@ launch_appliance (guestfs_h *g)
 
     add_cmdline (g, "-nographic");
 
+    if (g->smp > 1) {
+      snprintf (buf, sizeof buf, "%d", g->smp);
+      add_cmdline (g, "-smp");
+      add_cmdline (g, buf);
+    }
+
     snprintf (buf, sizeof buf, "%d", g->memsize);
     add_cmdline (g, "-m");
     add_cmdline (g, buf);
@@ -606,7 +618,7 @@ launch_appliance (guestfs_h *g)
     "panic=1 "         /* force kernel to panic if daemon exits */     \
     "console=ttyS0 "   /* serial console */                            \
     "udevtimeout=300 " /* good for very slow systems (RHBZ#480319) */  \
-    "noapic "          /* workaround for RHBZ#502058 - ok if not SMP */ \
+    "no_timer_check "  /* fix for RHBZ#502058 */                        \
     "acpi=off "        /* we don't need ACPI, turn it off */           \
     "printk.time=1 "   /* display timestamp before kernel messages */   \
     "cgroup_disable=memory " /* saves us about 5 MB of RAM */
@@ -690,6 +702,8 @@ launch_appliance (guestfs_h *g)
 
     setenv ("LC_ALL", "C", 1);
 
+    TRACE0 (launch_run_qemu);
+
     execv (g->qemu, g->cmdline); /* Run qemu. */
     perror (g->qemu);
     _exit (EXIT_FAILURE);
@@ -819,6 +833,8 @@ launch_appliance (guestfs_h *g)
     goto cleanup1;
   }
 
+  TRACE0 (launch_end);
+
   guestfs___launch_send_progress (g, 12);
 
   return 0;
@@ -1071,6 +1087,11 @@ test_qemu (guestfs_h *g)
   char cmd[1024];
   FILE *fp;
 
+  free (g->qemu_help);
+  g->qemu_help = NULL;
+  free (g->qemu_version);
+  g->qemu_version = NULL;
+
   snprintf (cmd, sizeof cmd, "LC_ALL=C '%s' -nographic -help", g->qemu);
 
   /* qemu -help should always work (qemu -version OTOH wasn't
@@ -1078,7 +1099,8 @@ test_qemu (guestfs_h *g)
    * probably indicates that the qemu binary is missing.
    */
   if (test_qemu_cmd (g, cmd, &g->qemu_help) == -1) {
-    perrorf (g, _("%s: command failed: If qemu is located on a non-standard path, try setting the LIBGUESTFS_QEMU environment variable."), cmd);
+    error (g, _("command failed: %s\n\nIf qemu is located on a non-standard path, try setting the LIBGUESTFS_QEMU\nenvironment variable.  There may also be errors printed above."),
+           cmd);
     return -1;
   }
 
@@ -1105,7 +1127,7 @@ test_qemu_cmd (guestfs_h *g, const char *cmd, char **ret)
     return -1;
   }
 
-  if (pclose (fp) == -1)
+  if (pclose (fp) != 0)
     return -1;
 
   return 0;