- libxml2 (optional)
+- libconfig (optional, to parse /etc/libguestfs-tools.conf)
+
- Augeas (http://augeas.net/) (optional)
- gperf
# libguestfs virt-cat, virt-filesystems and virt-ls.
-# Copyright (C) 2010 Red Hat Inc.
+# Copyright (C) 2010-2011 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
bin_PROGRAMS = virt-cat virt-filesystems virt-ls
SHARED_SOURCE_FILES = \
+ ../fish/config.c \
../fish/inspect.c \
../fish/keys.c \
../fish/options.h \
-I$(top_srcdir)/fish \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
- $(WARN_CFLAGS) $(WERROR_CFLAGS)
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(LIBCONFIG_CFLAGS)
virt_cat_LDADD = \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la
-I$(top_srcdir)/fish \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
- $(WARN_CFLAGS) $(WERROR_CFLAGS)
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(LIBCONFIG_CFLAGS)
virt_filesystems_LDADD = \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la
-I$(top_srcdir)/fish \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
- $(WARN_CFLAGS) $(WERROR_CFLAGS)
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(LIBCONFIG_CFLAGS)
virt_ls_LDADD = \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la
[AC_MSG_WARN([libxml2 not found, some core features will be disabled])])
AM_CONDITIONAL([HAVE_LIBXML2],[test "x$LIBXML2_LIBS" != "x"])
+dnl libconfig (highly recommended)
+PKG_CHECK_MODULES([LIBCONFIG], [libconfig],
+ [AC_SUBST([LIBCONFIG_CFLAGS])
+ AC_SUBST([LIBCONFIG_LIBS])
+ AC_DEFINE([HAVE_LIBCONFIG],[1],[libconfig found at compile time.])
+ ],
+ [AC_MSG_WARN([libconfig not found, some features will be disabled])])
+AM_CONDITIONAL([HAVE_LIBCONFIG],[test "x$LIBCONFIG_LIBS" != "x"])
+
dnl hivex library (highly recommended)
dnl This used to be a part of libguestfs, but was spun off into its
dnl own separate upstream project in libguestfs 1.0.85.
# libguestfs virt-df
-# Copyright (C) 2010 Red Hat Inc.
+# Copyright (C) 2010-2011 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
bin_PROGRAMS = virt-df
SHARED_SOURCE_FILES = \
+ ../fish/config.c \
../fish/inspect.c \
../fish/keys.c \
../fish/options.h \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
$(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(LIBCONFIG_CFLAGS) \
$(LIBVIRT_CFLAGS)
virt_df_LDADD = \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la \
$(LIBVIRT_LIBS) \
# libguestfs
-# Copyright (C) 2009-2010 Red Hat Inc.
+# Copyright (C) 2009-2011 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# so we know which ones are shared. These files must not include
# other guestfish files.
SHARED_SOURCE_FILES = \
+ config.c \
inspect.c \
keys.c \
options.h \
-DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
- $(WARN_CFLAGS) $(WERROR_CFLAGS)
+ $(WARN_CFLAGS) $(WERROR_CFLAGS) \
+ $(LIBCONFIG_CFLAGS)
guestfish_LDADD = \
- $(top_builddir)/src/libguestfs.la $(LIBREADLINE) -lm
+ $(LIBCONFIG_LIBS) \
+ $(LIBREADLINE) \
+ $(top_builddir)/src/libguestfs.la -lm
# Make guestfish use the convenience libraries.
noinst_LTLIBRARIES = libcmds.la librc_protocol.la
$<
touch $@
+# libguestfs tools config file.
+
+toolsconfdir = $(sysconfdir)
+toolsconf_DATA = libguestfs-tools.conf
+
# Bash completion script.
bashcompletiondir = $(sysconfdir)/bash_completion.d
--- /dev/null
+/* libguestfs - guestfish and guestmount shared option parsing
+ * Copyright (C) 2011 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#ifdef HAVE_LIBCONFIG
+#include <libconfig.h>
+#endif
+
+#include "guestfs.h"
+
+#include "options.h"
+
+static const char *home_filename = /* $HOME/ */ ".libguestfs-tools.rc";
+static const char *etc_filename = "/etc/libguestfs-tools.conf";
+
+#ifdef HAVE_LIBCONFIG
+
+/* Note that parse_config is called very early, before command line
+ * parsing and before the verbose flag has been set.
+ */
+
+void
+parse_config (void)
+{
+ const char *home;
+ size_t len;
+ char *path;
+ FILE *fp;
+ config_t conf;
+
+ config_init (&conf);
+
+ /* Try $HOME first. */
+ home = getenv ("HOME");
+ if (home != NULL) {
+ len = strlen (home) + 1 + strlen (home_filename) + 1;
+ path = malloc (len);
+ if (path == NULL) {
+ perror ("malloc");
+ exit (EXIT_FAILURE);
+ }
+ snprintf (path, len, "%s/%s", home, home_filename);
+
+ fp = fopen (path, "r");
+ if (fp != NULL) {
+ /*
+ if (verbose)
+ fprintf (stderr, "%s: reading configuration from %s\n",
+ program_name, path);
+ */
+
+ if (config_read (&conf, fp) == CONFIG_FALSE) {
+ fprintf (stderr,
+ _("%s: %s: line %d: error parsing configuration file: %s\n"),
+ program_name, path, config_error_line (&conf),
+ config_error_text (&conf));
+ exit (EXIT_FAILURE);
+ }
+
+ if (fclose (fp) == -1) {
+ perror (path);
+ exit (EXIT_FAILURE);
+ }
+
+ /* Notes:
+ *
+ * (1) It's not obvious from the documentation, that config_read
+ * completely resets the 'conf' structure. This means we cannot
+ * call config_read twice on the two possible configuration
+ * files, but instead have to copy out settings into our
+ * variables between calls.
+ *
+ * (2) If the next call fails then 'read_only' variable is not
+ * updated. Failure could happen just because the setting is
+ * missing from the configuration file, so we ignore it here.
+ */
+ config_lookup_bool (&conf, "read_only", &read_only);
+ }
+
+ free (path);
+ }
+
+ fp = fopen (etc_filename, "r");
+ if (fp != NULL) {
+ /*
+ if (verbose)
+ fprintf (stderr, "%s: reading configuration from %s\n",
+ program_name, etc_filename);
+ */
+
+ if (config_read (&conf, fp) == CONFIG_FALSE) {
+ fprintf (stderr,
+ _("%s: %s: line %d: error parsing configuration file: %s\n"),
+ program_name, etc_filename, config_error_line (&conf),
+ config_error_text (&conf));
+ exit (EXIT_FAILURE);
+ }
+
+ if (fclose (fp) == -1) {
+ perror (path);
+ exit (EXIT_FAILURE);
+ }
+
+ config_lookup_bool (&conf, "read_only", &read_only);
+ }
+
+ config_destroy (&conf);
+}
+
+#else /* !HAVE_LIBCONFIG */
+
+void
+parse_config (void)
+{
+ /*
+ if (verbose)
+ fprintf (stderr,
+ _("%s: compiled without libconfig, guestfish configuration file ignored\n"),
+ program_name);
+ */
+}
+
+#endif /* !HAVE_LIBCONFIG */
bindtextdomain (PACKAGE, LOCALEBASEDIR);
textdomain (PACKAGE);
+ parse_config ();
+
set_up_terminal ();
enum { HELP_OPTION = CHAR_MAX + 1 };
=item B<--rw>
-This option does nothing at the moment.
+This changes the I<-a>, I<-d> and I<-m> options so that disks are
+added and mounts are done read-write.
+
See L</OPENING DISKS FOR READ AND WRITE> below.
=item B<-x>
=head1 OPENING DISKS FOR READ AND WRITE
-The guestfish (and L<guestmount(1)>) options I<--ro> and I<--rw>
-affect whether the other command line options I<-a>, I<-c>, I<-d>,
-I<-i> and I<-m> open disk images read-only or for writing.
+The guestfish, L<guestmount(1)> and L<virt-rescue(1)> options I<--ro>
+and I<--rw> affect whether the other command line options I<-a>,
+I<-c>, I<-d>, I<-i> and I<-m> open disk images read-only or for
+writing.
-In libguestfs E<lt> 1.6.2, guestfish and guestmount defaulted to
-opening disk images supplied on the command line for write. To open a
-disk image read-only you have to do I<-a image --ro>.
+In libguestfs E<le> 1.8, guestfish, guestmount and virt-rescue
+defaulted to opening disk images supplied on the command line for
+write. To open a disk image read-only you have to do I<-a image --ro>.
This matters: If you accidentally open a live VM disk image writable
then you will cause irreversible disk corruption.
-By libguestfs 1.10 we intend to change the default the other way. Disk
-images will be opened read-only. You will have to either specify
-I<guestfish --rw> or change a configuration file in order to get write
-access for disk images specified by those other command line options.
+By libguestfs 1.10 we intend to change the default the other way.
+Disk images will be opened read-only. You will have to either specify
+I<guestfish --rw>, I<guestmount --rw>, I<virt-rescue --rw>, or change
+the configuration file C</etc/libguestfs-tools.conf> in order to get
+write access for disk images specified by those other command line
+options.
-This version of guestfish has a I<--rw> option which does nothing (it
-is already the default). However it is highly recommended that you
-use this option to indicate that guestfish needs write access, and to
-prepare your scripts for the day when this option will be required for
-write access.
+This version of guestfish, guestmount and virt-rescue has a I<--rw>
+option which does nothing (it is already the default). However it is
+highly recommended that you use this option to indicate that you need
+write access, and prepare your scripts for the day when this option
+will be required for write access.
B<Note:> This does I<not> affect commands like L</add> and L</mount>,
or any other libguestfs program apart from guestfish and guestmount.
=over 4
+=item $HOME/.libguestfs-tools.rc
+
+=item /etc/libguestfs-tools.conf
+
+This configuration file controls the default read-only or read-write
+mode (I<--ro> or I<--rw>).
+
+See L</OPENING DISKS FOR READ AND WRITE>.
+
=item $HOME/.guestfish
If compiled with GNU readline support, then the command history
=head1 COPYRIGHT
-Copyright (C) 2009-2010 Red Hat Inc.
+Copyright (C) 2009-2011 Red Hat Inc.
L<http://libguestfs.org/>
This program is free software; you can redistribute it and/or modify
--- /dev/null
+# /etc/libguestfs-tools.conf or .libguestfs-tools.rc
+#
+# This configuration file changes the defaults for the following programs:
+# * guestfish
+# * guestmount
+# * virt-rescue
+# For more information on these programs, read the manual pages
+# (guestfish(1) etc).
+#
+# /etc/libguestfs-tools.conf is the global configuration file for all
+# of the above programs. Local users can override the global
+# configuration by copying this file into '.libguestfs-tools.rc' in
+# their home directory and modifying it accordingly.
+#
+# This file is parsed by the libconfig library. For more information
+# about the format, see
+# http://www.hyperrealm.com/libconfig/libconfig_manual.html
+
+# Uncomment the following line to make guestfish, guestmount,
+# virt-rescue be read-only by default (as if the --ro flag was given).
+# If it is commented out then the default is read-write. Note that
+# the semi-colon (;) is required.
+
+#read_only = true;
char *options;
};
+/* in config.c */
+extern void parse_config (void);
+
/* in inspect.c */
extern void inspect_mount (void);
extern void print_inspect_prompt (void);
# These source files (all related to option parsing) are shared
# between guestfish and guestmount.
SHARED_SOURCE_FILES = \
+ ../fish/config.c \
../fish/inspect.c \
../fish/keys.c \
../fish/options.h \
-DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
$(FUSE_CFLAGS) \
+ $(LIBCONFIG_CFLAGS) \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
guestmount_LDADD = \
$(FUSE_LIBS) -lulockmgr \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la
bindtextdomain (PACKAGE, LOCALEBASEDIR);
textdomain (PACKAGE);
+ parse_config ();
+
enum { HELP_OPTION = CHAR_MAX + 1 };
/* The command line arguments are broadly compatible with (a subset
=item B<-w> | B<--rw>
-This option does nothing at the moment.
+This changes the I<-a>, I<-d> and I<-m> options so that disks are
+added and mounts are done read-write.
+
See L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
=item B<-x> | B<--trace>
=back
+=head1 FILES
+
+=over 4
+
+=item $HOME/.libguestfs-tools.rc
+
+=item /etc/libguestfs-tools.conf
+
+This configuration file controls the default read-only or read-write
+mode (I<--ro> or I<--rw>).
+
+See L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
+
+=back
+
=head1 SEE ALSO
L<guestfish(1)>,
# libguestfs virt-inspector
-# Copyright (C) 2009-2010 Red Hat Inc.
+# Copyright (C) 2009-2011 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
bin_PROGRAMS = virt-inspector
SHARED_SOURCE_FILES = \
+ ../fish/config.c \
../fish/inspect.c \
../fish/keys.c \
../fish/options.h \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
$(LIBXML2_CFLAGS) \
+ $(LIBCONFIG_CFLAGS) \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
virt_inspector_LDADD = \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
$(LIBXML2_LIBS) \
../gnulib/lib/libgnu.la
fish/cmds.c
fish/cmds_gperf.c
fish/completion.c
+fish/config.c
fish/copy.c
fish/destpaths.c
fish/echo.c
# libguestfs virt-rescue
-# Copyright (C) 2010 Red Hat Inc.
+# Copyright (C) 2010-2011 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
bin_PROGRAMS = virt-rescue
SHARED_SOURCE_FILES = \
+ ../fish/config.c \
../fish/inspect.c \
../fish/keys.c \
../fish/options.h \
-I$(top_srcdir)/fish \
-I$(srcdir)/../gnulib/lib -I../gnulib/lib \
-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
+ $(LIBCONFIG_CFLAGS) \
$(WARN_CFLAGS) $(WERROR_CFLAGS)
virt_rescue_LDADD = \
+ $(LIBCONFIG_LIBS) \
$(top_builddir)/src/libguestfs.la \
../gnulib/lib/libgnu.la
bindtextdomain (PACKAGE, LOCALEBASEDIR);
textdomain (PACKAGE);
+ parse_config ();
+
enum { HELP_OPTION = CHAR_MAX + 1 };
static const char *options = "a:c:d:m:rvVx";
might be running, and is generally recommended in cases where you
don't need write access to the disk.
+See also L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
+
=item B<--selinux>
Enable SELinux in the rescue appliance. You should read
=item B<--rw>
-This option does nothing at the moment.
+This changes the I<-a> and I<-d> options so that disks are
+added and mounts are done read-write.
+
See L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
=item B<-x>
quote or escape these characters on the command line. See the shell
manual page L<sh(1)> for details.
+=head1 FILES
+
+=over 4
+
+=item $HOME/.libguestfs-tools.rc
+
+=item /etc/libguestfs-tools.conf
+
+This configuration file controls the default read-only or read-write
+mode (I<--ro> or I<--rw>).
+
+See L<guestfish(1)/OPENING DISKS FOR READ AND WRITE>.
+
+=back
+
=head1 SEE ALSO
L<guestfs(3)>,
=head1 COPYRIGHT
-Copyright (C) 2009-2010 Red Hat Inc.
+Copyright (C) 2009-2011 Red Hat Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by