[PPL-devel] [GIT] ppl/ppl(master): Improve portability to systems that do not (fully) support Posix signal handling.

Roberto Bagnara bagnara at cs.unipr.it
Mon Feb 15 14:51:06 CET 2010


Module: ppl/ppl
Branch: master
Commit: 7ba6445b1c5adb835e27d2f005779d4343721d21
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=7ba6445b1c5adb835e27d2f005779d4343721d21

Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date:   Mon Feb 15 14:50:19 2010 +0100

Improve portability to systems that do not (fully) support Posix signal handling.

---

 Watchdog/configure.ac      |    1 +
 Watchdog/pwl-config.sed    |    4 ++-
 Watchdog/tests/pwl_test.cc |   62 +++++++++++++++++++++++++++++++++++++++----
 configure.ac               |    1 +
 ppl-config.sed             |    4 +++
 tests/ppl_test.cc          |   62 +++++++++++++++++++++++++++++++++++++++----
 6 files changed, 121 insertions(+), 13 deletions(-)

diff --git a/Watchdog/configure.ac b/Watchdog/configure.ac
index b831583..4e7b1a8 100644
--- a/Watchdog/configure.ac
+++ b/Watchdog/configure.ac
@@ -371,6 +371,7 @@ then
 
   # Checks for the availability of C library functions in C++.
   AC_CHECK_DECLS([getenv], , , [#include <cstdlib>])
+  AC_CHECK_DECLS([sigaction], , , [#include <csignal>])
 
   # Checks for typedefs, structures, and compiler characteristics.
   AC_CHECK_TYPES([siginfo_t], [], [], [[
diff --git a/Watchdog/pwl-config.sed b/Watchdog/pwl-config.sed
index 960a73e..15a0d31 100644
--- a/Watchdog/pwl-config.sed
+++ b/Watchdog/pwl-config.sed
@@ -1,9 +1,11 @@
 s/\([^A-Z_]\)HAVE_DECL_GETENV/\1PWL_HAVE_DECL_GETENV/g
+s/\([^A-Z_]\)HAVE_DECL_SIGACTION/\1PWL_HAVE_DECL_SIGACTION/g
 s/\([^A-Z_]\)HAVE_DLFCN_H/\1PWL_HAVE_DLFCN_H/g
 s/\([^A-Z_]\)HAVE_FENV_H/\1PWL_HAVE_FENV_H/g
 s/\([^A-Z_]\)HAVE_INTTYPES_H/\1PWL_HAVE_INTTYPES_H/g
 s/\([^A-Z_]\)HAVE_MEMORY_H/\1PWL_HAVE_MEMORY_H/g
-s/\([^A-Z_]\)HAVE_SETITIMER_H/\1PWL_HAVE_SETITIMER_H/g
+s/\([^A-Z_]\)HAVE_SETITIMER/\1PWL_HAVE_SETITIMER/g
+s/\([^A-Z_]\)HAVE_SIGINFO_T/\1PWL_HAVE_SIGINFO_T/g
 s/\([^A-Z_]\)HAVE_STDINT_H/\1PWL_HAVE_STDINT_H/g
 s/\([^A-Z_]\)HAVE_STDLIB_H/\1PWL_HAVE_STDLIB_H/g
 s/\([^A-Z_]\)HAVE_STRINGS_H/\1PWL_HAVE_STRINGS_H/g
diff --git a/Watchdog/tests/pwl_test.cc b/Watchdog/tests/pwl_test.cc
index 41ab632..f4b828c 100644
--- a/Watchdog/tests/pwl_test.cc
+++ b/Watchdog/tests/pwl_test.cc
@@ -43,9 +43,12 @@ uncaught_exception_handler() {
   exit(1);
 }
 
-#ifdef HAVE_SIGINFO_T
+#ifdef PWL_HAVE_DECL_SIGACTION
+
+#if defined(PWL_HAVE_SIGINFO_T) && defined(SA_SIGINFO)
+
 void
-fpe_handler(int sig, siginfo_t* sip, void*) {
+fpe_sigaction(int sig, siginfo_t* sip, void*) {
   if (sig != SIGFPE) {
     std::cerr << "fpe_handler called on signal different from SIGFPE"
 	      << std::endl;
@@ -113,7 +116,49 @@ fpe_handler(int sig, siginfo_t* sip, void*) {
   }
   exit(1);
 }
-#endif // defined(HAVE_SIGINFO_T)
+
+#else // !defined(PWL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
+
+void
+fpe_handler(int sig) {
+  if (sig != SIGFPE) {
+    std::cerr << "fpe_handler called on signal different from SIGFPE"
+	      << std::endl;
+    exit(1);
+  }
+  std::cerr << "SIGFPE caught"
+            << std::endl;
+#if defined(PWL_HAVE_FENV_H)
+    std::cerr << "Inquire with fetestexcept(): ";
+#ifdef FE_INEXACT
+    if (fetestexcept(FE_INEXACT))
+      std::cerr << "FE_INEXACT ";
+#endif
+#ifdef FE_DIVBYZERO
+    if (fetestexcept(FE_DIVBYZERO))
+      std::cerr << "FE_DIVBYZERO ";
+#endif
+#ifdef FE_UNDERFLOW
+    if (fetestexcept(FE_UNDERFLOW))
+      std::cerr << "FE_UNDERFLOW ";
+#endif
+#ifdef FE_OVERFLOW
+    if (fetestexcept(FE_OVERFLOW))
+      std::cerr << "FE_OVERFLOW ";
+#endif
+#if FE_INVALID
+    if (fetestexcept(FE_INVALID))
+      std::cerr << "FE_INVALID ";
+#endif
+    std::cerr << std::endl;
+#endif
+  }
+  exit(1);
+}
+
+#endif // !defined(PWL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
+
+#endif // defined(PWL_HAVE_DECL_SIGACTION)
 
 } // namespace
 
@@ -121,19 +166,24 @@ namespace Parma_Watchdog_Library {
 
 namespace Test {
 
-#ifdef HAVE_SIGINFO_T
 void
 set_handlers() {
+#ifdef PWL_HAVE_DECL_SIGACTION
   struct sigaction action;
-  action.sa_sigaction = fpe_handler;
   sigemptyset(&action.sa_mask);
+#if defined(PWL_HAVE_SIGINFO_T) && defined(SA_SIGINFO)
+  action.sa_sigaction = fpe_sigaction;
   action.sa_flags = SA_SIGINFO;
+#else // !defined(PWL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
+  action.sa_handler = fpe_handler;
+  action.sa_flags = 0;
+#endif // !defined(PWL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
   if (sigaction(SIGFPE, &action, NULL) != 0) {
     std::cerr << "sigaction() failed"
 	      << std::endl;
     abort();
   }
-#endif // defined(HAVE_SIGINFO_T)
+#endif // defined(PWL_HAVE_DECL_SIGACTION)
 
   std::set_unexpected(unexpected_exception_handler);
   std::set_terminate(uncaught_exception_handler);
diff --git a/configure.ac b/configure.ac
index 465f530..d67f0ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1472,6 +1472,7 @@ AC_CHECK_DECLS([getrusage],
 # include <sys/resource.h>
 #endif
 ])
+AC_CHECK_DECLS([sigaction], , , [#include <csignal>])
 
 # Checks for typedefs, structures, and compiler characteristics.
 AC_CHECK_TYPES([timeval])
diff --git a/ppl-config.sed b/ppl-config.sed
index 2d74bb6..95f8ae1 100644
--- a/ppl-config.sed
+++ b/ppl-config.sed
@@ -10,6 +10,7 @@ s/\([^A-Z_]\)HAVE_DECL_RLIMIT_AS/\1PPL_HAVE_DECL_RLIMIT_AS/g
 s/\([^A-Z_]\)HAVE_DECL_RLIMIT_DATA/\1PPL_HAVE_DECL_RLIMIT_DATA/g
 s/\([^A-Z_]\)HAVE_DECL_RLIMIT_RSS/\1PPL_HAVE_DECL_RLIMIT_RSS/g
 s/\([^A-Z_]\)HAVE_DECL_RLIMIT_VMEM/\1PPL_HAVE_DECL_RLIMIT_VMEM/g
+s/\([^A-Z_]\)HAVE_DECL_SIGACTION/\1PPL_HAVE_DECL_SIGACTION/g
 s/\([^A-Z_]\)HAVE_DECL_STRTOD/\1PPL_HAVE_DECL_STRTOD/g
 s/\([^A-Z_]\)HAVE_DECL_STRTOF/\1PPL_HAVE_DECL_STRTOF/g
 s/\([^A-Z_]\)HAVE_DECL_STRTOLD/\1PPL_HAVE_DECL_STRTOLD/g
@@ -26,6 +27,8 @@ s/\([^A-Z_]\)HAVE_INT_FAST16_T/\1PPL_HAVE_INT_FAST16_T/g
 s/\([^A-Z_]\)HAVE_INT_FAST32_T/\1PPL_HAVE_INT_FAST32_T/g
 s/\([^A-Z_]\)HAVE_INT_FAST64_T/\1PPL_HAVE_INT_FAST64_T/g
 s/\([^A-Z_]\)HAVE_MEMORY_H/\1PPL_HAVE_MEMORY_H/g
+s/\([^A-Z_]\)HAVE_SETITIMER/\1PPL_HAVE_SETITIMER/g
+s/\([^A-Z_]\)HAVE_SIGINFO_T/\1PPL_HAVE_SIGINFO_T/g
 s/\([^A-Z_]\)HAVE_SIGNAL_H/\1PPL_HAVE_SIGNAL_H/g
 s/\([^A-Z_]\)HAVE_STDINT_H/\1PPL_HAVE_STDINT_H/g
 s/\([^A-Z_]\)HAVE_STDLIB_H/\1PPL_HAVE_STDLIB_H/g
@@ -40,6 +43,7 @@ s/\([^A-Z_]\)HAVE_TYPEOF/\1PPL_HAVE_TYPEOF/g
 s/\([^A-Z_]\)HAVE_UINT_FAST16_T/\1PPL_HAVE_UINT_FAST16_T/g
 s/\([^A-Z_]\)HAVE_UINT_FAST32_T/\1PPL_HAVE_UINT_FAST32_T/g
 s/\([^A-Z_]\)HAVE_UINT_FAST64_T/\1PPL_HAVE_UINT_FAST64_T/g
+s/\([^A-Z_]\)HAVE_UINTPTR_T/\1PPL_HAVE_UINTPTR_T/g
 s/\([^A-Z_]\)HAVE_UNISTD_H/\1PPL_HAVE_UNISTD_H/g
 s/\([^A-Z_]\)HAVE___MPZ_STRUCT__MP_ALLOC/\1PPL_HAVE___MPZ_STRUCT__MP_ALLOC/g
 s/\([^A-Z_]\)HAVE___MPZ_STRUCT__MP_D/\1PPL_HAVE___MPZ_STRUCT__MP_D/g
diff --git a/tests/ppl_test.cc b/tests/ppl_test.cc
index 3c5caef..c0ac87f 100644
--- a/tests/ppl_test.cc
+++ b/tests/ppl_test.cc
@@ -43,9 +43,12 @@ uncaught_exception_handler() {
   exit(1);
 }
 
-#ifdef HAVE_SIGINFO_T
+#ifdef PPL_HAVE_DECL_SIGACTION
+
+#if defined(PPL_HAVE_SIGINFO_T) && defined(SA_SIGINFO)
+
 void
-fpe_handler(int sig, siginfo_t* sip, void*) {
+fpe_sigaction(int sig, siginfo_t* sip, void*) {
   if (sig != SIGFPE) {
     std::cerr << "fpe_handler called on signal different from SIGFPE"
 	      << std::endl;
@@ -113,7 +116,49 @@ fpe_handler(int sig, siginfo_t* sip, void*) {
   }
   exit(1);
 }
-#endif // defined(HAVE_SIGINFO_T)
+
+#else // !defined(PPL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
+
+void
+fpe_handler(int sig) {
+  if (sig != SIGFPE) {
+    std::cerr << "fpe_handler called on signal different from SIGFPE"
+	      << std::endl;
+    exit(1);
+  }
+  std::cerr << "SIGFPE caught"
+            << std::endl;
+#if defined(PWL_HAVE_FENV_H)
+    std::cerr << "Inquire with fetestexcept(): ";
+#ifdef FE_INEXACT
+    if (fetestexcept(FE_INEXACT))
+      std::cerr << "FE_INEXACT ";
+#endif
+#ifdef FE_DIVBYZERO
+    if (fetestexcept(FE_DIVBYZERO))
+      std::cerr << "FE_DIVBYZERO ";
+#endif
+#ifdef FE_UNDERFLOW
+    if (fetestexcept(FE_UNDERFLOW))
+      std::cerr << "FE_UNDERFLOW ";
+#endif
+#ifdef FE_OVERFLOW
+    if (fetestexcept(FE_OVERFLOW))
+      std::cerr << "FE_OVERFLOW ";
+#endif
+#if FE_INVALID
+    if (fetestexcept(FE_INVALID))
+      std::cerr << "FE_INVALID ";
+#endif
+    std::cerr << std::endl;
+#endif
+  }
+  exit(1);
+}
+
+#endif // !defined(PPL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
+
+#endif // defined(PPL_HAVE_DECL_SIGACTION)
 
 } // namespace
 
@@ -123,17 +168,22 @@ namespace Test {
 
 void
 set_handlers() {
-#ifdef HAVE_SIGINFO_T
+#ifdef PPL_HAVE_DECL_SIGACTION
   struct sigaction action;
-  action.sa_sigaction = fpe_handler;
   sigemptyset(&action.sa_mask);
+#if defined(PPL_HAVE_SIGINFO_T) && defined(SA_SIGINFO)
+  action.sa_sigaction = fpe_sigaction;
   action.sa_flags = SA_SIGINFO;
+#else // !defined(PPL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
+  action.sa_handler = fpe_handler;
+  action.sa_flags = 0;
+#endif // !defined(PPL_HAVE_SIGINFO_T) || !defined(SA_SIGINFO)
   if (sigaction(SIGFPE, &action, NULL) != 0) {
     std::cerr << "sigaction() failed"
 	      << std::endl;
     abort();
   }
-#endif // defined(HAVE_SIGINFO_T)
+#endif // defined(PPL_HAVE_DECL_SIGACTION)
 
   std::set_unexpected(unexpected_exception_handler);
   std::set_terminate(uncaught_exception_handler);




More information about the PPL-devel mailing list