X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=blobdiff_plain;f=src%2Fguestfs.c;h=72cd2f36693f7d4b2cf8b06b944f44942bec71fa;hp=66ab12af0438960f63bd597a5cd2c2eb3992e8f6;hb=9e8e99c921bccb9ac3b3965a7d689ff443799426;hpb=d5532e9ad29b28c2b323ad0abe4e0caa6e03f675 diff --git a/src/guestfs.c b/src/guestfs.c index 66ab12a..72cd2f3 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -327,6 +327,25 @@ guestfs_close (guestfs_h *g) if (g->state != CONFIG) guestfs_kill_subprocess (g); + /* Close any sockets and deregister any handlers. */ + if (g->stdout_watch >= 0) + g->main_loop->remove_handle (g->main_loop, g, g->stdout_watch); + if (g->sock_watch >= 0) + g->main_loop->remove_handle (g->main_loop, g, g->sock_watch); + g->stdout_watch = -1; + g->sock_watch = -1; + + if (g->fd[0] >= 0) + close (g->fd[0]); + if (g->fd[1] >= 0) + close (g->fd[1]); + if (g->sock >= 0) + close (g->sock); + g->fd[0] = -1; + g->fd[1] = -1; + g->sock = -1; + + /* Remove tmpfiles. */ if (g->tmpdir) { snprintf (filename, sizeof filename, "%s/sock", g->tmpdir); unlink (filename); @@ -678,6 +697,19 @@ guestfs_get_pid (guestfs_h *g) } } +struct guestfs_version * +guestfs_version (guestfs_h *g) +{ + struct guestfs_version *r; + + r = safe_malloc (g, sizeof *r); + r->major = PACKAGE_VERSION_MAJOR; + r->minor = PACKAGE_VERSION_MINOR; + r->release = PACKAGE_VERSION_RELEASE; + r->extra = safe_strdup (g, PACKAGE_VERSION_EXTRA); + return r; +} + /* Add a string to the current command line. */ static void incr_cmdline_size (guestfs_h *g) @@ -843,7 +875,8 @@ static const char *supermin_hostfiles_name = int guestfs_launch (guestfs_h *g) { - static const char *dir_template = "/tmp/libguestfsXXXXXX"; + const char *tmpdir; + char dir_template[PATH_MAX]; int r, i, pmore; size_t len; int wfd[2], rfd[2]; @@ -853,6 +886,15 @@ guestfs_launch (guestfs_h *g) char unixsock[256]; struct sockaddr_un addr; +#ifdef P_tmpdir + tmpdir = P_tmpdir; +#else + tmpdir = "/tmp"; +#endif + + tmpdir = getenv ("TMPDIR") ? : tmpdir; + snprintf (dir_template, sizeof dir_template, "%s/libguestfsXXXXXX", tmpdir); + /* Configured? */ if (!g->cmdline) { error (g, _("you must call guestfs_add_drive before guestfs_launch")); @@ -996,14 +1038,17 @@ guestfs_launch (guestfs_h *g) */ g->cmdline[0] = g->qemu; - /* Construct the -net channel parameter for qemu. */ - snprintf (vmchannel, sizeof vmchannel, - "channel,%d:unix:%s,server,nowait", - VMCHANNEL_PORT, unixsock); +#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 */ \ + "cgroup_disable=memory " /* saves us about 5 MB of RAM */ /* Linux kernel command line. */ snprintf (append, sizeof append, - "panic=1 console=ttyS0 guestfs=%s:%d%s%s%s", + LINUX_CMDLINE "guestfs=%s:%d%s%s%s", VMCHANNEL_ADDR, VMCHANNEL_PORT, g->verbose ? " guestfs_verbose=1" : "", g->append ? " " : "", g->append ? g->append : ""); @@ -1022,10 +1067,38 @@ guestfs_launch (guestfs_h *g) add_cmdline (g, "-nographic"); add_cmdline (g, "-serial"); add_cmdline (g, "stdio"); - add_cmdline (g, "-net"); - add_cmdline (g, vmchannel); - add_cmdline (g, "-net"); - add_cmdline (g, "user,vlan=0"); + +#if 0 + /* Doesn't work. See: + * http://lists.gnu.org/archive/html/qemu-devel/2009-07/threads.html + * Subject "guestfwd option doesn't allow supplementary ,server,nowait" + */ + if (qemu_supports (g, "guestfwd")) { + /* New-style -net user,guestfwd=... syntax for vmchannel. See: + * http://git.savannah.gnu.org/cgit/qemu.git/commit/?id=c92ef6a22d3c71538fcc48fb61ad353f7ba03b62 + */ + snprintf (vmchannel, sizeof vmchannel, + "user,vlan=0,guestfwd=tcp:%s:%d-unix:%s,server,nowait", + VMCHANNEL_ADDR, VMCHANNEL_PORT, unixsock); + + add_cmdline (g, "-net"); + add_cmdline (g, vmchannel); + } else { +#endif + /* Not guestfwd. HOPEFULLY this qemu uses the older -net channel + * syntax, or if not then we'll get a quick failure. + */ + snprintf (vmchannel, sizeof vmchannel, + "channel,%d:unix:%s,server,nowait", + VMCHANNEL_PORT, unixsock); + + add_cmdline (g, "-net"); + add_cmdline (g, vmchannel); + add_cmdline (g, "-net"); + add_cmdline (g, "user,vlan=0"); +#if 0 + } +#endif add_cmdline (g, "-net"); add_cmdline (g, "nic,model=virtio,vlan=0");