[Libguestfs] [PATCH 4/8 v2 DISCUSSION ONLY] daemon: Allow -r option to run daemon standalone.
Richard W.M. Jones
rjones at redhat.com
Fri Jan 28 19:37:59 UTC 2011
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
-------------- next part --------------
>From 5c5231800e53fc24f155a66effa768f30347f0eb Mon Sep 17 00:00:00 2001
From: Richard W.M. Jones <rjones at redhat.com>
Date: Thu, 27 Jan 2011 16:54:48 +0000
Subject: [PATCH 4/8] daemon: Allow -r option to run daemon standalone.
This changes several aspects of the daemon. Currently:
* sysroot will be "" (ie. operate directly on /)
* CHROOT_IN/CHROOT_OUT are disabled
* autosync doesn't try to unmount everything
---
daemon/daemon.h | 22 ++++++++++++++--------
daemon/guestfsd.c | 16 ++++++++++++++--
daemon/sync.c | 5 +++--
3 files changed, 31 insertions(+), 12 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h
index da991b1..4a686c0 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -33,6 +33,8 @@
/*-- in guestfsd.c --*/
extern int verbose;
+extern int autosync_umount;
+
extern const char *sysroot;
extern int sysroot_len;
@@ -253,17 +255,21 @@ extern void notify_progress (uint64_t position, uint64_t total);
*/
#define CHROOT_IN \
do { \
- int __old_errno = errno; \
- if (chroot (sysroot) == -1) \
- perror ("CHROOT_IN: sysroot"); \
- errno = __old_errno; \
+ if (sysroot_len > 0) { \
+ int __old_errno = errno; \
+ if (chroot (sysroot) == -1) \
+ perror ("CHROOT_IN: sysroot"); \
+ errno = __old_errno; \
+ } \
} while (0)
#define CHROOT_OUT \
do { \
- int __old_errno = errno; \
- if (chroot (".") == -1) \
- perror ("CHROOT_OUT: ."); \
- errno = __old_errno; \
+ if (sysroot_len > 0) { \
+ int __old_errno = errno; \
+ if (chroot (".") == -1) \
+ perror ("CHROOT_OUT: ."); \
+ errno = __old_errno; \
+ } \
} while (0)
/* Marks functions which are not implemented.
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c
index 8d950fa..94e4994 100644
--- a/daemon/guestfsd.c
+++ b/daemon/guestfsd.c
@@ -118,6 +118,9 @@ winsock_init (void)
const char *sysroot = "/sysroot"; /* No trailing slash. */
int sysroot_len = 8;
+/* If set (the default), do 'umount-all' when performing autosync. */
+int autosync_umount = 1;
+
/* Not used explicitly, but required by the gnulib 'error' module. */
const char *program_name = "guestfsd";
@@ -125,13 +128,13 @@ static void
usage (void)
{
fprintf (stderr,
- "guestfsd [-f|--foreground] [-v|--verbose]\n");
+ "guestfsd [-f|--foreground] [-v|--verbose] [-r]\n");
}
int
main (int argc, char *argv[])
{
- static const char *options = "fv?";
+ static const char *options = "frv?";
static const struct option long_options[] = {
{ "foreground", 0, 0, 'f' },
{ "help", 0, 0, '?' },
@@ -171,6 +174,15 @@ main (int argc, char *argv[])
dont_fork = 1;
break;
+ /* The -r flag is used when running standalone. It changes
+ * several aspects of the daemon.
+ */
+ case 'r':
+ sysroot = "";
+ sysroot_len = 0;
+ autosync_umount = 0;
+ break;
+
case 'v':
verbose = 1;
break;
diff --git a/daemon/sync.c b/daemon/sync.c
index 25c7de8..8f5a461 100644
--- a/daemon/sync.c
+++ b/daemon/sync.c
@@ -51,9 +51,10 @@ do_sync (void)
int
do_internal_autosync (void)
{
- int r;
+ int r = 0;
- r = do_umount_all ();
+ if (autosync_umount)
+ r = do_umount_all ();
sync_disks ();
--
1.7.3.5
More information about the Libguestfs
mailing list