Fix build and thread runtime compat with older GLib
authorPeter Wu <peter@lekensteyn.nl>
Sun, 24 Dec 2017 11:59:47 +0000 (12:59 +0100)
committerAnders Broman <a.broman58@gmail.com>
Sun, 24 Dec 2017 20:22:58 +0000 (20:22 +0000)
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>
dumpcap.c
epan/CMakeLists.txt
epan/dissectors/CMakeLists.txt
epan/dissectors/packet-tibia.c
epan/epan.c
ui/CMakeLists.txt
wsutil/glib-compat.c
wsutil/glib-compat.h

index bebe9195eff4ec0203f3e8ead71bd771c0c2e85d..7b4b554940b3d0a3fed29ac2ea6d2bc77a87a3d8 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
 #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;
index 85e9ed741de0fcf5c757c0c4620746f959b74018..1ad2bfedf87664fe02e432717458f5c897f2eb88 100644 (file)
@@ -282,6 +282,7 @@ set(epan_LIBS
        ${GCRYPT_LIBRARIES}
        ${GEOIP_LIBRARIES}
        ${GLIB2_LIBRARIES}
+       ${GTHREAD2_LIBRARIES}
        ${GNUTLS_LIBRARIES}
        ${KERBEROS_LIBRARIES}
        ${LUA_LIBRARIES}
index 9f4eff5cbe9eadd8ac9584e11d2267ec7e25488b..5c3a0d915121bbb69dcc469ec4e3cd40d8bbd5ba 100644 (file)
@@ -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
index 6e03365e270a0fb3d133c762bb5c78e822bd2e75..424ba90ebeafe1e85fdd3bccaf43b38f4f0ca872 100644 (file)
@@ -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 {
index 42d9208d61dd1c5f6880a9595437139dfef79d4d..43c1dbd284750f449c4574488a56652b09feb390 100644 (file)
@@ -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();
 
index e56e01a1d3b0c7b9cc2881201a55b411188c3385..9c2bb03584faafdd4abd511d545b2e3c68425fcf 100644 (file)
@@ -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)
index fc6e7f1acaece70355568cff0ec5203c2939c595..e741581c932adef5c5833f33921a16ba67588368 100644 (file)
@@ -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)*/
 
index 3110ad5146fc6a16ffada91d60f22a81b8de5259..8393e91232532557617015aa5642ad1dc6f92db9 100644 (file)
@@ -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) */