aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2017-12-24 12:59:47 +0100
committerAnders Broman <a.broman58@gmail.com>2017-12-24 20:22:58 +0000
commitbad83f249fa583e1f26224a9bd7b557f6d790c08 (patch)
tree076737f25d36b118a1d0377f9d1699281fbef47e
parent8642d72f36239267c474ef096252dc64ac6fd710 (diff)
Fix build and thread runtime compat with older GLib
CentOS 6 ships with glib 2.28.8 which do not support g_ptr_array_new_full (make-taps/make-dissectors) and need to link with wsutil for glib-compat. g_thread_new was only introduced with GLib 2.32 (not 2.31), so adjust the check accordingly. Abort in case thread creation fails (as documented). Properly initialize threads or it will abort on runtime (this also requires linking epan with gthreads in CMake, autotools already includes it with GLIB_LIBS). Change-Id: Ie81d6df7b3b26aaa4eb25e23719a220755e2c13c Reviewed-on: https://code.wireshark.org/review/24978 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Reviewed-by: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--dumpcap.c7
-rw-r--r--epan/CMakeLists.txt1
-rw-r--r--epan/dissectors/CMakeLists.txt3
-rw-r--r--epan/dissectors/packet-tibia.c2
-rw-r--r--epan/epan.c14
-rw-r--r--ui/CMakeLists.txt3
-rw-r--r--wsutil/glib-compat.c12
-rw-r--r--wsutil/glib-compat.h1
8 files changed, 33 insertions, 10 deletions
diff --git a/dumpcap.c b/dumpcap.c
index bebe9195ef..7b4b554940 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -120,6 +120,9 @@
#endif
#endif
+/* for g_thread_new */
+#include "wsutil/glib-compat.h"
+
#ifdef DEBUG_CHILD_DUMPCAP
FILE *debug_log; /* for logging debug messages to */
/* a file if DEBUG_CHILD_DUMPCAP */
@@ -2044,11 +2047,7 @@ pcapng_pipe_open_live(int fd,
}
#ifdef _WIN32
else {
-#if GLIB_CHECK_VERSION(2,31,0)
g_thread_new("cap_pipe_open_live", &cap_thread_read, pcap_src);
-#else
- g_thread_create(&cap_thread_read, pcap_src, FALSE, NULL);
-#endif
bh->block_type = type;
pcap_src->cap_pipe_buf = (char *) &bh->block_total_length;
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index 85e9ed741d..1ad2bfedf8 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -282,6 +282,7 @@ set(epan_LIBS
${GCRYPT_LIBRARIES}
${GEOIP_LIBRARIES}
${GLIB2_LIBRARIES}
+ ${GTHREAD2_LIBRARIES}
${GNUTLS_LIBRARIES}
${KERBEROS_LIBRARIES}
${LUA_LIBRARIES}
diff --git a/epan/dissectors/CMakeLists.txt b/epan/dissectors/CMakeLists.txt
index 9f4eff5cbe..5c3a0d9151 100644
--- a/epan/dissectors/CMakeLists.txt
+++ b/epan/dissectors/CMakeLists.txt
@@ -1865,7 +1865,8 @@ set(ALL_DISSECTOR_SRC
)
add_executable(make-dissectors make-dissectors.c)
-target_link_libraries(make-dissectors ${GLIB2_LIBRARIES})
+# wsutil is only required for glib-compat.c
+target_link_libraries(make-dissectors ${GLIB2_LIBRARIES} wsutil)
#
# We pass the arguments to make-dissectors in a file to avoid limitations
diff --git a/epan/dissectors/packet-tibia.c b/epan/dissectors/packet-tibia.c
index 6e03365e27..424ba90ebe 100644
--- a/epan/dissectors/packet-tibia.c
+++ b/epan/dissectors/packet-tibia.c
@@ -554,7 +554,7 @@ register_gameserv_addr(struct tibia_convo *convo, guint32 ipaddr, guint16 port)
alloc_address_wmem(NULL, &entry->addr, AT_IPv4, sizeof ipaddr, &ipaddr);
entry->port = port;
entry->privkey = NULL;
- if (!g_hash_table_contains(rsakeys, entry)) {
+ if (g_hash_table_lookup(rsakeys, entry) == NULL) {
entry->privkey = convo->privkey;
g_hash_table_insert(rsakeys, entry, entry->privkey);
} else {
diff --git a/epan/epan.c b/epan/epan.c
index 42d9208d61..43c1dbd284 100644
--- a/epan/epan.c
+++ b/epan/epan.c
@@ -191,6 +191,20 @@ epan_init(void (*register_all_protocols_func)(register_cb cb, gpointer client_da
{
volatile gboolean status = TRUE;
+ /*
+ * proto_init -> register_all_protocols -> g_async_queue_new which
+ * requires threads to be initialized. This happens automatically with
+ * GLib 2.32, before that g_thread_init must be called. But only since
+ * GLib 2.24, multiple invocations are allowed. Check for an earlier
+ * invocation just in case.
+ */
+#if !GLIB_CHECK_VERSION(2,31,0)
+# if !GLIB_CHECK_VERSION(2,24,0)
+ if (!g_thread_get_initialized())
+# endif
+ g_thread_init(NULL);
+#endif
+
/* initialize memory allocation subsystem */
wmem_init();
diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt
index e56e01a1d3..9c2bb03584 100644
--- a/ui/CMakeLists.txt
+++ b/ui/CMakeLists.txt
@@ -97,7 +97,8 @@ set_target_properties(ui PROPERTIES
)
add_executable(make-taps make-taps.c)
-target_link_libraries(make-taps ${GLIB2_LIBRARIES})
+# wsutil is only required for glib-compat.c
+target_link_libraries(make-taps ${GLIB2_LIBRARIES} wsutil)
if (HTML_HELP_COMPILER)
add_definitions(-DHHC_DIR)
diff --git a/wsutil/glib-compat.c b/wsutil/glib-compat.c
index fc6e7f1aca..e741581c93 100644
--- a/wsutil/glib-compat.c
+++ b/wsutil/glib-compat.c
@@ -120,9 +120,17 @@ g_async_queue_timeout_pop(GAsyncQueue *queue,
#if !GLIB_CHECK_VERSION(2,31,0)
-GThread *g_thread_new(const gchar *name _U_, GThreadFunc func, gpointer data)
+GThread *g_thread_new(const gchar *name, GThreadFunc func, gpointer data)
{
- return g_thread_create(func, data, TRUE, NULL);
+ GError *error = NULL;
+ GThread *thread;
+
+ thread = g_thread_create(func, data, TRUE, &error);
+
+ if G_UNLIKELY (thread == NULL)
+ g_error ("creating thread '%s': %s", name ? name : "", error->message);
+
+ return thread;
}
#endif /* GLIB_CHECK_VERSION(2,31,0)*/
diff --git a/wsutil/glib-compat.h b/wsutil/glib-compat.h
index 3110ad5146..8393e91232 100644
--- a/wsutil/glib-compat.h
+++ b/wsutil/glib-compat.h
@@ -28,7 +28,6 @@ WS_DLL_PUBLIC GPtrArray* g_ptr_array_new_full(guint reserved_size, GDestroyNotif
WS_DLL_PUBLIC gpointer g_async_queue_timeout_pop(GAsyncQueue *queue, guint64 timeout);
#endif /* !GLIB_CHECK_VERSION(2,31,18) */
-// joinable = TRUE, error = NULL
#if !GLIB_CHECK_VERSION(2,31,0)
WS_DLL_PUBLIC GThread *g_thread_new (const gchar *name, GThreadFunc func, gpointer data);
#endif /* !GLIB_CHECK_VERSION(2,31,0) */