[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/8 v2 DISCUSSION ONLY] Move appliance launching to separate function.



-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
>From 60e78e2ddcc38f752844a280ad3e29491402503e Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones redhat com>
Date: Thu, 27 Jan 2011 10:12:34 +0000
Subject: [PATCH 1/8] lib: Move appliance launching to separate function.

This is just code motion.
---
 src/launch.c |   38 ++++++++++++++++++++++++--------------
 1 files changed, 24 insertions(+), 14 deletions(-)

diff --git a/src/launch.c b/src/launch.c
index a7a86b9..775f7a6 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -70,6 +70,7 @@
 #include "guestfs-internal-actions.h"
 #include "guestfs_protocol.h"
 
+static int launch_appliance (guestfs_h *g);
 static int qemu_supports (guestfs_h *g, const char *option);
 
 /* Add a string to the current command line. */
@@ -350,32 +351,19 @@ static int is_openable (guestfs_h *g, const char *path, int flags);
 int
 guestfs__launch (guestfs_h *g)
 {
-  int r;
-  int wfd[2], rfd[2];
-  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. */
   if (!g->tmpdir) {
     TMP_TEMPLATE_ON_STACK (dir_template);
     g->tmpdir = safe_strdup (g, dir_template);
     if (mkdtemp (g->tmpdir) == NULL) {
       perrorf (g, _("%s: cannot create temporary directory"), dir_template);
-      goto cleanup0;
+      return -1;
     }
   }
 
@@ -386,6 +374,28 @@ guestfs__launch (guestfs_h *g)
   if (chmod (g->tmpdir, 0755) == -1)
     fprintf (stderr, "chmod: %s: %m (ignored)\n", g->tmpdir);
 
+  return launch_appliance (g);
+}
+
+static int
+launch_appliance (guestfs_h *g)
+{
+  int r;
+  int wfd[2], rfd[2];
+  char unixsock[256];
+  struct sockaddr_un addr;
+
+  /* At present you must add drives before starting the appliance.  In
+   * future when we enable hotplugging you won't need to do this.
+   */
+  if (!g->cmdline) {
+    error (g, _("you must call guestfs_add_drive before guestfs_launch"));
+    return -1;
+  }
+
+  /* Start the clock ... */
+  gettimeofday (&g->launch_t, NULL);
+
   /* Locate and/or build the appliance. */
   char *kernel = NULL, *initrd = NULL, *appliance = NULL;
   if (guestfs___build_appliance (g, &kernel, &initrd, &appliance) == -1)
-- 
1.7.3.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]