Commit Graph

181 Commits

Author SHA1 Message Date
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
2af8d07af6 fuse: Implement --long-options and --short-options in guestunmount. 2016-08-25 13:51:33 +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
Richard W.M. Jones
d5a8f82887 Use 'const' for stack integers where possible.
May improve optimization possibilities in a few cases.
2016-07-26 10:43:45 +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
Richard W.M. Jones
35bac3a650 lib: Deprecate old SELinux APIs, rewrite SELinux documentation (RHBZ#1152825).
Also turns the --selinux option of guestfish, guestmount and
virt-rescue into a no-op -- it didn't work before so this is
effectively no change.
2016-07-14 15:28:10 +01:00
Pino Toscano
d5b3f558e0 tests: remove remaining relative paths to binaries
Tests are run via the ./run binary, so all the binaries in the build
directory are available via $PATH already.

Followup of commit e85a976c5a.
2016-05-19 19:06:00 +02: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
Pino Toscano
7e970fcdb3 build: check the path of fuser, and use it in FUSE code
Check for the full path of fuser, and use it instead of hardcoding
/sbin/fuser (which is still left as fallback).
2016-03-22 09:45:41 +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
307c83177c Update copyright dates for 2016.
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2015/$1-2016/g' `git ls-files`
2016-01-02 21:19:51 +00:00
Pino Toscano
51362c9638 fuse: fix return value of guestunmount for unmounted paths
Exit with 3 as return value when fusermount fails, because the specified
mount point is not considered mounted for the user.  This is in line
with what the guestunmount documentation says.

Adapt the test-guestunmount-fd test to the updated return value.

Thanks to: Maxim Perevedentsev.
2015-11-24 16:28:06 +01: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
dc1d0880b0 tests: Move the tests/data and tests/guests directories to test-data.
Create a new top-level directory called test-data, which will carry
all the test data which is large and/or shared between multiple tests.

There are actually several new subdirectories created:

test-data/binaries: The pre-built binary and library files for random
architectures that we use to test various architecture detection
features (was part of tests/data).

test-data/blank-disks: The blank disks which are used for disk format
detection (was part of tests/data).

test-data/files: Other miscellaneous test files from tests/data that
are not included in the above.

test-data/phony-guests: The phony guests (was tests/guests).

test-data: The top-level directory builds the 'test.iso' image file
that is used for testing the C API and in miscellaneous other tests.
2015-10-30 16:07:32 +00:00
Pino Toscano
4d3466af68 fuse: test-fuse: close files even on errors
Make sure to close the open files even when test_fuse() returns earlier
because of failures, otherwise the mountpoint is still in use by open
files when later guestunmount is called on it.
2015-10-08 13:34:03 +02: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
8b1b3a10b3 fuse: Use SKIP_TEST_FUSE_SH consistently.
This fixes commit 96a02f0864.
2015-06-06 14:08:24 +01:00
Richard W.M. Jones
5bf7f770b6 When calling getline first time, initialize length to zero.
The man page for getline says:

   ssize_t getline(char **lineptr, size_t *n, FILE *stream);
 [...]
   If  *lineptr  is set to NULL and *n is set 0 before the call, then get‐
   line() will allocate a buffer for storing the line.  This buffer should
   be freed by the user program even if getline() failed.

which seems to indicate that we must initialize both line and len to 0
before the first call to getline.

In several places we were not initializing len.  The program still
worked fine, but it seems better to initialize the length anyway.
2015-05-14 13:22:00 +01:00
Richard W.M. Jones
96a02f0864 fuse: Add more consistent SKIP_* environment variables.
The new behaviour is as follows:

Skip all of the fuse tests:

  SKIP_TEST_FUSE_SH=1

Individual tests can be skipped by setting:

  SKIP_TEST_FUSE_UMOUNT_RACE_SH=1
  SKIP_TEST_GUESTMOUNT_FD=1
  SKIP_TEST_GUESTUNMOUNT_FD=1
  SKIP_TEST_GUESTUNMOUNT_NOT_MOUNTED_SH=1
2015-05-12 11:48:44 +01:00
Richard W.M. Jones
b02980d5af fuse: tests: Add some debugging to test-fuse-umount-race.sh.
This test fails on recent kernels, sometimes.

Apparently calling 'fusermount -u mp' can exit with an EBUSY error,
but still unmount the filesystem.  Or possibly guestmount crashes
coincidentally.  It's impossible to debug because debugging tools like
strace prevent fuse from working at all.
2015-04-23 19:03:36 +01:00
Richard W.M. Jones
6dee5a4152 fuse: guestunmount: Make the -v (verbose) option do something useful.
guestunmount had a -v / --verbose option, but it didn't change the
behaviour of the program in any way.

Make it print the invocations of the underlying fusermount program.
2015-04-23 19:02:41 +01:00
Richard W.M. Jones
403e32df23 fuse: Add a note about preserving inode numbers using -o use_ino.
Thanks: David Juran
2015-03-27 11:01:00 +00: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
Margaret Lewicka
5f67d23cf5 fuse: Alternatives for Linux-specific commands
* fusermount is Linux-only; on BSD and OS X umount should be used
* fuser has no -v flag on BSD/OSX, and -c is the
  POSIX-compatible equivalent of -m
* Does not solve the lack of pretty output of fuser -v, but does make it
  work on Mac OS X.
2015-02-14 09:39:49 +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
Richard W.M. Jones
145db4f629 test: fuse: Add debugging of commands run in the test. 2015-01-22 10:44:32 +00:00
Pino Toscano
0eedddad2f fuse: test-fuse: free "acl_text"
Make sure to free the buffer returned by acl_to_any_text.
2015-01-20 16:09:53 +01:00
Richard W.M. Jones
c5800dc97d Update copyright dates for 2015. 2015-01-17 09:08:15 +00:00
Richard W.M. Jones
5f6677ebd0 environment: Use guestfs___is_true when parsing various boolean environment variables (RHBZ#1175196).
You can now use LIBGUESTFS_DEBUG=true (etc.)

You can disable debugging/tracing by setting LIBGUESTFS_DEBUG=0 (etc.)
2014-12-17 14:38:44 +00: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
Pino Toscano
471ed473cf fuse: test-fuse: enclose acl vars within HAVE_ACL
Enclose the acl-related variables within a #ifdef HAVE_ACL block, so
when building without acl support and -Werror it can build.
2014-10-23 19:03:12 +02:00
Pino Toscano
ad300fcd5e fuse: test-fuse: use acl_to_any_text
Switch from acl_to_text to acl_to_any_text, so it is possible to specify
options, like forcing the numeric IDs for users/groups. This ensure the
resulting string has always numberic IDs, so the comparison can always
succeed.

Adapt the comparison string to the lack of final endline now.
2014-09-26 14:32:32 +02:00
Richard W.M. Jones
1b12c6d46b fuse: Remove test-fuse.sh (rewritten script) from EXTRA_DIST.
This fixes commit aca076e2e2.
2014-09-22 18:25:26 +01:00
Richard W.M. Jones
58eaf258c1 fuse: Enable futimens test (RHBZ#1144766). 2014-09-22 15:47:48 +01:00
Richard W.M. Jones
8664337cc3 New APIs: Implement stat calls that return nanosecond timestamps (RHBZ#1144891).
The existing APIs guestfs_stat, guestfs_lstat and guestfs_lstatlist
return a stat structure that contains atime, mtime and ctime fields
that store only the timestamp in seconds.

Modern filesystems can store timestamps down to nanosecond
granularity, and the ordinary glibc stat(2) wrapper will return these
in "hidden" stat fields:

  struct timespec st_atim;            /* Time of last access.  */
  struct timespec st_mtim;            /* Time of last modification.  */
  struct timespec st_ctim;            /* Time of last status change.  */

with the following macros defined for backwards compatibility:

  #define st_atime st_atim.tv_sec
  #define st_mtime st_mtim.tv_sec
  #define st_ctime st_ctim.tv_sec

It is not possible to redefine guestfs_stat to return a longer struct
guestfs_stat with room for the extra nanosecond fields, because that
would break the ABI of guestfs_lstatlist as it returns an array
containing consecutive stat structs (not pointers).  Changing the
return type of guestfs_stat would break API.  Changing the generator
to support symbol versioning is judged to be too intrusive.

Therefore this adds a new struct (guestfs_statns) and new APIs:

  guestfs_statns
  guestfs_lstatns
  guestfs_lstatnslist

which return the new struct (or array of structs in the last case).

The old APIs may of course still be used, forever, but are deprecated
and shouldn't be used in new programs.

Because virt tools are compiled with -DGUESTFS_WARN_DEPRECATED=1, I
have updated all the places calling the deprecated functions.  This
has revealed some areas for improvement: in particular virt-diff and
virt-ls could be changed to print the nanosecond fields.

FUSE now returns nanoseconds in stat calls where available, fixing
https://bugzilla.redhat.com/show_bug.cgi?id=1144891

Notes about the implementation:

- guestfs_internal_lstatlist has been removed and replaced by
  guestfs_internal_lstatnslist.  As the former was an internal API no
  one should have been calling it, or indeed can call it unless they
  start defining their own header files.

- guestfs_stat and guestfs_lstat have been changed into library-side
  functions.  They, along with guestfs_lstatlist, are now implemented
  as wrappers around the new functions which just throw away the
  nanosecond fields.
2014-09-22 15:47:48 +01:00
Richard W.M. Jones
aca076e2e2 fuse: Rewrite test-fuse.sh in C.
This gives us finer control over how system calls are done,
and also potentially lets us test more.

Currently two tests are disabled:

 - utimens because of https://bugzilla.redhat.com/show_bug.cgi?id=1144766

 - utimes because our stat call does not return the nanosecond fields
2014-09-21 22:15:37 +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
1fbf0a88f6 fuse: Make all the skip messages consistent in this test. 2014-05-25 22:34:51 +01:00