/****************************
* CONSTRUCTOR
***************************/
+
void uwrap_constructor(void)
{
+ char *glibc_malloc_lock_bug;
+
+ /*
+ * This is a workaround for a bug in glibc < 2.24:
+ *
+ * The child handler for the malloc() function is called and locks the
+ * mutex. Then our child handler is called and we try to call setenv().
+ * setenv() wants to malloc and tries to aquire the lock for malloc and
+ * we end up in a deadlock.
+ *
+ * So as a workaround we need to call malloc once before we setup the
+ * handlers.
+ *
+ * See https://sourceware.org/bugzilla/show_bug.cgi?id=16742
+ */
+ glibc_malloc_lock_bug = malloc(1);
+ if (glibc_malloc_lock_bug == NULL) {
+ exit(-1);
+ }
+ glibc_malloc_lock_bug[0] = '\0';
+
/*
* If we hold a lock and the application forks, then the child
* is not able to unlock the mutex and we are in a deadlock.
&uwrap_thread_parent,
&uwrap_thread_child);
+ free(glibc_malloc_lock_bug);
+
/* Here is safe place to call uwrap_init() and initialize data
* for main process.
*/