[Libguestfs] [PATCH 2/7] Add internal facility to checkpoint and roll back the command line.

Richard W.M. Jones rjones at redhat.com
Wed Nov 10 11:45:39 UTC 2010


-- 
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
-------------- next part --------------
>From 1c29849e0bdc731c023cff00d2c2354a41fd2a92 Mon Sep 17 00:00:00 2001
From: Richard Jones <rjones at redhat.com>
Date: Tue, 9 Nov 2010 18:50:57 +0000
Subject: [PATCH 2/7] Add internal facility to checkpoint and roll back the command line.

This internal interface can be used to ensure that certain
operations are atomic.
---
 src/guestfs-internal.h |    2 ++
 src/launch.c           |   20 ++++++++++++++++++++
 2 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 067251c..f8b3e94 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -234,6 +234,8 @@ extern int guestfs___match2 (guestfs_h *g, const char *str, const pcre *re, char
 #endif
 extern int guestfs___feature_available (guestfs_h *g, const char *feature);
 extern void guestfs___free_string_list (char **);
+extern int guestfs___checkpoint_cmdline (guestfs_h *g);
+extern void guestfs___rollback_cmdline (guestfs_h *g, int pos);
 
 #define error(g,...) guestfs_error_errno((g),0,__VA_ARGS__)
 #define perrorf guestfs_perrorf
diff --git a/src/launch.c b/src/launch.c
index e5bca56..48ddb8d 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -34,6 +34,7 @@
 #include <sys/select.h>
 #include <dirent.h>
 #include <signal.h>
+#include <assert.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
@@ -101,6 +102,25 @@ add_cmdline (guestfs_h *g, const char *str)
 }
 
 int
+guestfs___checkpoint_cmdline (guestfs_h *g)
+{
+  return g->cmdline_size;
+}
+
+void
+guestfs___rollback_cmdline (guestfs_h *g, int pos)
+{
+  int i;
+
+  assert (g->cmdline_size >= pos);
+
+  for (i = g->cmdline_size - 1; i >= pos; --i)
+    free (g->cmdline[i]);
+
+  g->cmdline_size = pos;
+}
+
+int
 guestfs__config (guestfs_h *g,
                  const char *qemu_param, const char *qemu_value)
 {
-- 
1.7.3.2



More information about the Libguestfs mailing list