From: Richard Jones Date: Sat, 8 May 2010 08:28:19 +0000 (+0100) Subject: launch: Rearrange the code so config check is first. X-Git-Tag: 1.3.11~5 X-Git-Url: http://git.annexia.org/?p=libguestfs.git;a=commitdiff_plain;h=55e9707f8591488542da48fc89738234b4d85016 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. --- 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) {