Commit Graph

68 Commits

Author SHA1 Message Date
Richard W.M. Jones
a1b3d8d04b tests: Extend $TEST_FUNCTIONS with predefined functions for skipping tests etc.
Apply this change across all the shell scripts containing tests.

Additionally this defines the environment variables $abs_srcdir,
$abs_builddir, $top_srcdir, $top_builddir, $abs_top_srcdir and
$abs_top_builddir which can now be used throughout test scripts.
2017-02-21 17:23:22 +00:00
Richard W.M. Jones
a9199a46b1 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.
2017-01-26 15:05:47 +00:00
Richard W.M. Jones
f161c9ea57 Rename src/ to lib/ 2017-01-26 15:05:46 +00:00
Richard W.M. Jones
b53cec584d lib: Move utilities to new directory common/utils.
Just code motion.

This commit makes it clearer what is a utility and what is part of the
library.  It also makes it clear that we should rename:

  guestfs-internal-frontend.h -> utils.h
  guestfs-internal-frontend-cleanups.h -> cleanups.h (?)

but this commit does not make that change.
2017-01-26 15:05:46 +00:00
Richard W.M. Jones
d6c42a6c58 valgrind: Don't use "nested" run scripts.
When TESTS_ENVIRONMENT already uses 'run', the VG variable
doesn't also need to use 'run'.

The specific problem is that if the command contains newlines
then double invocations of the 'run' script fails (in libtool).
ie the following command failed causing errors in check-valgrind:

  $VG virt-builder phony-fedora \
      -v --no-cache --no-check-signature $no_network \
  ...
      --write '/etc/append4:line1
  ' \
  ...
2016-10-11 18:08:49 +01:00
Pino Toscano
e3f681e1b8 tools: build common fish sources in a static library
Create a new libfishcommon convenience static library to build just once
(instead of 12 times!) the majority of the guestfish sources used in the
rest of the C tools (mostly for command line stuff, inspection, and
mount).

The notable exceptions not using libfishcommon are guestfish itself, and
virt-rescue: both need to build at least one of the common sources using
additional CPPFLAGS.
2016-09-26 14:16:44 +02:00
Pino Toscano
284c6e1078 build: remove extra libconfig linkage
Some of the C tools were building also config.c as part of the shared
sources from guestfish, and thus bringing a dependency on libconfig.
Since none of them actually read the libguestfs configuration at all,
then exclude fish/config.c from their build, and stop linking to
libconfig.
2016-09-26 11:13:17 +02:00
Pino Toscano
0920b805fd fish: move disk decryption helpers in own file
This way it is easier to use them outside the rest of the code in
guestfish for inspection & mount.

Just code motion, no behaviour changes.
2016-09-19 14:48:19 +02:00
Pino Toscano
eea210dbf7 Use the getprogname gnulib module
Make use of the recently added 'getprogname' module in gnulib: replace
our guestfs_int_program_name with the getprogname() provided by the
module, since it does the same thing, and in a portable way.
As consequence of the above, use gnulib in a couple of tests that use
getprogname().

Since guestfs_int_program_name is gone, drop the configure checks
associated with it.
2016-09-08 09:57:15 +02:00
Richard W.M. Jones
76c0a67d30 build: Add common CLEANFILES and DISTCLEANFILES to common-rules.mk.
By adding common CLEANFILES and DISTCLEANFILES variables to
common-rules.mk, we can remove these from most other Makefiles, and
also clean files more consistently.

Note that bin_PROGRAMS are already cleaned by 'make clean', so I
removed cases where these were unnecessarily added to CLEANFILES.
2016-08-25 16:54:34 +01:00
Richard W.M. Jones
c795d50af3 fish: Move display_*_options functions to a separate file.
By moving these two functions out of the common options parsing code,
it means we don't need to depend on all the other machinery of options
parsing, such as the global variables ("verbose"), libconfig, etc.
2016-08-25 12:52:42 +01:00
Pino Toscano
8e57268dd4 static const char *str -> static const char str[]
Make all the static constant strings as char arrays, so they can be
fully stored in read-only memory.
2016-07-22 13:16:02 +02:00
Richard W.M. Jones
08e27451a6 tests: Add script to check documented tool options match actual options.
podcheck.pl is run as part of the tests to perform various checks on
the documentation and the tool.

Currently we check only that the documented options matches the
options that the tool implements and vice versa.  This commit would
also allow us (in future) to check --help, --long-options,
--short-options, --version output.

