summaryrefslogtreecommitdiffstats
path: root/lib/replace
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2014-06-03 10:44:19 -0700
committerJeremy Allison <jra@samba.org>2014-06-07 03:15:14 +0200
commit536c799f00d7bdd6a574b6bdbc0e9c742eeef8b5 (patch)
treef59af2726545ce9fd8944b5ab07553af1a41b242 /lib/replace
parent463311422ca1caad2e228deb630e9d12e212fae1 (diff)
downloadsamba-536c799f00d7bdd6a574b6bdbc0e9c742eeef8b5.tar.gz
samba-536c799f00d7bdd6a574b6bdbc0e9c742eeef8b5.tar.xz
samba-536c799f00d7bdd6a574b6bdbc0e9c742eeef8b5.zip
lib: tevent: make TEVENT_SIG_INCREMENT atomic.
On arm platforms incrementing a variable is not an atomic operation, so may be interrupted by signal processing (if a signal interrupts another signal handler). Use compiler built-ins to make this atomic. __sync_fetch_and_add() works on gcc, llvm, IBM xlC on AIX, and Intel icc (10.1 and above). atomic_add_32() works on Oracle Solaris. Based on an inital patch from kamei@osstech.co.jp. Bug #10640 - smbd is not responding - tevent_common_signal_handler() increments non-atomic variables https://bugzilla.samba.org/show_bug.cgi?id=10640 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <Volker.Lendecke@SerNet.DE>
Diffstat (limited to 'lib/replace')
-rw-r--r--lib/replace/replace.h5
-rw-r--r--lib/replace/wscript25
2 files changed, 30 insertions, 0 deletions
diff --git a/lib/replace/replace.h b/lib/replace/replace.h
index f940898e4b9..bc40bf012e6 100644
--- a/lib/replace/replace.h
+++ b/lib/replace/replace.h
@@ -904,4 +904,9 @@ bool nss_wrapper_hosts_enabled(void);
bool socket_wrapper_enabled(void);
bool uid_wrapper_enabled(void);
+/* Needed for Solaris atomic_add_XX functions. */
+#if defined(HAVE_SYS_ATOMIC_H)
+#include <sys/atomic.h>
+#endif
+
#endif /* _LIBREPLACE_REPLACE_H */
diff --git a/lib/replace/wscript b/lib/replace/wscript
index a26de0f8bae..22dd1322a21 100644
--- a/lib/replace/wscript
+++ b/lib/replace/wscript
@@ -110,6 +110,7 @@ struct foo bar = { .y = 'X', .x = 1 };
conf.CHECK_HEADERS('sys/extattr.h sys/ea.h sys/proplist.h sys/cdefs.h')
conf.CHECK_HEADERS('utmp.h utmpx.h lastlog.h malloc.h')
conf.CHECK_HEADERS('syscall.h sys/syscall.h inttypes.h')
+ conf.CHECK_HEADERS('sys/atomic.h')
# Check for process set name support
conf.CHECK_CODE('''
@@ -229,6 +230,30 @@ struct foo bar = { .y = 'X', .x = 1 };
msg="Checking whether we have ucontext_t",
headers='signal.h sys/ucontext.h')
+ # Check for atomic builtins. */
+ conf.CHECK_CODE('''
+ int main(void) {
+ int i;
+ (void)__sync_fetch_and_add(&i, 1);
+ return 0;
+ }
+ ''',
+ 'HAVE___SYNC_FETCH_AND_ADD',
+ msg='Checking for __sync_fetch_and_add compiler builtin')
+
+ conf.CHECK_CODE('''
+ #include <stdint.h>
+ #include <sys/atomic.h>
+ int main(void) {
+ int32_t i;
+ atomic_add_32(&i, 1);
+ return 0;
+ }
+ ''',
+ 'HAVE_ATOMIC_ADD_32',
+ headers='stdint.h sys/atomic.h',
+ msg='Checking for atomic_add_32 compiler builtin')
+
# these may be builtins, so we need the link=False strategy
conf.CHECK_FUNCS('strdup memmem printf memset memcpy memmove strcpy strncpy bzero', link=False)