Spot-check of glib initialization

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

 



Amanda is using glib these days, and is quite happy with it.  However,
we were just tripped up by a change in glib-2.24 where g_type_init
initializes threads before we're ready.  This is important because we
need to initialize libcurl before threads are started.

I've rejiggered the glib_init method.  You can see the updated version here:
  http://github.com/djmitche/amanda/blob/glibinit/common-src/glib-util.c#L36
and also copied below (with apologies for the inevitable text
wrapping).  I'd like to know if I've missed anything else that might
trip up compatibility with future versions of glib.  If you spot
something, please let me know.

void
glib_init(void) {
    static gboolean did_glib_init = FALSE;
    if (did_glib_init) return;
    did_glib_init = TRUE;

    /* set up libcurl (this must happen before threading
     * is initialized) */
#ifdef HAVE_LIBCURL
# ifdef G_THREADS_ENABLED
    g_assert(!g_thread_supported()); /* assert threads aren't initialized yet */
# endif
    g_assert(curl_global_init(CURL_GLOBAL_ALL) == 0);
#endif

    /* do a version check */
#if GLIB_CHECK_VERSION(2,6,0)
    {
        const char *glib_err = glib_check_version(GLIB_MAJOR_VERSION,
                                                  GLIB_MINOR_VERSION,
                                                  GLIB_MICRO_VERSION);
        if (glib_err) {
            error(_("%s: Amanda was compiled with glib-%d.%d.%d"), glib_err,
                    GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);
            exit(1); /* glib_init may be called before error handling
is set up */
        }
    }
#endif

    /* Initialize glib's type system.  On glib >= 2.24, this will initialize
     * threads, so it must be done after curl is initialized. */
    g_type_init();

    /* And set up glib's threads */
#if defined(G_THREADS_ENABLED) && !defined(G_THREADS_IMPL_NONE)
    if (!g_thread_supported())
        g_thread_init(NULL);
#endif
}

-- 
Open Source Storage Engineer
http://www.zmanda.com
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux