80 Commits

Author SHA1 Message Date
Ken Stailey
fcacda8374 fish: In interactive mode, improve error message for help of unknown command (RHBZ#1497475) 2017-09-30 22:17:05 +01:00
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
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
0b7acf50b6 fish: Use guestfs___{free_string_list,count_strings} utility functions.
Instead of custom-coded versions.
2013-02-20 19:32:11 +00:00
Richard W.M. Jones
2a8de9001e fish: Use guestfs_event_to_string instead of guestfish-specific generated functions. 2013-02-19 13:41:57 +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
ec3b75e5ff Rearrange internal header files.
This commit rearranges the internal header files.

"src/guestfs-internal.h" is just for the library, as before.

"src/guestfs-internal-frontend.h" is for use by all library, bindings,
tools C code, but NOT the daemon.

"src/guestfs-internal-all.h" is for use by all C code including the
daemon.

This is just code motion, but it has some important consequences:

(1) We can use the CLEANUP_* macros in bindings and tools code.

(2) We can get rid of TMP_TEMPLATE_ON_STACK.

(3) We will (in future) be able to stop bindings and tools code from
using the safe_* allocation functions (which are NOT safe to use
outside the library alone).
2013-02-01 14:07:25 +00:00
Richard W.M. Jones
1efed122c0 lib: Rework temporary and cache directory code.
New APIs: set-tmpdir, get-tmpdir, set-cachedir, get-cachedir.

The current code has evolved over time and has a number of problems:

(a) A single environment variable ($TMPDIR) controls the
location of several directories.

(b) It's hard for the library user to predict which directory
libguestfs will use, unless the user simulates the same internal steps
that libguestfs performs.

This commit fixes these issues.

(a) Now three environment variables control the location of all small
temporary files, and the appliance cache:

  For temporary files: $LIBGUESTFS_TMPDIR or $TMPDIR or /tmp.

  For the appliance cache: $LIBGUESTFS_CACHEDIR or $TMPDIR or /var/tmp.

The user can also set these directories explicitly through API calls
(guestfs_set_tmpdir and guestfs_set_cachedir).

(b) The user can also retrieve the actual directories that libguestfs
will use, by calling guestfs_get_tmpdir and guestfs_get_cachedir.
These functions are also used internally.

This commit also:

 - reworks the internal tmpdir code

 - removes the internal (undocumented) guestfs_tmpdir call (replacing
   it with calls to the documented guestfs_get_tmpdir API instead)

 - changes the ./run script to set LIBGUESTFS_TMPDIR and
   LIBGUESTFS_CACHEDIR

 - adds a test

 - fixes a few places like libguestfs-make-fixed-appliance which
   depended on $TMPDIR
2012-11-09 13:11:53 +00:00
Richard W.M. Jones
cb13ffe190 syntax: Remove definitions of O_CLOEXEC, except in examples (thanks Jim Meyering).
The gnulib <fcntl.h> replacement header will now define this symbol if
it's not defined already.
2012-09-17 10:07:31 +01:00
Richard W.M. Jones
79bf966cea fish: Move 'feature_available' function to global.
This is just code motion.
2012-05-02 15:34:02 +01:00
Richard W.M. Jones
6aa95e87c1 Remove "convenience header" "gettext.h" and use <libintl.h> instead.
gettextize provides a local file called "gettext.h".  Remove this and
use <libintl.h> from glibc headers instead.

Most of this change is mechanical: #include <libintl.h> in every C
file which uses any gettext function.  But also we remove the
gettext.h file, and adjust the "_" macros.

Note that this effectively removes the ./configure --disable-nls
option, although we don't know if that ever worked.
2012-05-01 08:57:55 +01:00
Richard W.M. Jones
606732d02e Use O_CLOEXEC / SOCK_CLOEXEC for almost all file descriptors.
The presumption is that all file descriptors should be created with
the close-on-exec flag set.  The only exception are file descriptors
that we want passed through to exec'd subprocesses (mainly pipes and
stdin/stdout/stderr).

