summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-21 22:54:44 +0200
committerLennart Poettering <lennart@poettering.net>2009-04-21 22:54:44 +0200
commit928adf412f6d568926e00831c55c8d2d574ddc61 (patch)
tree20afa2ea0f8b21954123afd4105cc72a1d1b3881 /src
parent7b0086185fcebe671cafd4292ee0ce9e0e73c848 (diff)
memtrap: make installation of SIGBUS handler explicit to ease integration into libraries
Diffstat (limited to 'src')
-rw-r--r--src/pulsecore/memtrap.c38
-rw-r--r--src/pulsecore/memtrap.h2
-rw-r--r--src/tests/sigbus-test.c1
3 files changed, 18 insertions, 23 deletions
diff --git a/src/pulsecore/memtrap.c b/src/pulsecore/memtrap.c
index 49042537..a6ae510f 100644
--- a/src/pulsecore/memtrap.c
+++ b/src/pulsecore/memtrap.c
@@ -154,21 +154,6 @@ pa_memtrap* pa_memtrap_add(const void *start, size_t size) {
lock = pa_static_mutex_get(&write_lock, FALSE, FALSE);
pa_mutex_lock(lock);
- if (!memtraps[0]) {
- struct sigaction sa;
-
- /* Before we install the signal handler, make sure the
- * semaphore is valid so that the initialization of the
- * semaphore doesn't have to happen from the signal handler */
- pa_static_semaphore_get(&semaphore, 0);
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_sigaction = signal_handler;
- sa.sa_flags = SA_RESTART|SA_SIGINFO;
-
- pa_assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
- }
-
n = (unsigned) pa_atomic_load(&read_lock);
j = WHICH(n);
@@ -204,14 +189,6 @@ void pa_memtrap_remove(pa_memtrap *m) {
pa_xfree(m);
- if (!memtraps[0]) {
- struct sigaction sa;
-
- memset(&sa, 0, sizeof(sa));
- sa.sa_handler = SIG_DFL;
- pa_assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
- }
-
pa_mutex_unlock(lock);
}
@@ -255,3 +232,18 @@ unlock:
return m;
}
+
+void pa_memtrap_install(void) {
+ struct sigaction sa;
+
+ /* Before we install the signal handler, make sure the semaphore
+ * is valid so that the initialization of the semaphore
+ * doesn't have to happen from the signal handler */
+ pa_static_semaphore_get(&semaphore, 0);
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_sigaction = signal_handler;
+ sa.sa_flags = SA_RESTART|SA_SIGINFO;
+
+ pa_assert_se(sigaction(SIGBUS, &sa, NULL) == 0);
+}
diff --git a/src/pulsecore/memtrap.h b/src/pulsecore/memtrap.h
index d93d6720..6cad296c 100644
--- a/src/pulsecore/memtrap.h
+++ b/src/pulsecore/memtrap.h
@@ -35,4 +35,6 @@ void pa_memtrap_remove(pa_memtrap *m);
pa_bool_t pa_memtrap_is_good(pa_memtrap *m);
+void pa_memtrap_install(void);
+
#endif
diff --git a/src/tests/sigbus-test.c b/src/tests/sigbus-test.c
index dec4f0f2..4b9ca840 100644
--- a/src/tests/sigbus-test.c
+++ b/src/tests/sigbus-test.c
@@ -35,6 +35,7 @@ int main(int argc, char *argv[]) {
pa_memtrap *m;
pa_log_set_level(PA_LOG_DEBUG);
+ pa_memtrap_install();
/* Create the memory map */
pa_assert_se((fd = open("sigbus-test-map", O_RDWR|O_TRUNC|O_CREAT, 0660)) >= 0);