From a9199a46b12b4efe3a12046e556a8b52032e8cda Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 20 Jan 2017 11:24:49 +0000 Subject: [PATCH] fish: Move fishcommon library to common/options. This is mostly code motion but: (1) I had to remove the compile-time COMPILING_GUESTFISH and COMPILING_VIRT_RESCUE macros and replace them with runtime constants and checks. (2) I moved the fish/config.c file into this library. --- Makefile.am | 2 +- align/Makefile.am | 3 +- align/scan.c | 2 + cat/Makefile.am | 15 ++++--- cat/cat.c | 2 + cat/filesystems.c | 2 + cat/log.c | 2 + cat/ls.c | 2 + cat/tail.c | 2 + common/options/Makefile.am | 50 +++++++++++++++++++++ {fish => common/options}/config.c | 0 {fish => common/options}/decrypt.c | 0 {fish => common/options}/display-options.c | 0 {fish => common/options}/display-options.h | 0 {fish => common/options}/domain.c | 0 {fish => common/options}/inspect.c | 1 - {fish => common/options}/keys.c | 0 {fish => common/options}/options.c | 12 ++--- {fish => common/options}/options.h | 13 +----- {fish => common/options}/uri.c | 0 {fish => common/options}/uri.h | 0 configure.ac | 1 + df/Makefile.am | 3 +- df/main.c | 6 +++ diff/Makefile.am | 3 +- diff/diff.c | 2 + docs/C_SOURCE_FILES | 22 +++++----- docs/guestfs-hacking.pod | 4 ++ edit/Makefile.am | 3 +- edit/edit.c | 2 + fish/Makefile.am | 51 +++------------------- fish/fish.c | 2 + format/Makefile.am | 3 +- format/format.c | 2 + fuse/Makefile.am | 16 +++---- fuse/guestmount.c | 2 + inspector/Makefile.am | 3 +- inspector/inspector.c | 2 + make-fs/Makefile.am | 3 +- make-fs/make-fs.c | 2 + mllib/Makefile.am | 7 +-- po/POTFILES | 17 ++++---- rescue/Makefile.am | 20 ++------- rescue/rescue.c | 2 + 44 files changed, 157 insertions(+), 129 deletions(-) create mode 100644 common/options/Makefile.am rename {fish => common/options}/config.c (100%) rename {fish => common/options}/decrypt.c (100%) rename {fish => common/options}/display-options.c (100%) rename {fish => common/options}/display-options.h (100%) rename {fish => common/options}/domain.c (100%) rename {fish => common/options}/inspect.c (99%) rename {fish => common/options}/keys.c (100%) rename {fish => common/options}/options.c (98%) rename {fish => common/options}/options.h (98%) rename {fish => common/options}/uri.c (100%) rename {fish => common/options}/uri.h (100%) diff --git a/Makefile.am b/Makefile.am index a7fddd463..604ca51b0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -89,7 +89,7 @@ SUBDIRS += tests/tsk endif # Common code used by the tools. -SUBDIRS += common/visit +SUBDIRS += common/visit common/options # libguestfs-test-tool SUBDIRS += test-tool diff --git a/align/Makefile.am b/align/Makefile.am index 0568efb2e..98543139a 100644 --- a/align/Makefile.am +++ b/align/Makefile.am @@ -41,6 +41,7 @@ virt_alignment_scan_CPPFLAGS = \ -DGUESTFS_WARN_DEPRECATED=1 \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/df \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib \ @@ -53,9 +54,9 @@ virt_alignment_scan_CFLAGS = \ $(LIBVIRT_CFLAGS) virt_alignment_scan_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/align/scan.c b/align/scan.c index 953ee913a..175df1e83 100644 --- a/align/scan.c +++ b/align/scan.c @@ -66,6 +66,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 0; +int in_guestfish = 0; +int in_virt_rescue = 0; static int quiet = 0; /* --quiet */ static int uuid = 0; /* --uuid */ diff --git a/cat/Makefile.am b/cat/Makefile.am index 632f4c003..14d23b08b 100644 --- a/cat/Makefile.am +++ b/cat/Makefile.am @@ -45,6 +45,7 @@ virt_cat_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -53,9 +54,9 @@ virt_cat_CFLAGS = \ $(LIBXML2_CFLAGS) virt_cat_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ @@ -70,6 +71,7 @@ virt_filesystems_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -78,9 +80,9 @@ virt_filesystems_CFLAGS = \ $(LIBXML2_CFLAGS) virt_filesystems_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ @@ -95,6 +97,7 @@ virt_log_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -103,9 +106,9 @@ virt_log_CFLAGS = \ $(LIBXML2_CFLAGS) virt_log_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ @@ -121,6 +124,7 @@ virt_ls_CPPFLAGS = \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ -I$(top_srcdir)/common/visit \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -129,10 +133,10 @@ virt_ls_CFLAGS = \ $(LIBXML2_CFLAGS) virt_ls_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/visit/libvisit.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ @@ -147,6 +151,7 @@ virt_tail_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -155,9 +160,9 @@ virt_tail_CFLAGS = \ $(LIBXML2_CFLAGS) virt_tail_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/cat/cat.c b/cat/cat.c index 1ac32d75a..90f6fb0d6 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -47,6 +47,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; static int do_cat (int argc, char *argv[]); diff --git a/cat/filesystems.c b/cat/filesystems.c index 73967d7bb..1036c6f4a 100644 --- a/cat/filesystems.c +++ b/cat/filesystems.c @@ -49,6 +49,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 0; +int in_guestfish = 0; +int in_virt_rescue = 0; static int csv = 0; /* --csv */ static int human = 0; /* --human-readable|-h */ diff --git a/cat/log.c b/cat/log.c index 84528bd7c..cc180ecea 100644 --- a/cat/log.c +++ b/cat/log.c @@ -51,6 +51,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; #define JOURNAL_DIR "/var/log/journal" diff --git a/cat/ls.c b/cat/ls.c index 2e327d9b9..e0b5ff8bc 100644 --- a/cat/ls.c +++ b/cat/ls.c @@ -52,6 +52,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; static int csv = 0; static int human = 0; diff --git a/cat/tail.c b/cat/tail.c index 0066be734..8785d453a 100644 --- a/cat/tail.c +++ b/cat/tail.c @@ -51,6 +51,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; static int do_tail (int argc, char *argv[], struct drv *drvs, struct mp *mps); static time_t disk_mtime (struct drv *drvs); diff --git a/common/options/Makefile.am b/common/options/Makefile.am new file mode 100644 index 000000000..4aab6b110 --- /dev/null +++ b/common/options/Makefile.am @@ -0,0 +1,50 @@ +# libguestfs +# Copyright (C) 2009-2017 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 $(top_srcdir)/subdir-rules.mk + +# liboptions.la contains guestfish code which is used in other +# C tools for options parsing and a few other things +noinst_LTLIBRARIES = liboptions.la + +liboptions_la_SOURCES = \ + config.c \ + decrypt.c \ + display-options.h \ + display-options.c \ + domain.c \ + inspect.c \ + keys.c \ + options.h \ + options.c \ + uri.h \ + uri.c +liboptions_la_CPPFLAGS = \ + -DGUESTFS_WARN_DEPRECATED=1 \ + -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ + -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib +liboptions_la_CFLAGS = \ + $(WARN_CFLAGS) $(WERROR_CFLAGS) \ + $(LIBCONFIG_CFLAGS) \ + $(LIBXML2_CFLAGS) +liboptions_la_LIBADD = \ + $(top_builddir)/common/utils/libutils.la \ + $(top_builddir)/lib/libguestfs.la \ + $(LIBCONFIG_LIBS) \ + $(LIBXML2_LIBS) \ + $(LTLIBINTL) diff --git a/fish/config.c b/common/options/config.c similarity index 100% rename from fish/config.c rename to common/options/config.c diff --git a/fish/decrypt.c b/common/options/decrypt.c similarity index 100% rename from fish/decrypt.c rename to common/options/decrypt.c diff --git a/fish/display-options.c b/common/options/display-options.c similarity index 100% rename from fish/display-options.c rename to common/options/display-options.c diff --git a/fish/display-options.h b/common/options/display-options.h similarity index 100% rename from fish/display-options.h rename to common/options/display-options.h diff --git a/fish/domain.c b/common/options/domain.c similarity index 100% rename from fish/domain.c rename to common/options/domain.c diff --git a/fish/inspect.c b/common/options/inspect.c similarity index 99% rename from fish/inspect.c rename to common/options/inspect.c index edfd2d47c..bb4ee87e7 100644 --- a/fish/inspect.c +++ b/common/options/inspect.c @@ -38,7 +38,6 @@ #include "guestfs.h" /* These definitions ensure we get all extern definitions from the header. */ -#define COMPILING_GUESTFISH 1 #include "options.h" /* Global that saves the root device between inspect_mount and diff --git a/fish/keys.c b/common/options/keys.c similarity index 100% rename from fish/keys.c rename to common/options/keys.c diff --git a/fish/options.c b/common/options/options.c similarity index 98% rename from fish/options.c rename to common/options/options.c index b88c194ec..a531e2e18 100644 --- a/fish/options.c +++ b/common/options/options.c @@ -198,8 +198,8 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive) next_drive += r; break; -#if COMPILING_GUESTFISH case drv_N: + if (!in_guestfish) abort (); /* -N option is not affected by --ro */ r = guestfs_add_drive_opts (g, drv->N.filename, GUESTFS_ADD_DRIVE_OPTS_FORMAT, "raw", @@ -210,10 +210,9 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive) drv->nr_drives = 1; next_drive++; break; -#endif -#if COMPILING_VIRT_RESCUE case drv_scratch: + if (!in_virt_rescue) abort (); r = guestfs_add_drive_scratch (g, drv->scratch.size, -1); if (r == -1) exit (EXIT_FAILURE); @@ -221,7 +220,6 @@ add_drives_handle (guestfs_h *g, struct drv *drv, char next_drive) drv->nr_drives = 1; next_drive++; break; -#endif default: /* keep GCC happy */ abort (); @@ -341,17 +339,15 @@ free_drives (struct drv *drv) case drv_d: /* d.filename is optarg, don't free it */ break; -#if COMPILING_GUESTFISH case drv_N: + if (!in_guestfish) abort (); free (drv->N.filename); drv->N.data_free (drv->N.data); break; -#endif -#if COMPILING_VIRT_RESCUE case drv_scratch: + if (!in_virt_rescue) abort (); /* nothing */ break; -#endif default: ; /* keep GCC happy */ } free (drv); diff --git a/fish/options.h b/common/options/options.h similarity index 98% rename from fish/options.h rename to common/options/options.h index a0863addc..1598daf48 100644 --- a/fish/options.h +++ b/common/options/options.h @@ -34,6 +34,8 @@ extern int inspector; extern int keys_from_stdin; extern int echo_keys; extern const char *libvirt_uri; +extern int in_guestfish; +extern int in_virt_rescue; /* List of drives added via -a, -d or -N options. NB: Unused fields * in this struct MUST be zeroed, ie. use calloc, not malloc. @@ -54,12 +56,8 @@ struct drv { drv_a, /* -a option (without URI) */ drv_uri, /* -a option (with URI) */ drv_d, /* -d option */ -#if COMPILING_GUESTFISH drv_N, /* -N option (guestfish only) */ -#endif -#if COMPILING_VIRT_RESCUE drv_scratch, /* --scratch option (virt-rescue only) */ -#endif } type; union { struct { @@ -80,18 +78,14 @@ struct drv { struct { char *guest; /* guest name */ } d; -#if COMPILING_GUESTFISH struct { char *filename; /* disk filename (testX.img) */ void *data; /* prepared type */ void (*data_free)(void*); /* function to free 'data' */ } N; -#endif -#if COMPILING_VIRT_RESCUE struct { int64_t size; /* size of the disk in bytes */ } scratch; -#endif }; /* Opaque pointer. Not used by the options-parsing code, and so @@ -121,10 +115,7 @@ extern int add_libvirt_drives (guestfs_h *g, const char *guest); extern void inspect_mount_handle (guestfs_h *g); extern void inspect_mount_root (guestfs_h *g, const char *root); #define inspect_mount() inspect_mount_handle (g) - -#if COMPILING_GUESTFISH extern void print_inspect_prompt (void); -#endif /* in key.c */ extern char *read_key (const char *param); diff --git a/fish/uri.c b/common/options/uri.c similarity index 100% rename from fish/uri.c rename to common/options/uri.c diff --git a/fish/uri.h b/common/options/uri.h similarity index 100% rename from fish/uri.h rename to common/options/uri.h diff --git a/configure.ac b/configure.ac index a85a802a9..dbf5ce56f 100644 --- a/configure.ac +++ b/configure.ac @@ -181,6 +181,7 @@ AC_CONFIG_FILES([Makefile builder/test-website/virt-builder/repos.d/libguestfs.conf cat/Makefile common/errnostring/Makefile + common/options/Makefile common/protocol/Makefile common/utils/Makefile common/visit/Makefile diff --git a/df/Makefile.am b/df/Makefile.am index d92137269..e2eef596c 100644 --- a/df/Makefile.am +++ b/df/Makefile.am @@ -43,6 +43,7 @@ virt_df_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -53,9 +54,9 @@ virt_df_CFLAGS = \ $(LIBVIRT_CFLAGS) virt_df_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/df/main.c b/df/main.c index b4fe0e076..29a1a1db3 100644 --- a/df/main.c +++ b/df/main.c @@ -55,6 +55,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 0; +int in_guestfish = 0; +int in_virt_rescue = 0; int csv = 0; /* --csv */ int human = 0; /* --human-readable|-h */ @@ -349,6 +351,10 @@ single_drive_display_name (struct drv *drvs) if (name == NULL) error (EXIT_FAILURE, errno, "strdup"); break; + + case drv_N: + case drv_scratch: + abort (); /* Only used in guestfish or virt-rescue. */ } if (!name) diff --git a/diff/Makefile.am b/diff/Makefile.am index 8c9be75aa..5e71b74de 100644 --- a/diff/Makefile.am +++ b/diff/Makefile.am @@ -33,6 +33,7 @@ virt_diff_CPPFLAGS = \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ -I$(top_srcdir)/common/visit -I$(top_builddir)/common/visit \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/cat -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -41,10 +42,10 @@ virt_diff_CFLAGS = \ $(LIBXML2_CFLAGS) virt_diff_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/visit/libvisit.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/diff/diff.c b/diff/diff.c index 724c7d7e3..fc31ad361 100644 --- a/diff/diff.c +++ b/diff/diff.c @@ -60,6 +60,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; static int atime = 0; static int csv = 0; diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES index d48209f47..5c9478c96 100644 --- a/docs/C_SOURCE_FILES +++ b/docs/C_SOURCE_FILES @@ -11,6 +11,17 @@ cat/filesystems.c cat/log.c cat/ls.c cat/tail.c +common/options/config.c +common/options/decrypt.c +common/options/display-options.c +common/options/display-options.h +common/options/domain.c +common/options/inspect.c +common/options/keys.c +common/options/options.c +common/options/options.h +common/options/uri.c +common/options/uri.h common/utils/cleanup.c common/utils/guestfs-internal-frontend-cleanups.h common/utils/guestfs-internal-frontend.h @@ -170,14 +181,9 @@ erlang/structs.c fish/alloc.c fish/cmds.c fish/completion.c -fish/config.c fish/copy.c -fish/decrypt.c fish/destpaths.c -fish/display-options.c -fish/display-options.h fish/display.c -fish/domain.c fish/echo.c fish/edit.c fish/entries-0.c @@ -197,13 +203,9 @@ fish/fish.h fish/glob.c fish/help.c fish/hexedit.c -fish/inspect.c -fish/keys.c fish/lcd.c fish/man.c fish/more.c -fish/options.c -fish/options.h fish/prep-boot.c fish/prep-disk.c fish/prep-fs.c @@ -228,8 +230,6 @@ fish/setenv.c fish/supported.c fish/tilde.c fish/time.c -fish/uri.c -fish/uri.h fish/windows.c fish/windows.h format/format.c diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod index 2df78ba77..1244cd668 100644 --- a/docs/guestfs-hacking.pod +++ b/docs/guestfs-hacking.pod @@ -89,6 +89,10 @@ The communication protocol used between the library and the daemon running inside the appliance has to encode errnos as strings, which is handled by this library. +=item F + +Common options parsing for guestfish, guestmount and some virt tools. + =item F The XDR-based communication protocol used between the library diff --git a/edit/Makefile.am b/edit/Makefile.am index 602bced7f..317937b4c 100644 --- a/edit/Makefile.am +++ b/edit/Makefile.am @@ -39,6 +39,7 @@ virt_edit_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -47,9 +48,9 @@ virt_edit_CFLAGS = \ $(LIBXML2_CFLAGS) virt_edit_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/edit/edit.c b/edit/edit.c index 1e1781d90..2f986a34c 100644 --- a/edit/edit.c +++ b/edit/edit.c @@ -52,6 +52,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; static const char *backup_extension = NULL; static const char *perl_expr = NULL; diff --git a/fish/Makefile.am b/fish/Makefile.am index b0e783cda..3a503985b 100644 --- a/fish/Makefile.am +++ b/fish/Makefile.am @@ -67,52 +67,8 @@ EXTRA_DIST = \ virt-tar-in.pod \ virt-tar-out.pod -# These source files (mostly related to option parsing) are shared -# between guestfish, guestmount and some other virt tools. Keep a -# convenient list here just so we know which ones are shared. These -# files must not include other guestfish files. -FISHCOMMON_SOURCE_FILES = \ - decrypt.c \ - display-options.h \ - display-options.c \ - domain.c \ - inspect.c \ - keys.c \ - options.h \ - options.c \ - uri.h \ - uri.c - -SHARED_SOURCE_FILES = \ - $(FISHCOMMON_SOURCE_FILES) \ - config.c \ - progress.h \ - progress.c - -# libfishcommon.la contains guestfish code which is used in other -# C tools. Note this convenience static library is *not* used in -# guestfish, as the sources are built with extra defines -# (e.g. -DCOMPILING_GUESTFISH) in that case. -libfishcommon_la_SOURCES = \ - $(FISHCOMMON_SOURCE_FILES) -libfishcommon_la_CPPFLAGS = \ - -DGUESTFS_WARN_DEPRECATED=1 \ - -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ - -I$(top_srcdir)/lib -I$(top_builddir)/lib \ - -I$(top_srcdir)/fish -I$(top_builddir)/fish \ - -I$(srcdir)/../gnulib/lib -I../gnulib/lib -libfishcommon_la_CFLAGS = \ - $(WARN_CFLAGS) $(WERROR_CFLAGS) \ - $(LIBXML2_CFLAGS) -libfishcommon_la_LIBADD = \ - $(top_builddir)/common/utils/libutils.la \ - $(top_builddir)/lib/libguestfs.la \ - $(LIBXML2_LIBS) \ - $(LTLIBINTL) - guestfish_SOURCES = \ $(generator_built) \ - $(SHARED_SOURCE_FILES) \ alloc.c \ cmds-gperf.h \ copy.c \ @@ -137,6 +93,8 @@ guestfish_SOURCES = \ prep-fs.c \ prep-lv.c \ prep-boot.c \ + progress.h \ + progress.c \ rc.c \ reopen.c \ setenv.c \ @@ -160,11 +118,11 @@ cmds-gperf.c: cmds-gperf.gperf mv $@-t $@ guestfish_CPPFLAGS = \ - -DCOMPILING_GUESTFISH=1 \ -DGUESTFS_WARN_DEPRECATED=1 \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish -I$(top_builddir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -177,6 +135,7 @@ guestfish_LDADD = \ $(LIBCONFIG_LIBS) \ $(LIBREADLINE) \ $(LIBTINFO_LIBS) \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ $(LIBXML2_LIBS) \ @@ -184,7 +143,7 @@ guestfish_LDADD = \ -lm # Make guestfish use the convenience libraries. -noinst_LTLIBRARIES = libcmds.la librc_protocol.la libfishcommon.la +noinst_LTLIBRARIES = libcmds.la librc_protocol.la guestfish_LDADD += libcmds.la librc_protocol.la ../gnulib/lib/libgnu.la if HAVE_RPCGEN diff --git a/fish/fish.c b/fish/fish.c index f9271cf7e..b7d63cf56 100644 --- a/fish/fish.c +++ b/fish/fish.c @@ -105,6 +105,8 @@ int progress_bars = 0; int is_interactive = 0; const char *input_file = NULL; int input_lineno = 0; +int in_guestfish = 1; +int in_virt_rescue = 0; static void __attribute__((noreturn)) usage (int status) diff --git a/format/Makefile.am b/format/Makefile.am index 85bdb6254..2d3cc774c 100644 --- a/format/Makefile.am +++ b/format/Makefile.am @@ -32,6 +32,7 @@ virt_format_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -41,9 +42,9 @@ virt_format_CFLAGS = \ $(LIBVIRT_CFLAGS) virt_format_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/format/format.c b/format/format.c index e70f32d3b..f23113bbe 100644 --- a/format/format.c +++ b/format/format.c @@ -47,6 +47,8 @@ int keys_from_stdin = 0; int echo_keys = 0; int inspector = 0; const char *libvirt_uri = NULL; +int in_guestfish = 0; +int in_virt_rescue = 0; static const char *filesystem = NULL; static const char *vg = NULL, *lv = NULL; diff --git a/fuse/Makefile.am b/fuse/Makefile.am index d2342153a..c3d4398a0 100644 --- a/fuse/Makefile.am +++ b/fuse/Makefile.am @@ -30,15 +30,9 @@ bin_PROGRAMS = \ guestmount \ guestunmount -# These source files (all related to option parsing) are shared -# between guestfish and guestmount. -SHARED_SOURCE_FILES = \ - ../fish/config.c - # guestmount guestmount_SOURCES = \ - $(SHARED_SOURCE_FILES) \ guestmount.c guestmount_CPPFLAGS = \ @@ -46,21 +40,21 @@ guestmount_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib guestmount_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ - $(LIBCONFIG_CFLAGS) \ $(LIBXML2_CFLAGS) \ $(FUSE_CFLAGS) guestmount_LDADD = \ $(FUSE_LIBS) \ - $(LIBCONFIG_LIBS) \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ + $(LIBCONFIG_LIBS) \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ @@ -69,14 +63,13 @@ guestmount_LDADD = \ # guestunmount guestunmount_SOURCES = \ - ../fish/display-options.c \ - ../fish/display-options.h \ guestunmount.c guestunmount_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -84,6 +77,7 @@ guestunmount_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) guestunmount_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ $(LIBXML2_LIBS) \ diff --git a/fuse/guestmount.c b/fuse/guestmount.c index 27bda06db..3839397ed 100644 --- a/fuse/guestmount.c +++ b/fuse/guestmount.c @@ -84,6 +84,8 @@ int inspector = 0; int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri; +int in_guestfish = 0; +int in_virt_rescue = 0; static void __attribute__((noreturn)) fuse_help (void) diff --git a/inspector/Makefile.am b/inspector/Makefile.am index 358a3f9d3..753e2c93c 100644 --- a/inspector/Makefile.am +++ b/inspector/Makefile.am @@ -60,6 +60,7 @@ virt_inspector_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -68,9 +69,9 @@ virt_inspector_CFLAGS = \ $(LIBXML2_CFLAGS) virt_inspector_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/inspector/inspector.c b/inspector/inspector.c index 8f9d04dc3..7a115c058 100644 --- a/inspector/inspector.c +++ b/inspector/inspector.c @@ -53,6 +53,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 1; +int in_guestfish = 0; +int in_virt_rescue = 0; static const char *xpath = NULL; static int inspect_apps = 1; static int inspect_icon = 1; diff --git a/make-fs/Makefile.am b/make-fs/Makefile.am index 8d8971a88..bef0e7bf8 100644 --- a/make-fs/Makefile.am +++ b/make-fs/Makefile.am @@ -32,6 +32,7 @@ virt_make_fs_CPPFLAGS = \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib @@ -40,9 +41,9 @@ virt_make_fs_CFLAGS = \ $(LIBXML2_CFLAGS) virt_make_fs_LDADD = \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ - $(top_builddir)/fish/libfishcommon.la \ $(LIBXML2_LIBS) \ $(LTLIBINTL) \ ../gnulib/lib/libgnu.la diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c index 7a3ecd3a9..4fbef2d4b 100644 --- a/make-fs/make-fs.c +++ b/make-fs/make-fs.c @@ -48,6 +48,8 @@ const char *libvirt_uri; int live; int read_only; int verbose; +int in_guestfish = 0; +int in_virt_rescue = 0; static const char *format = "raw", *label = NULL, *partition = NULL, *size_str = NULL, *type = "ext2"; diff --git a/mllib/Makefile.am b/mllib/Makefile.am index b9a6cf3fc..9cb244c8d 100644 --- a/mllib/Makefile.am +++ b/mllib/Makefile.am @@ -71,10 +71,10 @@ SOURCES_ML = \ SOURCES_C = \ ../common/visit/visit.c \ - ../fish/decrypt.c \ - ../fish/keys.c \ + ../common/options/decrypt.c \ + ../common/options/keys.c \ + ../common/options/uri.c \ ../fish/progress.c \ - ../fish/uri.c \ common_utils-c.c \ dev_t-c.c \ exit-c.c \ @@ -113,6 +113,7 @@ libmllib_a_CPPFLAGS = \ -I$(top_srcdir)/common/utils \ -I$(top_srcdir)/lib \ -I$(top_srcdir)/common/visit \ + -I$(top_srcdir)/common/options \ -I$(top_srcdir)/fish libmllib_a_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ diff --git a/po/POTFILES b/po/POTFILES index 2eddd759b..5796a6230 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -12,6 +12,14 @@ cat/ls.c cat/tail.c common/errnostring/errnostring-gperf.c common/errnostring/errnostring.c +common/options/config.c +common/options/decrypt.c +common/options/display-options.c +common/options/domain.c +common/options/inspect.c +common/options/keys.c +common/options/options.c +common/options/uri.c common/utils/cleanup.c common/utils/structs-cleanup.c common/utils/structs-print.c @@ -156,15 +164,12 @@ erlang/dispatch.c erlang/main.c erlang/structs.c fish/alloc.c +fish/cmds-gperf.c fish/cmds.c fish/completion.c -fish/config.c fish/copy.c -fish/decrypt.c fish/destpaths.c -fish/display-options.c fish/display.c -fish/domain.c fish/echo.c fish/edit.c fish/entries-0.c @@ -181,12 +186,9 @@ fish/fish.c fish/glob.c fish/help.c fish/hexedit.c -fish/inspect.c -fish/keys.c fish/lcd.c fish/man.c fish/more.c -fish/options.c fish/prep-boot.c fish/prep-disk.c fish/prep-fs.c @@ -208,7 +210,6 @@ fish/setenv.c fish/supported.c fish/tilde.c fish/time.c -fish/uri.c fish/windows.c format/format.c fuse/guestmount.c diff --git a/rescue/Makefile.am b/rescue/Makefile.am index 92ebc4af2..7919aafd5 100644 --- a/rescue/Makefile.am +++ b/rescue/Makefile.am @@ -25,41 +25,27 @@ EXTRA_DIST = \ bin_PROGRAMS = virt-rescue -SHARED_SOURCE_FILES = \ - ../fish/config.c \ - ../fish/decrypt.c \ - ../fish/display-options.h \ - ../fish/display-options.c \ - ../fish/domain.c \ - ../fish/inspect.c \ - ../fish/keys.c \ - ../fish/options.h \ - ../fish/options.c \ - ../fish/uri.h \ - ../fish/uri.c - virt_rescue_SOURCES = \ - $(SHARED_SOURCE_FILES) \ rescue.c virt_rescue_CPPFLAGS = \ - -DCOMPILING_VIRT_RESCUE=1 \ -DGUESTFS_WARN_DEPRECATED=1 \ -DLOCALEBASEDIR=\""$(datadir)/locale"\" \ -I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \ -I$(top_srcdir)/lib -I$(top_builddir)/lib \ + -I$(top_srcdir)/common/options -I$(top_builddir)/common/options \ -I$(top_srcdir)/fish \ -I$(srcdir)/../gnulib/lib -I../gnulib/lib virt_rescue_CFLAGS = \ $(WARN_CFLAGS) $(WERROR_CFLAGS) \ - $(LIBCONFIG_CFLAGS) \ $(LIBXML2_CFLAGS) virt_rescue_LDADD = \ - $(LIBCONFIG_LIBS) \ + $(top_builddir)/common/options/liboptions.la \ $(top_builddir)/common/utils/libutils.la \ $(top_builddir)/lib/libguestfs.la \ + $(LIBCONFIG_LIBS) \ $(LIBXML2_LIBS) \ $(LIBVIRT_LIBS) \ $(LTLIBINTL) \ diff --git a/rescue/rescue.c b/rescue/rescue.c index 673008594..ed40ba61b 100644 --- a/rescue/rescue.c +++ b/rescue/rescue.c @@ -51,6 +51,8 @@ int keys_from_stdin = 0; int echo_keys = 0; const char *libvirt_uri = NULL; int inspector = 0; +int in_guestfish = 0; +int in_virt_rescue = 1; static void __attribute__((noreturn)) usage (int status)