Commit Graph

667 Commits

Author SHA1 Message Date
Richard W.M. Jones
e6c89f9631 utils: Rename ‘guestfs-internal-frontend.h’ to ‘guestfs-utils.h’.
The reason it's not just ‘utils.h’ is because Pino is worried that we
might pick up /usr/include/utils.h from a rogue library.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
5efebd8c7e utils: Split out structs cleanups and printing into common/structs.
These won't be used by the daemon, so interferes with us using
common/utils in the daemon, so they are moved to a different library.
2017-07-10 17:01:59 +01:00
Richard W.M. Jones
8c9a4bc84f common/options: Change drv struct to store drive index instead of device name.
The device name is only used by guestfish (when using the -N option to
prepare drives).  We constructed the device name very naively,
basically ‘sprintf ("/dev/sd%c", next_drive)’.

This stores the device index instead, and only constructs the device
name in guestfish.  Also the device name is constructed properly using
guestfs_int_drive_name so it can cope with #drives > 26.

As a side effect of this change we can remove the extra parameter of
the add_drives macro.

Thanks: Pino Toscano
2017-05-03 19:32:37 +01:00
Richard W.M. Jones
ee206d7ba8 Use Unicode single quotes ‘’ in place of short single quoted strings throughout.
Only in end-user messages and documentation.  This change was done
mostly mechanically using the Perl script attached below.

I also changed don't -> don’t etc and made some other simple fixes.

See also: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html

----------
 #!/usr/bin/perl -w

use strict;
use Locale::PO;

my $re = qr{'([-\w%.,=?*/]+)'};

my %files = ();

foreach my $filename ("po/libguestfs.pot", "po-docs/libguestfs-docs.pot") {
    my $poref = Locale::PO->load_file_asarray($filename);

    foreach my $po (@$poref) {
        if ($po->msgid =~ $re) {
            my @refs = split /\s+/, $po->reference;
            foreach my $ref (@refs) {
                my ($file, $lineno) = split /:/, $ref, 2;
                $file =~ s{^\.\./}{};
                if (exists $files{$file}) {
                    push @{$files{$file}}, $lineno;
                } else {
                    $files{$file} = [$lineno];
                }
            }
        }
    }
}

foreach my $file (sort keys %files) {
    unless (-w $file) {
        warn "warning: $file is probably generated\n"; # have to edit generator
        next;
    }
    my @lines = sort { $a <=> $b } @{$files{$file}};

    #print "editing $file at lines ", join (", ", @lines), " ...\n";
    open FILE, "<$file" or die "$file: $!";
    my @all = ();
    push @all, $_ while <FILE>;
    close FILE;

    my $ext = $file;
    $ext =~ s/^.*\.//;

    foreach (@lines) {
        # Don't mess with verbatim sections in POD files.
        next if $ext eq "pod" && $all[$_-1] =~ m/^ /;

        unless ($all[$_-1] =~ $re) {
            # this can happen for multi-line strings, have to edit it
            # by hand
            warn "warning: $file:$_ does not contain expected content\n";
            next;
        }
        $all[$_-1] =~ s/$re/‘$1’/g;
    }

    rename "$file", "$file.bak";
    open FILE, ">$file" or die "$file: $!";
    print FILE $_ for @all;
    close FILE;
    my $mode = (stat ("$file.bak"))[2];
    chmod ($mode & 0777, "$file");
}
2017-04-04 18:47:37 +01:00
Richard W.M. Jones
126ef5d082 Use Unicode single quotes ‘’ in place of `' in strings throughout.
See: https://www.cl.cam.ac.uk/~mgk25/ucs/quotes.html
2017-03-31 10:38:04 +01:00
Richard W.M. Jones
4bbb1f7490 lib: Prefer tirpc for XDR, and rationalise how we search for alternatives.
glibc in Fedora is currently configured with `--enable-obsolete-rpc',
so I guess we can see which way the wind is blowing.

(1) This changes our configure script to prefer libtirpc if it is
available.

If libtirpc is _not_ available then:

(a) Headers must be located in <rpc/xdr.h>, or the user must supply
the right CFLAGS.

(b) XDR functions must be located in one of -lportablexdr, -lrpc,
-lxdr, -lnsl or no library at all (ie. -lc), and the user must set
LDFLAGS if needed.

(2) We no longer add these paths automatically to $(CFLAGS)/$(LIBS).
Any part of libguestfs which needs <rpc/*.h> or the xdr_* functions
must use $(RPC_CFLAGS)/$(RPC_LIBS) explicitly.

(3) Previously Mac OS X had a workaround for the broken 64 bit support
in the supplied rpcgen.  This workaround "activates" all the time if
you use tirpc, so breaking Linux after the above changes.  tirpc is
supported on OS X, so I think it's just better to use that rather than
the broken rpcgen.  For that reason I removed the workaround
completely.

Thanks: Roy Keene
2017-03-07 12:54:17 +00:00
Pino Toscano
be82ba38df fish: fully init the msghdr buffers
This way no fields (msg_flags in particular) remain uninitialized.
2017-03-03 16:36:27 +01:00
Richard W.M. Jones
45e046dac9 tests: Disable some tests so they don't break when ./configure --without-libvirt 2017-02-23 13:59:38 +00:00
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
1230543f71 fish: Link to libtinfo (RHBZ#1417549).
Fixes commit a8c5739fd2.

Reported by: Jean-Christophe Manciot
2017-02-14 13:18:57 +01:00
Richard W.M. Jones
48d4117789 fish: Handle changed type of 'len' parameter in gperf 3.1 (RHBZ#1416941).
Commit 004de6cf45 was not sufficient to
solve this problem.  We are also using gperf in guestfish.  Rewrite
the code in the same way to avoid having to prototype the hash
function.
2017-01-28 13:23:40 +00:00
Richard W.M. Jones
5d607f752b common/edit: Don't use random() function.
Generate the random filename using our utility function
guestfs_int_random_string.  This also means that we will not need to
call srandom() in guestfish or virt-edit.
2017-01-27 09:42:01 +00:00
Richard W.M. Jones
a8c5739fd2 fish: Move edit, progress, windows under common/
Three more pieces of common code are moved under the common/
subdirectory.  This is just code motion.

Note that windows.[ch] wasn't even being used by guestfish.  That code
was only used in other virt tools.
2017-01-26 15:05:47 +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
Pino Toscano
55bf7de97c Update copyright dates for 2017
Run the following command over the source:

  perl -pi.bak -e 's/(20[01][0-9])-2016/$1-2017/g' `git ls-files`

(Thanks Rich for the perl snippet, as used in past years.)
2017-01-03 16:48:21 +01:00
Richard W.M. Jones
bad1059bc4 fish: Fix small typos in virt-copy-in and virt-copy-out man pages (RHBZ#1398070).
Thanks: Xianghua Chen
2016-11-24 09:53:10 +00:00
Richard W.M. Jones
4d535c7038 docs: internal: Allow headers and structs to be documented.
This makes a number of small changes to how the internal documentation
is generated and what can be documented.

Header files are now permitted to contain internal documentation.
This works in the same wasy as .c files.

Also documentation can be added for structs as well as functions.

This commit also adds documentation to some header files and structs,
and fixes a few places which contained broken header documentation.
2016-10-25 13:38:01 +01:00
Richard W.M. Jones
8b076d87a1 New tool: virt-tail.
This follows (tails) a log file within a guest, rather like
the regular 'tail -f' command.  For example:

  virt-tail -d guest /var/log/messages
2016-10-12 13:49:46 +01: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
23ca442f63 fish, inspector: get rid of COMPILING_VIRT_INSPECTOR
All the define was doing in options.h was masking the declaration of
inspect_mount_root, which was always built-in in inspect.c (because of
the unconditional #define there) anyway.

Since this is common code used by all the C tools, try to avoid extra
knobs which add different code paths for no benefit.
2016-09-26 11:45:07 +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
a749b5d93a fish: Split up the very large fish/cmds.c file.
Make parallel compiles faster in this directory (about 8s down to 3s).
2016-09-02 23:14:08 +01: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
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
Richard W.M. Jones
a8e15ea924 daemon: Ignore -Wnull-dereference & -Wshift-overflow warnings.
One -Wnull-dereference warning is real: we deliberately cause a
segfault in one of the tests.

There is a -Wshift-overflow bug in a Gtk 2 header.

The others are the result of shortcomings in GCC.

In all cases we have to add GCC diagnostic overrides to ignore
the warnings when compiling with ./configure --enable-werror.
2016-07-24 10:55:52 +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
5e65da07fa podcheck: Check tool --help output.
For OCaml tools this does essentially nothing useful because the
--help output is automatically generated from the options, and so
cannot be wrong.  However for C tools this is a useful check.

It would be nice to generate C tools --help output, but there isn't
enough information in the getopt data to do that.

This commit also includes fixes to the --help output for a few tools.
2016-07-21 12:45:15 +01: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
Richard W.M. Jones
69e5410e62 fish: rc: Rewrite file descriptor send/receive.
On Linux 4.7.0 the old code was giving -EINVAL errors.  This rewrites
the code based on online sources, and it works on at least RHEL 7,
Linux 4.4 and 4.7.  Also checked with valgrind.
2016-06-03 21:47:04 +01:00
Richard W.M. Jones
8417eb4587 fish: rc: Fail hard if recvmsg doesn't receive a file descriptor.
Also some code reformatting.
2016-06-03 21:03:03 +01:00
Pino Toscano
1c9e808eee fish: generate test-prep.sh with generator
Generate test-prep.sh using the generator, so the prepared disk types
tested are the same as the ones configured in prepopts.ml.
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
Richard W.M. Jones
ea71e00d1a fish: Add internal documentation to several files. 2016-05-08 20:59:36 +01:00
Richard W.M. Jones
01f98a2500 docs: Convert more ordinary comments to internal documentation comments. 2016-04-13 13:47:50 +01:00
Richard W.M. Jones
24e5b591e4 docs: Add internal documentation for a few guestfish functions. 2016-04-12 21:10:53 +01: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
180b853658 fish: Link with LIBTINFO_LIBS.
Required on Gentoo.

Thanks: Mark Pictor
2016-03-16 15:16:39 +00:00
Cédric Bosdonnat
1c30c23a19 fish: fix btrfs subvolumes display in error case
The list of filesystems that is printed when there was an error prints
the internal mountable string even for the btrfs subvolumes. Let's
printing a valid -m option value instead.
2016-03-08 16:25:19 +01:00
Richard W.M. Jones
07c496c53c Use less stack.
GCC has two warnings related to large stack frames.  We were already
using the -Wframe-larger-than warning, but this reduces the threshold
from 10000 to 5000 bytes.

However that warning only covers the static part of frames (not
alloca).  So this change also enables -Wstack-usage=10000 which covers
both the static and dynamic usage (alloca and variable length arrays).

Multiple changes are made throughout the code to reduce frames to fit
within these new limits.

Note that stack allocation of large strings can be a security issue.
For example, we had code like:

 size_t len = strlen (fs->windows_systemroot) + 64;
 char software[len];
 snprintf (software, len, "%s/system32/config/software",
           fs->windows_systemroot);

where fs->windows_systemroot is guest controlled.  It's not clear what
the effects might be of allowing the guest to allocate potentially
very large stack frames, but at best it allows the guest to cause
libguestfs to segfault.  It turns out we are very lucky that
fs->windows_systemroot cannot be set arbitrarily large (see checks in
is_systemroot).

This commit changes those to large heap allocations instead.
2016-03-07 17:36:24 +00:00
Richard W.M. Jones
fadce8d3e7 fish: Set program name correctly for virt-{copy,tar}-{in,out} programs.
Set the (libguestfs handle) program name correctly when running
programs like virt-copy-in, so the program name is not "guestfish" but
"virt-copy-in".

Note this feature cannot be tested using the ./run script, since
libtool (buggily) resets the program name to "lt-guestfish".  However
I tested it on the installed copy and it worked there.
2016-02-26 10:45:21 +00:00
Pino Toscano
9753986819 fish, sysprep: run FUSE-related tests only when FUSE is available
They will fail anyway in that case, so run them only when the FUSE
support is built in.
2016-02-11 18:40:04 +01:00
Pino Toscano
55202a4d49 New API: get-sockdir
Introduce a new read-only API to get a path where to store temporary
sockets: this is different from tmpdir, as we need short paths for
sockets (due to sockaddr_un::sun_path), and it is either
XDG_RUNTIME_DIR if set, or /tmp; adapt guestfs_int_create_socketname
to create sockets in that location.

Furthermore, print sockdir and XDG_RUNTIME_DIR in test-tool for
debugging.
2016-02-03 13:15:29 +01:00