This commit includes scripts to run the tests and various fixes to the
manual pages to ensure that the tests pass.
2016-07-19 13:06:14 +01:00
Richard W.M. Jones
8886f2951d fish, format, fuse: Remove bogus short options.
For guestfish, guestmount, remove '?' from short options.  Currently
those tools don't process -?, so I believe these are erroneous:

  $ guestfish -\?
  Try `guestfish --help' for more information.

For virt-format, the -c, -d and -q options are removed.  These options
just give errors because they appear in the short options list but not
in the case statement.
2016-07-19 12:32:09 +01:00
Pino Toscano
64bb9edd52 tests: specify the image format when possible
When possible, make the disk image format explicit when invoking tools
or using add-drive. This avoids warnings from qemu about the unspecified
format for the image, and also makes qemu slightly faster (skipping the
disk image probing).
Tests checking the image probing are not touched.

This changes also:
- old-style invocations of tools (`$tool $filename`) into new style
  (`$tool -a $filename`)
- add-drive-ro/add-drive-with-if guestfish commands into add/add-drive
  with explicit readonly/iface arguments

There should be no change in the tests results.
2016-05-19 19:06:00 +02:00
Pino Toscano
dc02e8985f tools: improve reporting for option errors (RHBZ#1316041)
Improve the error messages produced by C-based tools in case of issues
with the command line options:
- explicitly mention to use -a/-d (and -A/-D in virt-diff)
- when extra arguments are found, mention the correct way to pass
  options to certain command line switches (like --format)
- in virt-inspector, give a cleaner error message when neither -i nor
  any -m is specified

In all the cases, keep the extra notice to use 'TOOL --help' to get more
help with it.
2016-05-05 14:25:28 +02:00
Richard W.M. Jones
fdfedcb4ef Use 'error' function for fprintf followed by exit.
Like with the previous commit, this replaces instances of:

  if (something_bad) {
    fprintf (stderr, "%s: error message\n", guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

with:

  if (something_bad)
    error (EXIT_FAILURE, 0, "error message");

(except in a few cases were errno was incorrectly being ignored, in
which case I have fixed that).

It's slightly more complex than the previous commit because we must be
careful to:

 - Remove the program name (since error(3) prints it).

 - Remove any trailing \n character from the message.

Candidates for replacement were found using:

  pcregrep --buffer-size 10M -M '\bfprintf\b.*\n.*\bexit\b' `git ls-files`
2016-04-04 17:57:38 +01:00
Richard W.M. Jones
129e4938ba Use 'error' function consistently throughout.
Wherever we had code which did:

  if (something_bad) {
    perror (...);
    exit (EXIT_FAILURE);
  }

replace this with use of the error(3) function:

  if (something_bad)
    error (EXIT_FAILURE, errno, ...);

The error(3) function is supplied by glibc, or by gnulib on platforms
which don't have it, and is much more flexible than perror(3).  Since
we already use error(3), there seems to be no downside to mandating it
everywhere.

Note there is one nasty catch with error(3): error (EXIT_SUCCESS, ...)
does *not* exit!  This is also the reason why error(3) cannot be
marked as __attribute__((noreturn)).

Because the examples can't use gnulib, I did not change them.

To search for multiline patterns of the above form, pcregrep -M turns
out to be very useful:

  pcregrep --buffer-size 10M -M '\bperror\b.*\n.*\bexit\b' `git ls-files`
2016-04-04 13:14:26 +01:00
Richard W.M. Jones
446f7794e0 podwrapper: Add --warning flag for manual pages of CLI tools (RHBZ#1293527).
This doesn't add --warning flags to the translated pages,
which is a bug to be fixed at some point.
2016-01-11 13:42:49 +00:00
Richard W.M. Jones
a2edda266e build: Make 'make clean' remove more files.
Remove man pages and other pages which 'make clean' did not remove
before.

To evaluate which pages could be removed, I did a full build and
check, and then ran 'make clean' followed by 'git clean -xdf'.  By
examining the output of the git clean command I could see which files
were being missed.

Files that are _not_ removed by make clean or make distclean:

 - generator-built files

 - Makefile, Makefile.in, .deps, .depend

 - any ./configure output files (maybe they should be?)
2015-11-03 13:53:37 +00:00
Richard W.M. Jones
47b095b928 website: Put website into a separate directory.
Move the random set of HTML files we build from html/ into
the website/ directory.

Also in the website/ directory, put the index.html file from
http://libguestfs.org, which was previously not under version control.
It is generated from index.html.in so we can automatically add the
current version and release date.

Also in the website/ directory, put various CSS file, images, etc.
which are required by the website and were also previously not under
version control.

Change the 'make website' rule to 'make maintainer-upload-website'.
As the name suggests, it is only useful for the maintainer, and will
fail with an error for anyone else.
2015-10-31 17:09:29 +00:00
Richard W.M. Jones
677c721e85 Fix whitespace.
Because of previous automated commits, such as changing 'guestfs___'
-> 'guestfs_int_', several function calls no longer lined up with
their parameters, and some lines were too long.

The bulk of this commit was done using emacs batch mode and the
technique described here:

  http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html

The changes suggested by emacs were then reviewed by hand.
2015-10-05 14:28:33 +01:00
Richard W.M. Jones
d07b32e14f Change 'fprintf (stdout,...)' -> printf.
Result of earlier copy and paste.
2015-10-05 14:28:33 +01:00
Richard W.M. Jones
533901409e pod: Use F<> for filenames instead of C<>.
Done using a sequence of regular expressions like this:

  perl -pi.bak -e 's{C</}{F</}g' `git ls-files \*.pod` generator/actions.ml
  perl -pi.bak -e 's{C<C:\\}{F<C:\\}g' `git ls-files \*.pod` generator/actions.ml
  [etc]

and then tediously checking every change by hand.
2015-06-15 15:42:46 +01:00
Richard W.M. Jones
bfbcc01403 Change guestfs___* to guestfs_int_*
libguestfs has used double and triple underscores in identifiers.
These aren't valid for global names in C++.

The first step is to replace all guestfs___* (3 underscores) with
guestfs_int_*.  We've used guestfs_int_* elsewhere already as a prefix
for internal identifiers.

This is an entirely mechanical change done using:
  git ls-files | xargs perl -pi.bak -e 's/guestfs___/guestfs_int_/g'

Reference: http://stackoverflow.com/a/228797
2015-02-14 18:46:04 +00:00
Richard W.M. Jones
5cafedaa45 lib: Change 'program_name' macro to avoid conflict with gnulib.
The gnulib 'error' module uses 'program_name'.  On some platforms --
but not Linux / glibc -- it references it as:

  extern char *program_name;

This means when you compile libguestfs on non-glibc (eg. Mac OS X)
gnulib requires 'program_name' as an external string reference, which
we don't provide.

This change doesn't define this string reference for gnulib, but it
does change the name of the macro we use to avoid conflicts if we
eventually need to export 'program_name' as a string.

Thanks: Margaret Lewicka
2015-02-07 16:30:28 +00:00
Pino Toscano
d7abf5c8f2 format, make-fs: specify the label on mkfs
If specified, pass the label for the new filesystem directly to the
mkfs (or mkfs_btrfs) call.

This saves one set_label call, mostly.
2015-01-19 16:47:53 +01:00
Pino Toscano
b00adf3b78 tools: implement --short-options
Just like --long-options, it makes it possible to know which short
options are supported by each tool; this can help improving the bash
completion, for example.
2014-11-27 16:26:13 +01:00
Pino Toscano
a5426cce5f build: check for libintl, and use it
Look for libint/gettext and link to it; this properly detects whether
libint is part of libc.
2014-11-05 13:45:17 +01:00
Richard W.M. Jones
e85a976c5a tests: Don't use relative paths to binaries in tests.
All tests run under the ./run binary.  For a long time the ./run
binary has set the $PATH environment variable to contain all of the
directories with binaries in them.

Therefore there is no reason to use ../fish/guestfish instead of just
plain guestfish (and the same applies to other built binaries).
2014-09-17 17:31:50 +01:00
Richard W.M. Jones
b7bdb63d89 tools: Check for dangling --format parameters (RHBZ#1140894).
In most C tools, virt-sysprep and virt-customize, you have to put the
--format parameter before the corresponding -a parameter.  ie.  The
following is correct:

  guestfish --format qcow2 -a disk1 -a disk2

But the following is incorrect.  The --format parameter is dangling
and prior to this commit would have been silently ignored:

  guestfish -a disk1 -a disk2 --format qcow2

After this change, dangling --format parameters now lead to an error:

  guestfish: --format parameter must appear before -a parameter

In virt-customize, also check that --attach-format parameter appears
before --attach parameter.

Thanks: Lingfei Kong
2014-09-13 10:49:58 +01:00
Richard W.M. Jones
ffffe71c16 build: Remove code coverage and code profiling options.
This reverts commit 5a2e320ec9.
2014-04-09 14:51:59 +01:00
Richard W.M. Jones
c4dc70f8c4 podwrapper: Remove =encoding from input files and add it back in podwrapper.
This changes podwrapper so that the input (POD) files should not
contain an =encoding directive.  However they must be UTF-8.
Podwrapper then adds the '=encoding utf8' directive back during final
generation.

This in particular avoids problems with nested =encoding directives in
fragments.  These break POD, and are undesirable anyway.
2014-03-20 13:47:19 +00:00
Richard W.M. Jones
fb3afdff47 virt-format: Discard the data on the disks.
If possible, this means that the host will be able to reclaim most of
the space used by formatted disks.
2014-03-13 10:38:40 +00:00
Richard W.M. Jones
59fce974e2 pod: Remove stray +x (executable) mode on various POD files.
find -name '*.pod' -perm /0111 -exec chmod -x {} \;
2014-01-28 22:17:12 +00:00
Richard W.M. Jones
c46e41cb3c format: Add --label option for setting filesystem label.
$ ./run ./format/virt-format -a /tmp/test.img --filesystem=ext2 --label=BOOT
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ext2  BOOT   -    1.0G  -
/dev/sda1  partition   -     -      83   1.0G  /dev/sda
/dev/sda   device      -     -      -    1.0G  -

Thanks: Gerd Hoffmann (kraxel)
2013-08-29 11:38:06 +01:00
Richard W.M. Jones
d432ab2b5a format: Set MBR partition type byte appropriately (RHBZ#1000428).
Windows won't see a filesystem unless the MBR partition type
byte is set correctly.

$ ./run ./format/virt-format -a /tmp/test.img
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
Name       Type        VFS      Label  MBR  Size  Parent
/dev/sda1  filesystem  unknown  -      -    1.0G  -
/dev/sda1  partition   -        -      83   1.0G  /dev/sda
/dev/sda   device      -        -      -    1.0G  -

$ ./run ./format/virt-format -a /tmp/test.img --filesystem=ntfs
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  ntfs  -      -    1.0G  -
/dev/sda1  partition   -     -      07   1.0G  /dev/sda
/dev/sda   device      -     -      -    1.0G  -

$ ./run ./format/virt-format -a /tmp/test.img --filesystem=vfat
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
Name       Type        VFS   Label  MBR  Size  Parent
/dev/sda1  filesystem  vfat  -      -    1.0G  -
/dev/sda1  partition   -     -      0b   1.0G  /dev/sda
/dev/sda   device      -     -      -    1.0G  -

$ ./run ./format/virt-format -a /tmp/test.img --lvm --filesystem=vfat
$ ./run ./cat/virt-filesystems -a /tmp/test.img --all --long -h
Name        Type        VFS   Label  MBR  Size   Parent
/dev/VG/LV  filesystem  vfat  -      -    1020M  -
/dev/VG/LV  lv          -     -      -    1020M  /dev/VG
/dev/VG     vg          -     -      -    1020M  /dev/sda1
/dev/sda1   pv          -     -      -    1020M  -
/dev/sda1   partition   -     -      8e   1.0G   /dev/sda
/dev/sda    device      -     -      -    1.0G   -

Thanks: Gerd Hoffmann (kraxel)
2013-08-29 11:24:00 +01:00
Richard W.M. Jones
4d7c14fdbb fish: Split off URI handling (for -a argument) from general options parsing.
This is so we will be able to reuse the same code in the OCaml tools.

This is just code motion.
2013-07-30 15:37:16 +01:00
Richard W.M. Jones
4180abcc1f tests: Use unique or temporary names for temporary files.
Review every test(!) to ensure that it:

 - Doesn't use a generic name (eg. "test1.img", "test.out") for any
   temporary file it needs.

 - Does instead use a unique name or a temporary name (eg. a name like
   "name-of-the-test.img", or a scratch disk).

 - Does not use 'rm -f' to clean up its temporary files (so we can
   detect errors if the wrong temporary file is created or removed).

This allows tests to be run in parallel, so they don't stomp on each
other's temporary files.
2013-07-23 10:16:00 +01:00
Richard W.M. Jones
349300af08 fish: Add -a URI (add remote storage) to options.
Add a remote drive by doing:

 guestfish -a ssh://example.com/path/to/disk.img

There are several different protocols supported, as explained in the
man page.

This affects all virt-* tools that use the common guestfish options
parsing code.
2013-04-16 15:28:31 +01:00
Richard W.M. Jones
142b874ce8 Remove use of gnulib progname module.
It's simpler to use the glibc 'program_invocation_short_name(3)'
feature, and fall back to a generic solution.  Also remove risky
assignments to argv[0].
2013-04-11 14:42:54 +01:00
Richard W.M. Jones
1cb38ab924 New API: feature-available.
This API is an easier to use version of the existing guestfs_available,
because the new API returns true/false instead of throwing an error
when a feature from the list is not available.

In truth we've had this implementation internally in the library
and several tools and in Sys::Guestfs::Lib for a long time.  This
change just turns it into a publicly consumable API.
2013-04-02 12:38:50 +01:00
Richard W.M. Jones
6c9a7fe561 Add --long-options option to most tools.
For example:

$ guestfish --long-options
--add
--cmd-help
--connect
--csh
--domain
--echo-keys
[etc.]

The idea of this is to make it easier to write a bash completion
script that accurately expands --<TAB> options for each command.
2013-03-28 14:46:20 +00:00
Richard W.M. Jones
04723b4dd1 lib: Create libutils convenience library.
The libutils convenience library is a place for code shared between
the main library, language bindings and virt tools.  Note that the
code is statically linked into both the library, each binding and each
tool, but this is an improvement because (a) the source is shared and
(b) libguestfs.so can export fewer private functions.

Currently it contains the cleanup functions, and the functions
guestfs___free_string_list function and guestfs___for_each_disk.

guestfs___for_each_disk has changed so that it no longer
unconditionally sets the error in the guestfs handle.  Instead callers
can control error handling.
2013-02-20 19:15:05 +00:00
Richard W.M. Jones
09c4f94c9d build: Separate out *_CPPFLAGS from *_CFLAGS.
This is pretty pointless.
2013-02-11 21:36:27 +00:00
Richard W.M. Jones
4255db65e5 tools: Use CLEANUP_* macros in several C tools. 2013-02-09 20:37:03 +00:00
Richard W.M. Jones
42bffcd00a Remove all occurrences of the bad_cast (lowercase) function.
Not to be confused with the libxml2 macro 'BAD_CAST' which converts
from 'signed char *' to 'unsigned char *'.

The 'bad_cast' function was defined and used all over the place as a
replacement for a '(char *)' cast.  I think it is better to make these
casts explicit, instead of hiding them in an obscure function.
2013-02-01 14:16:51 +00:00
Richard W.M. Jones
5a2e320ec9 configure: Add --enable-code-profiling and --enable-code-coverage flags.
These configure flags enable code profiling (with gprof) and code
coverage (with gcov) respectively.

Although this is a nice idea, it's not currently very useful.

Libtool mangles filenames in such a way that gcov cannot locate its
datafiles.

Profiling is of dubious utility with libguestfs which is not CPU-bound
and relies extensively on running external programs (oprofile-like
system profiling that took into account libguestfs + qemu or
libguestfs + qemu + the appliance + filesystem tools *would* be
useful).

Also neither flag will help in capturing data from the appliance.
2012-12-04 14:11:14 +00:00
Richard W.M. Jones
3636c5fcff tests: Replace 'make extra-tests' with individual tests.
'make extra-tests' was a monolithic set of tests that did all sorts of
things: valgrind, tests over local guests, tests with upstream qemu,
tests with upstream libvirt, tests with the appliance attach method.

This made it hard to perform individual tests, eg. just valgrind
testing.  It was also hard to maintain because the tests were not
located in the same directories as the programs and sometimes
duplicated tests that were run elsewhere.

This commit splits up 'make extra-tests' into 5 separate targets:

 make check-valgrind              # run a subset of tests under valgrind
 make check-valgrind-local-guests # test under valgrind with local guests
 make check-with-appliance        # test with attach-method == appliance
 make check-with-upstream-qemu    # test with an alternate/upstream qemu
 make check-with-upstream-libvirt # test with an alternate/upstream libvirt

(You can also still run 'make extra-tests' which is now simply
a rule that runs the above 5 targets in order).

This replaces everything that was in the tests/extra directory,
so that has now gone.
2012-11-13 15:26:29 +00:00
Richard W.M. Jones
2d220f5da2 tools: Modify existing tools to use guestfs_{push,pop}_error_handler.
This is a shorter and more convenient way to disable errors
temporarily across calls.
2012-11-09 19:51:09 +00:00