For open calls, we pass O_CLOEXEC as an extra flag, eg:

  fd = open ("foo", O_RDONLY|O_CLOEXEC);

This is a Linux-ism, but using a macro we can easily make it portable.

For sockets, similarly:

  sock = socket (..., SOCK_STREAM|SOCK_CLOEXEC, ...);

For accepted sockets, we use the Linux accept4 system call which
allows flags to be supplied, but we use the Gnulib 'accept4' module to
make this portable.

For dup, dup2, we use the Linux dup3 system call, and the Gnulib
modules 'dup3' and 'cloexec'.
2012-03-14 19:30:46 +00:00
Richard W.M. Jones
f76a88011a Replace 'int' with 'size_t' passim.
Analyze all uses of 'int' in the code, and replace with 'size_t' where
appropriate.
2012-03-13 08:23:56 +00:00
Richard W.M. Jones
f7c744bbf8 fish: remote: Make sure global cleanups are called for guestfish --listen.
Return to the main program ('fish.c') and perform global cleanups when
the guestfish remote server exits.
2012-03-12 15:13:29 +00:00
Richard W.M. Jones
7123f0cab1 fish: Allow events to be processed in guestfish.
Add 'event', 'list-events' and 'delete-event' commands so that event
handlers can be registered, listed and deleted in guestfish.  The
event handler is a shell script snippet or host command.

Cc: Pádraig Brady <P@draigBrady.com>
2011-12-16 19:52:08 +00:00
Richard W.M. Jones
6146412f06 fish: Make progress bars into a mini library.
This library could now be called from other virt tools.
2011-08-26 21:54:59 +01:00
Richard W.M. Jones
3064277680 fish: Declare run_* functions in a generated header file.
Calls to these functions are generated, so there is no need to declare
the functions by hand.
2011-08-07 21:04:00 +01:00
Richard W.M. Jones
319e946b92 fish: Print input file and line number in error messages.
eg:
*stdin*:37: libguestfs: error: luks_close: Device lukstest is busy.
2011-08-05 15:08:44 +01:00
Richard W.M. Jones
dfb89e3556 fish: Add 'display' command for displaying graphical files. 2011-06-28 18:58:54 +01:00
Richard W.M. Jones
b8be128caa fish: Enhance guestfish win:... parsing to understand drive letters. 2011-04-05 20:01:59 +01:00
Richard W.M. Jones
4e0cf4dbf8 New event API (RHBZ#664558).
This API allows more than one callback to be registered for each
event, makes it possible to call the API from other languages, and
allows [nearly all] log, debug and trace messages to be rerouted from
stderr.

An older version of this API was discussed on the mailing list here:
https://www.redhat.com/archives/libguestfs/2010-December/msg00081.html
https://www.redhat.com/archives/libguestfs/2011-January/msg00012.html

This also updates guestfish to use the new API for its progress bars.
2011-03-15 12:16:50 +00:00
Richard W.M. Jones
4bcb267a24 fish: Make exit_on_error into a completely local variable.
Note that 'time' and 'glob' (which both run subcommands) do not
correctly pass the exit_on_error flag in the remote case.  This is not
a regression: the current code doesn't work either.
2011-01-18 10:33:01 +00:00
Richard W.M. Jones
272b754093 fish: Don't use external pod2text program.
This removes the dependency from guestfish to the external
pod2text program (and hence the final dependency on perl for
guestfish).  This is done by storing the formatted pod2text
output in guestfish as the help text.
2010-11-26 21:51:11 +00:00
Richard W.M. Jones
371e83c090 fish: Add --listen --csh to for csh, tcsh compatibility.
(Thanks Eric Blake).
2010-11-05 15:39:27 +00:00
Richard W.M. Jones
a232e62dcf fish: '-i' option automatically handles whole-disk encryption.
This feature is also available in guestmount because of the
shared option parsing code.

You don't need to do anything to enable it, just using -i
will attempt decryption of encrypted partitions.

Only works for simple Fedora whole-disk encryption.  It's a
work-in-progress to make it work for other types of encryption.
2010-11-05 11:39:24 +00:00
Richard W.M. Jones
74f7c9e4b7 fish: Make the 'help' command more helpful. 2010-11-04 17:04:03 +00:00
Richard W.M. Jones
c66d6f215e Unify guestfish and guestmount options processing (RHBZ#642932).
In guestfish, factor out the processing of the options -a, -c,
-d, -i, -m, -n, -r, -v, -V, -x into a separate set of files:
options.c, options.h, inspect.c, virt.c.

Change guestmount so that it uses these same files (from the
../fish directory) to process the same options.

This unifies the handling of these options between the two programs.
It also adds the useful inspection feature to guestmount, so you
can now do:

  guestmount -d Guest -i --ro mnt/
2010-10-27 12:04:16 +01:00
Richard W.M. Jones
6391d1a7cf fish: Change 'int argc' to 'size_t argc' throughout. 2010-10-21 10:50:25 +01:00
Richard W.M. Jones
c9c0ac7d36 Allow $TMPDIR to override most temporary directory uses.
Be more consistent in allowing the user to override use of the
temporary directory by specifying $TMPDIR.  Also prefer P_tmpdir
macro (defined in <stdio.h>) if that is defined, rather than
hard-coding "/tmp" for the fallback location.
2010-09-24 19:25:06 +01:00
Richard W.M. Jones
d75a2bff12 fish: Implement 'hexedit' command. 2010-09-21 19:51:22 +01:00
Richard W.M. Jones
8ea62c8d7f leak: Free list of drives and mountpoints in guestfish.
Previously the list of -a, -d, -m, -N parameters were leaked.  This
change frees them explicitly.

This is not such an important fix since guestfish is a one-shot
program, but it aids in finding other leaks in future.

(Found by valgrind).
2010-09-21 19:51:22 +01:00
Richard W.M. Jones
0003ea2c3d generator: Generate guestfish-only commands.
The guestfish-only commands such as 'alloc' and 'edit' are
now generated from one place in the generator instead of being
spread around ad-hoc in the C code.
2010-09-18 09:38:05 +01:00
Richard Jones
2635a9c70e fish: Implement copy-in and copy-out commands. 2010-09-09 23:12:19 +01:00
Richard Jones
d5c8d3b45b fish: Add guestfish -N bootroot and -N bootrootlv for creating boot+root disks. 2010-09-08 11:00:00 +01:00
Richard Jones
60cdd02b02 fish: Generate list of prepared disk image types.
This commit shouldn't change the semantics of the code.
2010-09-08 09:59:29 +01:00
Richard Jones
54837f6d7b fish: Implement progress bars in guestfish.
The progress bar is updated 3 times per second, and is not displayed
at all for operations which take less than two seconds.

You can disable progress bars by using the flag --no-progress-bars,
and you can enable progress bars in non-interactive sessions with
the flag --progress-bars.

A good way to test this is to use the following command:

guestfish --progress-bars \
          -N disk:10G \
          zero-device /dev/sda

(adjust "10G" to get different lengths of time).
2010-09-01 14:20:02 +01:00
Richard Jones
3003df6bbc fish: Detect UTF-8 output and open termcap/terminfo database.
Provide a generic mechanism within guestfish to detect if
output if UTF-8 and to open the termcap (or terminfo) database
for the current terminal type.
2010-09-01 12:03:35 +01:00
Richard Jones
4440e22f4f fish: Reimplement -i option using new C-based inspection.
Don't shell out to virt-inspector.  Instead, use the new C-based
inspection APIs.

This is much faster.

The new syntax is slightly different:

  guestfish -a disk.img -i
  guestfish -d guest -i

However, the old syntax still works.
2010-08-17 14:09:25 +01:00
Richard Jones
1a9aa565b3 fish: Add -c/--connect and -d/--domain options.
The -d option lets you specify libvirt domains.  The disks from
these domains are found and added, as if you'd named them with -a.

The -c option lets you specify a libvirt URI, which is needed
when we consult libvirt to implement the above.
2010-08-17 14:09:25 +01:00
Richard Jones
581a7965fa generator: Add 'Key' parameter type.
Add a 'Key' parameter type, used for passing sensitive key material
into libguestfs.

Eventually the plan is to mlock() key material into memory.  However
this is very difficult to achieve because the encoded XDR strings
end up in many places.  Therefore users should note that key material
passed to libguestfs might end up in swap.

The only difference between 'Key' and 'String' currently is that
guestfish requests the key from /dev/tty with echoing turned off.
2010-07-21 19:49:22 +01:00
Richard Jones
f2b7a8e15c fish: help command return error for non-existent commands (RHBZ#597145).
With this change, the exit status indicates error for non-existent
commands.

$ guestfish -h foo
foo: command not known, use -h to list all commands
$ echo $?
1
$ guestfish help foo
foo: command not known, use -h to list all commands
$ echo $?
1
2010-06-02 13:38:00 +01:00
Richard Jones
c9f1a45334 fish: New command: 'supported'
This checks all available optional groups and prints out which
ones are supported by the daemon.  Note you must launch the appliance
first.

Example:

><fs> supported
      augeas yes
     inotify yes
 linuxfsuuid yes
linuxmodules yes
 linuxxattrs yes
        lvm2 yes
       mknod yes
      ntfs3g yes
   ntfsprogs yes
    realpath yes
       scrub yes
     selinux yes
          xz yes
    zerofree yes
2010-05-25 11:31:11 +01:00
Richard Jones
bece54704b fish: Make 'launch' function static.
This commit makes the launch function static and private to
'fish.c', and changes the generator so the function is no longer
called for the 'run/launch' command.
2010-05-08 09:25:32 +01:00
Richard Jones
78d2523ec8 fish: Add 'man' command which opens the manual. 2010-04-24 09:11:37 +01:00
Richard Jones
4a9b979a31 fish: Add -N option for making prepared disk images.
Previously you might have typed:

$ guestfish
><fs> alloc test1.img 100M
><fs> run
><fs> part-disk /dev/sda mbr
><fs> mkfs ext4 /dev/sda1

now you can do the same with:

$ guestfish -N fs:ext4

Some tests have also been updated to use this new
functionality.
2010-04-22 18:07:11 +01:00
Richard Jones
3119aa687d fish: Allow -<<END as a syntax for uploading "heredocs".
For example:

    ><fs> upload -<<END /foo
    some data
    some more data
    END
    ><fs> cat /foo
    some data
    some more data
2010-04-19 15:08:45 +01:00
Richard Jones
42fc0e02b0 fish: Autocomplete 'sparse' command (RHBZ#582899).
I also rechecked the list of built-in commands against
the actual commands to make sure no others were omitted.
2010-04-17 13:11:20 +01:00
Richard Jones
4c50f4c38d fish: Print extended help when the user types an unknown command first.
$ guestfish /tmp/disk.img
/tmp/disk.img: unknown command
Did you mean to open a disk image?  guestfish -a disk.img
For a list of commands:             guestfish -h
For complete documentation:         man guestfish
2010-04-07 12:06:07 +01:00
Richard Jones
7581672c78 Mac OS X: Detect bindtextdomain.
These are missing on Mac OS X.  I think you would need to install
a gettext package to get these.
2010-03-22 08:48:08 +00:00
Richard Jones
ade327a7af Don't export STREQ and friends in <guestfs.h>
Move these to private header file(s) and other places as required
since these aren't part of the public API.
2009-11-10 17:09:12 +00:00