From 87ea8b98d5c2bc4a9ecb5951fb5ef06831fc1b99 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Mar 2015 10:59:08 -0700 Subject: [PATCH] lib: tdb: Use sigaction when testing for robust mutexes. Fixes bug #11175 New: Lots of winbindd zombie processes on Solaris platform. https://bugzilla.samba.org/show_bug.cgi?id=11175 Signed-off-by: Jeremy Allison --- lib/tdb/common/mutex.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/tdb/common/mutex.c b/lib/tdb/common/mutex.c index 12f89d3..3700903 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); + (void)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); + (void)tdb_robust_mutex_setup_sigchild(tdb_robust_mutext_old_handler); cleanup_m: pthread_mutex_destroy(m); cleanup_ma: -- 2.2.0.rc0.207.ga3a616c