summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2015-03-20 10:59:08 -0700
committerVolker Lendecke <vl@samba.org>2015-03-24 14:43:22 +0100
commitd1914367289b58f26544ee6e116490d662d9c41c (patch)
treecae24c8276f7fef0cfd3c25e4b81eb31adb38f3c /lib
parente67130c60687cfecda878e7084c64e03a7f7a098 (diff)
downloadsamba-d1914367289b58f26544ee6e116490d662d9c41c.tar.gz
lib: tdb: Use sigaction when testing for robust mutexes.
Fixes bug #11175 - Lots of winbindd zombie processes on Solaris platform. https://bugzilla.samba.org/show_bug.cgi?id=11175 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Tue Mar 24 14:43:22 CET 2015 on sn-devel-104
Diffstat (limited to 'lib')
-rw-r--r--lib/tdb/common/mutex.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/lib/tdb/common/mutex.c b/lib/tdb/common/mutex.c
index 12f89d3b3da..d45cce82343 100644
--- a/lib/tdb/common/mutex.c
+++ b/lib/tdb/common/mutex.c
@@ -713,6 +713,27 @@ cleanup_ma:
static void (*tdb_robust_mutext_old_handler)(int) = SIG_ERR;
static pid_t tdb_robust_mutex_pid = -1;
+static void (*tdb_robust_mutex_setup_sigchild(void (*handler)(int)))(int)
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction act;
+ struct sigaction oldact;
+
+ memset(&act, '\0', sizeof(act));
+
+ act.sa_handler = handler;
+#ifdef SA_RESTART
+ act.sa_flags = SA_RESTART;
+#endif
+ sigemptyset(&act.sa_mask);
+ sigaddset(&act.sa_mask, SIGCHLD);
+ sigaction(SIGCHLD, &act, &oldact);
+ return oldact.sa_handler;
+#else /* !HAVE_SIGACTION */
+ return NULL;
+#endif
+}
+
static void tdb_robust_mutex_handler(int sig)
{
if (tdb_robust_mutex_pid != -1) {
@@ -803,8 +824,11 @@ _PUBLIC_ bool tdb_runtime_check_for_robust_mutexes(void)
goto cleanup_ma;
}
- tdb_robust_mutext_old_handler = signal(SIGCHLD,
- tdb_robust_mutex_handler);
+ tdb_robust_mutext_old_handler = tdb_robust_mutex_setup_sigchild(
+ tdb_robust_mutex_handler);
+ if (tdb_robust_mutext_old_handler == NULL) {
+ goto cleanup_ma;
+ }
tdb_robust_mutex_pid = fork();
if (tdb_robust_mutex_pid == 0) {
@@ -869,7 +893,7 @@ _PUBLIC_ bool tdb_runtime_check_for_robust_mutexes(void)
goto cleanup_child;
}
}
- signal(SIGCHLD, tdb_robust_mutext_old_handler);
+ tdb_robust_mutex_setup_sigchild(tdb_robust_mutext_old_handler);
ret = pthread_mutex_trylock(m);
if (ret != EOWNERDEAD) {
@@ -915,7 +939,7 @@ cleanup_child:
}
}
cleanup_sig_child:
- signal(SIGCHLD, tdb_robust_mutext_old_handler);
+ tdb_robust_mutex_setup_sigchild(tdb_robust_mutext_old_handler);
cleanup_m:
pthread_mutex_destroy(m);
cleanup_ma: