From 55e9707f8591488542da48fc89738234b4d85016 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Sat, 8 May 2010 09:28:19 +0100 Subject: [PATCH] launch: Rearrange the code so config check is first. Move the config state check first in the guestfs_launch function, so that we don't reset g->launch_t or calculate the temporary directory in the case where the launch function will immediately return with an error. --- src/guestfs.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/guestfs.c b/src/guestfs.c index 2fc73ef..027e08c 100644 --- a/src/guestfs.c +++ b/src/guestfs.c @@ -948,9 +948,21 @@ guestfs__launch (guestfs_h *g) char unixsock[256]; struct sockaddr_un addr; + /* Configured? */ + if (!g->cmdline) { + error (g, _("you must call guestfs_add_drive before guestfs_launch")); + return -1; + } + + if (g->state != CONFIG) { + error (g, _("the libguestfs handle has already been launched")); + return -1; + } + /* Start the clock ... */ gettimeofday (&g->launch_t, NULL); + /* Make the temporary directory. */ #ifdef P_tmpdir tmpdir = P_tmpdir; #else @@ -960,18 +972,6 @@ guestfs__launch (guestfs_h *g) 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")); - return -1; - } - - if (g->state != CONFIG) { - error (g, _("qemu has already been launched")); - return -1; - } - - /* Make the temporary directory. */ if (!g->tmpdir) { g->tmpdir = safe_strdup (g, dir_template); if (mkdtemp (g->tmpdir) == NULL) { -- 1.8.3.1