[Libguestfs] simplify debugging of guestfsd

Richard W.M. Jones rjones at redhat.com
Sun Oct 14 18:02:29 UTC 2012


On Fri, Sep 21, 2012 at 02:24:13PM +0100, Richard W.M. Jones wrote:
> So environment variables are the way to go.
> 
> Another complication is that guestfs_create doesn't have a rich way to
> return errors, and thus if the environment variables cannot be parsed
> things start to go wrong.  Currently it spits error messages out to
> stderr in this case, which is very bad behaviour.
> 
> With the benefit of hindsight, splitting handle creation and
> environment parsing into two calls would have been better:
> 
>   g = guestfs_create ();
>   if (!g) error;
>   if (guestfs_set_environment (g) == -1) {
>     /* with the handle created, richer error methods are now available */
>   }
> 
> But we cannot change that now without breaking clients.

I thought of a way to do this which is backwards compatible.

Introduce a new guestfs_create_flags () call which takes a flag
variable.  By default, passing flag == 0 is entirely the same as
guestfs_create.

  g = guestfs_create_flags (0);
  if (!g) error;

However you could also use it like this:

  g = guestfs_create_flags (GUESTFS_CREATE_NO_ENVIRONMENT);
  if (!g) error;

where no environment variable processing is done (hence no errors are
possible except ENOMEM).  Callers can do environment variable
processing later (see guestfs_set_environment above).  Or maybe not if
they don't want to be affected by the environment.  Errors can be
handled properly in those later calls.

In the language backends, we'd have to map this to more flexible
functions, eg. in Perl:

  my $g = Sys::Guestfs->new (environment => 0);

(which is of course backwards compatible with existing code).

I'll post a patch for this tomorrow if I have the time.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list