Re: [osinfo-db/libosinfo PATCH 0/6] Add support to images

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Oct 31, 2018 at 10:45:32PM +0100, Fabiano Fidêncio wrote:
> Last but not least, I'm cc'ing here Richard Jones and Pino Toscano in
> order to get their input in the libguestfs bits ... mainly to know
> whether explicitly depending on libguestfs is a good idea or not (and,
> if not, to get some feedback on different approaches that could be
> taken).

libguestfs is a pretty large dependency.  It's also circular
(libguestfs uses libosinfo!)

IMO you would probably be better off dlopen-ing libguestfs.  At the
packaging level that would allow you to make the dependency optional
(ie. Recommends or Suggests in RPM).

dlopen would change the way you have to call libguestfs, but it's not
especially hard.  The code would end up looking something like:

  #include <dlfcn.h>
  #include <guestfs.h>

  static void *dl;
  static guestfs_h * (*guestfs_create) (void);
  static void (*guestfs_close) (guestfs_h *);
  // etc.

  ...

  static void your_init_function () __attribute__((constructor));
  static void your_fini_function () __attribute__((destructor));

  static void
  your_init_function ()
  {
    dl = dlopen ("libguestfs.so.0", RTLD_NOW);
    if (dl == NULL)
      return;
    guestfs_create = dlsym (dl, "guestfs_create");
    guestfs_close = dlsym (dl, "guestfs_close");
    // etc.
  }

  static void
  your_fini_function ()
  {
    if (dl)
      dlclose (dl);
  }

  int
  your_public_function ()
  {
    if (!dl) // ie. libguestfs not available at run time
      return -EOPNOTSUPP;

    g = guestfs_create ();
    // etc.
  }

(It might also be possible to do this with weak linking)

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org

_______________________________________________
Libosinfo mailing list
Libosinfo@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libosinfo




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Fedora Users]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux