libnm: avoid deadlock during g_module_open() in _nm_utils_init()

_nm_utils_init() is a __attribute__((constructor)) function,
that is, it runs during dlopen().

On the other head, g_module_open() itself calls dlopen().

It is prone to deadlock. Don't do it.

The check is only an aggressive assertion to crash the application
if it wrongly loads libnm and libnm-util/libnm-glib at the same time.
If that happens, all is lost already. We can just as well call the
assertion later. It's not supposed to fail anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=796804
This commit is contained in:
Thomas Haller 2018-07-13 15:47:45 +02:00
parent 60f9be4e14
commit 4444db6b6f
2 changed files with 15 additions and 7 deletions

View file

@ -2057,6 +2057,21 @@ static void
nm_setting_class_init (NMSettingClass *setting_class)
{
GObjectClass *object_class = G_OBJECT_CLASS (setting_class);
GModule *self_module;
gpointer func;
/* loading libnm and legacy libraries libnm-util/libnm-glib at the same
* time is not supported. The reason is, that both libraries use the same
* glib type names ("NMSetting"), and glib does not support namespacing
* to allow for that.
*
* Arbitrarily, add a check here, see whether a known symbol from libnm-util
* is present. If it is, it indicates that the process is borked and we
* abort. */
self_module = g_module_open (NULL, 0);
if (g_module_symbol (self_module, "nm_util_get_private", &func))
g_error ("libnm-util symbols detected; Mixing libnm with libnm-util/libnm-glib is not supported");
g_module_close (self_module);
g_type_class_add_private (setting_class, sizeof (NMSettingPrivate));

View file

@ -236,8 +236,6 @@ static void __attribute__((constructor))
_nm_utils_init (void)
{
static int initialized = 0;
GModule *self;
gpointer func;
if (g_atomic_int_get (&initialized) != 0)
return;
@ -249,11 +247,6 @@ _nm_utils_init (void)
* Hence, a poor-man guard "initialized" above is more than sufficient,
* although it does not guarantee that the code is not run concurrently. */
self = g_module_open (NULL, 0);
if (g_module_symbol (self, "nm_util_get_private", &func))
g_error ("libnm-util symbols detected; Mixing libnm with libnm-util/libnm-glib is not supported");
g_module_close (self);
bindtextdomain (GETTEXT_PACKAGE, NMLOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");