summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Hack <hack.robin@gmail.com>2015-01-23 15:10:02 +0100
committerAndreas Schneider <asn@cryptomilk.org>2015-01-28 17:17:07 +0100
commita79b5cf41c49a36a88d4ba486171699668a5357a (patch)
treeee4cc5765ae47bce5541d5f872330dae0291a314 /lib
parente279eee670310530eebe5dcfa3fc16b54d0356f2 (diff)
downloadsamba-a79b5cf41c49a36a88d4ba486171699668a5357a.tar.gz
samba-a79b5cf41c49a36a88d4ba486171699668a5357a.tar.xz
samba-a79b5cf41c49a36a88d4ba486171699668a5357a.zip
uwrap: Add library constructor and move pthread_atfork inside.
Library constructor is used for pthread_atfork call. Moved here because pthread_atfork is cumulative and should be called only once. Signed-off-by: Robin Hack <hack.robin@gmail.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/uid_wrapper/uid_wrapper.c31
-rw-r--r--lib/uid_wrapper/wscript17
2 files changed, 39 insertions, 9 deletions
diff --git a/lib/uid_wrapper/uid_wrapper.c b/lib/uid_wrapper/uid_wrapper.c
index a492b965d5..a955e77f0e 100644
--- a/lib/uid_wrapper/uid_wrapper.c
+++ b/lib/uid_wrapper/uid_wrapper.c
@@ -51,6 +51,12 @@
pthread_mutex_unlock(&( m ## _mutex)); \
} while(0)
+#ifdef HAVE_CONSTRUCTOR_ATTRIBUTE
+#define CONSTRUCTOR_ATTRIBUTE __attribute__ ((constructor))
+#else
+#define CONSTRUCTOR_ATTRIBUTE
+#endif /* HAVE_CONSTRUCTOR_ATTRIBUTE */
+
#ifdef HAVE_DESTRUCTOR_ATTRIBUTE
#define DESTRUCTOR_ATTRIBUTE __attribute__ ((destructor))
#else
@@ -249,6 +255,7 @@ static pthread_mutex_t uwrap_id_mutex = PTHREAD_MUTEX_INITIALIZER;
*********************************************************/
bool uid_wrapper_enabled(void);
+void uwrap_constructor(void) CONSTRUCTOR_ATTRIBUTE;
void uwrap_destructor(void) DESTRUCTOR_ATTRIBUTE;
/*********************************************************
@@ -591,15 +598,6 @@ static void uwrap_init(void)
UWRAP_LOG(UWRAP_LOG_DEBUG, "Initialize uid_wrapper");
- /*
- * 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.
- * This should prevent such deadlocks.
- */
- pthread_atfork(&uwrap_thread_prepare,
- &uwrap_thread_parent,
- &uwrap_thread_child);
-
UWRAP_LOCK(uwrap_id);
uwrap.initialised = true;
@@ -1249,6 +1247,21 @@ long int syscall (long int sysno, ...)
#endif /* HAVE_SYS_SYSCALL_H || HAVE_SYSCALL_H */
/****************************
+ * CONSTRUCTOR
+ ***************************/
+void uwrap_constructor(void)
+{
+ /*
+ * 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.
+ * This should prevent such deadlocks.
+ */
+ pthread_atfork(&uwrap_thread_prepare,
+ &uwrap_thread_parent,
+ &uwrap_thread_child);
+}
+
+/****************************
* DESTRUCTOR
***************************/
diff --git a/lib/uid_wrapper/wscript b/lib/uid_wrapper/wscript
index 6b585956e0..bd797e5a72 100644
--- a/lib/uid_wrapper/wscript
+++ b/lib/uid_wrapper/wscript
@@ -21,6 +21,23 @@ def configure(conf):
addmain=False,
msg='Checking for thread local storage')
+ # check HAVE_CONSTRUCTOR_ATTRIBUTE
+ conf.CHECK_CODE('''
+ void test_constructor_attribute(void) __attribute__ ((constructor));
+
+ void test_constructor_attribute(void)
+ {
+ return;
+ }
+
+ int main(void) {
+ return 0;
+ }
+ ''',
+ 'HAVE_CONSTRUCTOR_ATTRIBUTE',
+ addmain=False,
+ msg='Checking for library constructor support')
+
# check HAVE_DESTRUCTOR_ATTRIBUTE
conf.CHECK_CODE('''
void test_destructor_attribute(void) __attribute__ ((destructor));