+ add_cmdline (g, "-net");
+ add_cmdline (g, buf);
+
+ vmchannel = "guestfs_vmchannel=tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT;
+ }
+
+ /* Not guestfwd. HOPEFULLY this qemu uses the older -net channel
+ * syntax, or if not then we'll get a quick failure.
+ */
+ else {
+ snprintf (buf, sizeof buf,
+ "channel," GUESTFWD_PORT ":unix:%s,server,nowait", unixsock);
+
+ add_cmdline (g, "-net");
+ add_cmdline (g, buf);
+ add_cmdline (g, "-net");
+ add_cmdline (g, "user,vlan=0,net=10.0.2.0/8");
+
+ vmchannel = "guestfs_vmchannel=tcp:" GUESTFWD_ADDR ":" GUESTFWD_PORT;
+ }
+ add_cmdline (g, "-net");
+ add_cmdline (g, "nic,model=" NET_IF ",vlan=0");
+
+#define LINUX_CMDLINE \
+ "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 */ \
+ "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 */
+
+ /* Linux kernel command line. */
+ snprintf (buf, sizeof buf,
+ LINUX_CMDLINE
+ "%s " /* (selinux) */
+ "%s " /* (vmchannel) */
+ "%s " /* (verbose) */
+ "%s", /* (append) */
+ g->selinux ? "selinux=1 enforcing=0" : "selinux=0",
+ vmchannel ? vmchannel : "",
+ g->verbose ? "guestfs_verbose=1" : "",
+ g->append ? g->append : "");
+
+ add_cmdline (g, "-kernel");
+ add_cmdline (g, (char *) kernel);
+ add_cmdline (g, "-initrd");
+ add_cmdline (g, (char *) initrd);
+ add_cmdline (g, "-append");
+ add_cmdline (g, buf);
+
+ /* Finish off the command line. */
+ incr_cmdline_size (g);
+ g->cmdline[g->cmdline_size-1] = NULL;
+
+ if (g->verbose)
+ print_cmdline (g);
+
+ if (!g->direct) {
+ /* Set up stdin, stdout. */
+ close (0);
+ close (1);
+ close (wfd[1]);
+ close (rfd[0]);
+
+ if (dup (wfd[0]) == -1) {
+ dup_failed:
+ perror ("dup failed");
+ _exit (1);
+ }
+ if (dup (rfd[1]) == -1)
+ goto dup_failed;
+
+ close (wfd[0]);
+ close (rfd[1]);
+ }
+
+#if 0
+ /* Set up a new process group, so we can signal this process
+ * and all subprocesses (eg. if qemu is really a shell script).
+ */
+ setpgid (0, 0);
+#endif
+
+ setenv ("LC_ALL", "C", 1);
+
+ execv (g->qemu, g->cmdline); /* Run qemu. */
+ perror (g->qemu);
+ _exit (1);