diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2016-04-04 18:02:42 +0200 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2016-04-05 15:38:18 +0200 |
commit | 2a4bf49edd6e094174dd6e0a65051cf4b378b03c (patch) | |
tree | c3bf937e015bef8d6ddd081bc6e86f7465c40797 | |
parent | 8473d0ae71e5c7ae005b186048ba930208749238 (diff) |
log: Make sure glib threading is initialized
While testing spice-server on EL6, I was getting random crashes in the
glib logging code because g_logv was called recursively even though this
was not visible in a backtrace.
It turns out on older glib versions (EL6 has 2.28), g_logv is not
thread-safe unless g_thread_init() is called first. If g_thread_init()
is not called, the GMutex/GPrivate calls g_logv makes are turned into
no-ops, which is going to cause the recursion issue I was seeing.
This commit adds a call to g_thread_init() for these older glib
versions.
(gdb) bt
0x7fff9f9fb110 "item.type: 114", unused_data=0x0) at gmessages.c:863
format=0x7ffff50e72ac "item.type: %d", args1=0x7fff9f9fb640) at gmessages.c:517
SPICE_LOG_LEVEL_DEBUG, strloc=0x7ffff50e72ba "dcc.c:1652", function=
0x7ffff50e7320 "release_item_before_push", format=0x7ffff50e72ac "item.type: %d", args=
0x7fff9f9fb640) at log.c:163
SPICE_LOG_LEVEL_DEBUG, strloc=0x7ffff50e72ba "dcc.c:1652", function=
0x7ffff50e7320 "release_item_before_push", format=0x7ffff50e72ac "item.type: %d") at log.c:195
at dcc.c:1652
at dcc.c:1719
at dcc-send.c:2450
at red-channel.c:578
at red-channel.c:1587
at event-loop.c:122
0x7ffff4fb2ef2 <watch_func>, user_data=0x7fff980244e0) at giounix.c:166
0x7ffff86ec770) at gmain.c:3092
-rw-r--r-- | common/log.c | 8 | ||||
-rw-r--r-- | m4/spice-deps.m4 | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/common/log.c b/common/log.c index d4a6d28..e39eefc 100644 --- a/common/log.c +++ b/common/log.c @@ -138,6 +138,14 @@ SPICE_CONSTRUCTOR_FUNC(spice_log_init) g_log_set_handler(SPICE_LOG_DOMAIN, G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, spice_logger, NULL); + /* Threading is always enabled from 2.31.0 onwards */ + /* Our logging is potentially used from different threads. + * Older glibs require that g_thread_init() is called when + * doing that. */ +#if !GLIB_CHECK_VERSION(2, 31, 0) + if (!g_thread_supported()) + g_thread_init(NULL); +#endif } static void spice_logv(const char *log_domain, diff --git a/m4/spice-deps.m4 b/m4/spice-deps.m4 index fb43cd2..170adf2 100644 --- a/m4/spice-deps.m4 +++ b/m4/spice-deps.m4 @@ -173,7 +173,7 @@ AC_DEFUN([SPICE_CHECK_PIXMAN], [ # use in the GLIB2_CFLAGS and GLIB2_LIBS variables. #------------------ AC_DEFUN([SPICE_CHECK_GLIB2], [ - PKG_CHECK_MODULES(GLIB2, glib-2.0 >= 2.22 gio-2.0 >= 2.22) + PKG_CHECK_MODULES(GLIB2, glib-2.0 >= 2.22 gio-2.0 >= 2.22 gthread-2.0 >= 2.22) ]) # SPICE_CHECK_PYTHON_MODULES() |