[libvirt] python module set-up ignores virInitialize failure

Jim Meyering jim at meyering.net
Tue May 18 10:32:13 UTC 2010


I've just fixed code in a test that ignored virInitialize failure.
Looking at all uses, I saw one other: in python/libvirt-override.c,
where the initialization function ignores virInitialize failure:

  void
  #ifndef __CYGWIN__
  initlibvirtmod
  #else
  initcygvirtmod
  #endif
    (void)
  {
      static int initialized = 0;

      if (initialized != 0)
          return;

      virInitialize();

      /* initialize the python extension module */
      Py_InitModule((char *)
  #ifndef __CYGWIN__
                    "libvirtmod"
  #else
                    "cygvirtmod"
  #endif
                    , libvirtMethods);

      initialized = 1;
  }

Unfortunately, this function is public, so we can't change its signature.
Any suggestions?

For reference, here's the function definition.  It shows that there
are many ways in which virInitialize can fail, including its many
registration functions:

/**
 * virInitialize:
 *
 * Initialize the library. It's better to call this routine at startup
 * in multithreaded applications to avoid potential race when initializing
 * the library.
 *
 * Returns 0 in case of success, -1 in case of error
 */
int
virInitialize(void)
{
    if (initialized)
        return(0);

    initialized = 1;

    if (virThreadInitialize() < 0 ||
        virErrorInitialize() < 0 ||
        virRandomInitialize(time(NULL) ^ getpid()))
        return -1;

    gcry_control(GCRYCTL_SET_THREAD_CBS, &virTLSThreadImpl);
    gcry_check_version(NULL);

    virLogSetFromEnv();

    DEBUG0("register drivers");

#if HAVE_WINSOCK2_H
    if (winsock_init () == -1) return -1;
#endif

    if (!bindtextdomain(GETTEXT_PACKAGE, LOCALEBASEDIR))
        return (-1);

    /*
     * Note that the order is important: the first ones have a higher
     * priority when calling virConnectOpen.
     */
#ifdef WITH_DRIVER_MODULES
    /* We don't care if any of these fail, because the whole point
     * is to allow users to only install modules they want to use.
     * If they try to open a connection for a module that
     * is not loaded they'll get a suitable error at that point
     */
    virDriverLoadModule("test");
    virDriverLoadModule("xen");
    virDriverLoadModule("openvz");
    virDriverLoadModule("vbox");
    virDriverLoadModule("esx");
    virDriverLoadModule("xenapi");
    virDriverLoadModule("remote");
#else
# ifdef WITH_TEST
    if (testRegister() == -1) return -1;
# endif
# ifdef WITH_XEN
    if (xenRegister () == -1) return -1;
# endif
# ifdef WITH_OPENVZ
    if (openvzRegister() == -1) return -1;
# endif
# ifdef WITH_PHYP
    if (phypRegister() == -1) return -1;
# endif
# ifdef WITH_VBOX
    if (vboxRegister() == -1) return -1;
# endif
# ifdef WITH_ESX
    if (esxRegister() == -1) return -1;
# endif
# ifdef WITH_XENAPI
    if (xenapiRegister() == -1) return -1;
# endif
# ifdef WITH_REMOTE
    if (remoteRegister () == -1) return -1;
# endif
#endif

    return(0);
}




More information about the libvir-list mailing list