mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-07 10:48:12 +02:00
core: fix building for GLib thread API changes (GLib >= 2.31.0) (bgo #662695)
This commit is contained in:
parent
582a8407ba
commit
4d1d3b9935
2 changed files with 43 additions and 11 deletions
|
|
@ -563,9 +563,18 @@ main (int argc, char *argv[])
|
||||||
umask (022);
|
umask (022);
|
||||||
|
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Threading is always enabled starting from GLib 2.31.0.
|
||||||
|
* See also http://developer.gnome.org/glib/2.31/glib-Deprecated-Thread-APIs.html.
|
||||||
|
*/
|
||||||
|
#if !GLIB_CHECK_VERSION (2,31,0)
|
||||||
if (!g_thread_supported ())
|
if (!g_thread_supported ())
|
||||||
g_thread_init (NULL);
|
g_thread_init (NULL);
|
||||||
dbus_g_thread_init ();
|
dbus_g_thread_init ();
|
||||||
|
#else
|
||||||
|
dbus_threads_init_default ();
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS
|
#ifndef HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS
|
||||||
#error HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS not defined
|
#error HAVE_DBUS_GLIB_DISABLE_LEGACY_PROP_ACCESS not defined
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2004 - 2010 Red Hat, Inc.
|
* Copyright (C) 2004 - 2011 Red Hat, Inc.
|
||||||
* Copyright (C) 2007 - 2008 Novell, Inc.
|
* Copyright (C) 2007 - 2008 Novell, Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
@ -36,7 +36,11 @@
|
||||||
struct HostnameThread {
|
struct HostnameThread {
|
||||||
GThread *thread;
|
GThread *thread;
|
||||||
|
|
||||||
|
#if GLIB_CHECK_VERSION (2,31,0)
|
||||||
|
GMutex lock;
|
||||||
|
#else
|
||||||
GMutex *lock;
|
GMutex *lock;
|
||||||
|
#endif
|
||||||
gboolean dead;
|
gboolean dead;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
@ -50,6 +54,25 @@ struct HostnameThread {
|
||||||
gpointer user_data;
|
gpointer user_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* GMutex API has changed:
|
||||||
|
* http://developer.gnome.org/glib/2.31/glib-Threads.html#GMutex
|
||||||
|
* http://developer.gnome.org/glib/2.31/glib-Deprecated-Thread-APIs.html
|
||||||
|
*/
|
||||||
|
#if GLIB_CHECK_VERSION (2,31,0)
|
||||||
|
#define X_MUTEX_LOCK(mutex) g_mutex_lock (&(mutex))
|
||||||
|
#define X_MUTEX_UNLOCK(mutex) g_mutex_unlock (&(mutex))
|
||||||
|
#define X_MUTEX_INIT(mutex) g_mutex_init (&(mutex))
|
||||||
|
#define X_MUTEX_CLEAR(mutex) g_mutex_clear (&(mutex))
|
||||||
|
#define X_THREAD_CREATE(func,data) g_thread_try_new ("hostname-thread", func, data, NULL);
|
||||||
|
#else
|
||||||
|
#define X_MUTEX_LOCK(mutex) g_mutex_lock (mutex)
|
||||||
|
#define X_MUTEX_UNLOCK(mutex) g_mutex_unlock (mutex)
|
||||||
|
#define X_MUTEX_INIT(mutex) mutex = g_mutex_new ()
|
||||||
|
#define X_MUTEX_CLEAR(mutex) g_mutex_free (mutex)
|
||||||
|
#define X_THREAD_CREATE(func,data) g_thread_create (func, data, FALSE, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
hostname_thread_run_cb (gpointer user_data)
|
hostname_thread_run_cb (gpointer user_data)
|
||||||
{
|
{
|
||||||
|
|
@ -72,12 +95,12 @@ hostname_thread_worker (gpointer data)
|
||||||
|
|
||||||
nm_log_dbg (LOGD_DNS, "(%p) starting address reverse-lookup", ht);
|
nm_log_dbg (LOGD_DNS, "(%p) starting address reverse-lookup", ht);
|
||||||
|
|
||||||
g_mutex_lock (ht->lock);
|
X_MUTEX_LOCK (ht->lock);
|
||||||
if (ht->dead) {
|
if (ht->dead) {
|
||||||
g_mutex_unlock (ht->lock);
|
X_MUTEX_UNLOCK (ht->lock);
|
||||||
return (gpointer) NULL;
|
return (gpointer) NULL;
|
||||||
}
|
}
|
||||||
g_mutex_unlock (ht->lock);
|
X_MUTEX_UNLOCK (ht->lock);
|
||||||
|
|
||||||
ht->ret = getnameinfo (ht->addr, ht->addr_size, ht->hostname, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
ht->ret = getnameinfo (ht->addr, ht->addr_size, ht->hostname, NI_MAXHOST, NULL, 0, NI_NAMEREQD);
|
||||||
if (ht->ret == 0) {
|
if (ht->ret == 0) {
|
||||||
|
|
@ -106,7 +129,7 @@ hostname_thread_free (HostnameThread *ht)
|
||||||
|
|
||||||
nm_log_dbg (LOGD_DNS, "(%p) freeing reverse-lookup thread", ht);
|
nm_log_dbg (LOGD_DNS, "(%p) freeing reverse-lookup thread", ht);
|
||||||
|
|
||||||
g_mutex_free (ht->lock);
|
X_MUTEX_CLEAR (ht->lock);
|
||||||
memset (ht, 0, sizeof (HostnameThread));
|
memset (ht, 0, sizeof (HostnameThread));
|
||||||
g_free (ht);
|
g_free (ht);
|
||||||
}
|
}
|
||||||
|
|
@ -123,7 +146,7 @@ hostname4_thread_new (guint32 ip4_addr,
|
||||||
ht = g_malloc0 (sizeof (HostnameThread));
|
ht = g_malloc0 (sizeof (HostnameThread));
|
||||||
g_assert (ht);
|
g_assert (ht);
|
||||||
|
|
||||||
ht->lock = g_mutex_new ();
|
X_MUTEX_INIT (ht->lock);
|
||||||
ht->callback = callback;
|
ht->callback = callback;
|
||||||
ht->user_data = user_data;
|
ht->user_data = user_data;
|
||||||
|
|
||||||
|
|
@ -132,7 +155,7 @@ hostname4_thread_new (guint32 ip4_addr,
|
||||||
ht->addr = (struct sockaddr *) &ht->addr4;
|
ht->addr = (struct sockaddr *) &ht->addr4;
|
||||||
ht->addr_size = sizeof (ht->addr4);
|
ht->addr_size = sizeof (ht->addr4);
|
||||||
|
|
||||||
ht->thread = g_thread_create (hostname_thread_worker, ht, FALSE, NULL);
|
ht->thread = X_THREAD_CREATE (hostname_thread_worker, ht);
|
||||||
if (!ht->thread) {
|
if (!ht->thread) {
|
||||||
hostname_thread_free (ht);
|
hostname_thread_free (ht);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -158,7 +181,7 @@ hostname6_thread_new (const struct in6_addr *ip6_addr,
|
||||||
ht = g_malloc0 (sizeof (HostnameThread));
|
ht = g_malloc0 (sizeof (HostnameThread));
|
||||||
g_assert (ht);
|
g_assert (ht);
|
||||||
|
|
||||||
ht->lock = g_mutex_new ();
|
X_MUTEX_INIT (ht->lock);
|
||||||
ht->callback = callback;
|
ht->callback = callback;
|
||||||
ht->user_data = user_data;
|
ht->user_data = user_data;
|
||||||
|
|
||||||
|
|
@ -167,7 +190,7 @@ hostname6_thread_new (const struct in6_addr *ip6_addr,
|
||||||
ht->addr = (struct sockaddr *) &ht->addr6;
|
ht->addr = (struct sockaddr *) &ht->addr6;
|
||||||
ht->addr_size = sizeof (ht->addr6);
|
ht->addr_size = sizeof (ht->addr6);
|
||||||
|
|
||||||
ht->thread = g_thread_create (hostname_thread_worker, ht, FALSE, NULL);
|
ht->thread = X_THREAD_CREATE (hostname_thread_worker, ht);
|
||||||
if (!ht->thread) {
|
if (!ht->thread) {
|
||||||
hostname_thread_free (ht);
|
hostname_thread_free (ht);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -189,9 +212,9 @@ hostname_thread_kill (HostnameThread *ht)
|
||||||
|
|
||||||
nm_log_dbg (LOGD_DNS, "(%p) stopping reverse-lookup thread", ht);
|
nm_log_dbg (LOGD_DNS, "(%p) stopping reverse-lookup thread", ht);
|
||||||
|
|
||||||
g_mutex_lock (ht->lock);
|
X_MUTEX_LOCK (ht->lock);
|
||||||
ht->dead = TRUE;
|
ht->dead = TRUE;
|
||||||
g_mutex_unlock (ht->lock);
|
X_MUTEX_UNLOCK (ht->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue