-guestfs_launch (guestfs_h *g)
-{
- static const char *dir_template = "/tmp/libguestfsXXXXXX";
- int r, i;
- const char *qemu = QEMU; /* XXX */
- const char *kernel = "/boot/vmlinuz-2.6.27.15-170.2.24.fc10.x86_64";
- const char *initrd = "/boot/initrd-2.6.27.15-170.2.24.fc10.x86_64.img";
- char unixsock[256];
- char vmchannel[256];
- char tmpfile[256];
-
- /* XXX Choose which qemu to run. */
- /* XXX Choose initrd, etc. */
-
- /* Make the temporary directory containing the logfile and socket. */
- if (!g->tmpdir) {
- g->tmpdir = safe_strdup (g, dir_template);
- if (mkdtemp (g->tmpdir) == NULL)
- return perrorf (g, "%s: cannot create temporary directory", dir_template);
-
- snprintf (unixsock, sizeof unixsock, "%s/sock", g->tmpdir);
- }
-
- r = fork ();
- if (r == -1)
- return perrorf (g, "fork");
-
- if (r > 0) { /* Parent (library). */
- g->pid = r;
-
- /* If qemu is going to die during startup, give it a tiny amount of
- * time to print the error message.
- */
- usleep (10000);
- } else { /* Child (qemu). */
- /* Set up the full command line. Do this in the subprocess so we
- * don't need to worry about cleaning up.
- */
- g->cmdline[0] = (char *) qemu;
-
- g->cmdline = realloc (g->cmdline, sizeof (char *) * (g->cmdline_size + 14));
- if (g->cmdline == NULL) {
- perror ("realloc");
- _exit (1);
- }
-
- snprintf (vmchannel, sizeof vmchannel,
- "channel,%d:unix:%s,server,nowait", 666, unixsock);
-
- g->cmdline[g->cmdline_size ] = "-kernel";
- g->cmdline[g->cmdline_size+ 1] = (char *) kernel;
- g->cmdline[g->cmdline_size+ 2] = "-initrd";
- g->cmdline[g->cmdline_size+ 3] = (char *) initrd;
- g->cmdline[g->cmdline_size+ 4] = "-append";
- g->cmdline[g->cmdline_size+ 5] = "console=ttyS0";
- g->cmdline[g->cmdline_size+ 6] = "-nographic";
- g->cmdline[g->cmdline_size+ 7] = "-serial";
- g->cmdline[g->cmdline_size+ 8] = "stdio";
- g->cmdline[g->cmdline_size+ 9] = "-net";
- g->cmdline[g->cmdline_size+10] = vmchannel;
- g->cmdline[g->cmdline_size+11] = "-net";
- g->cmdline[g->cmdline_size+12] = "user,vlan0";
- g->cmdline[g->cmdline_size+13] = NULL;
-
- if (g->verbose) {
- fprintf (stderr, "Running %s", qemu);
- for (i = 0; g->cmdline[i]; ++i)
- fprintf (stderr, " %s", g->cmdline[i]);
- fprintf (stderr, "\n");
- }
-
- /* Set up stdin, stdout. Messages should go to the logfile. */
- close (0);
- close (1);
- open ("/dev/null", O_RDONLY);
- snprintf (tmpfile, sizeof tmpfile, "%s/qemu.log", g->tmpdir);
- open (tmpfile, O_WRONLY|O_CREAT|O_APPEND, 0644);
- /*dup2 (1, 2);*/
-
- execv (qemu, g->cmdline); /* Run qemu. */
- perror (qemu);
- _exit (1);
- }