diff options
author | Tavian Barnes <tavianator@gmail.com> | 2011-12-26 04:20:52 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2011-12-26 04:20:52 -0500 |
commit | bf56062df55226e44afb574791dbbe67d3632642 (patch) | |
tree | 4c49e2201b2763146abcb96e89bb4a17cdda576b | |
parent | a8181915a4aac7a37bdd62705e2eac1067eb1904 (diff) | |
download | dimension-bf56062df55226e44afb574791dbbe67d3632642.tar.xz |
Print errno in dmnsn_report_error().
-rw-r--r-- | configure.ac | 13 | ||||
-rw-r--r-- | libdimension/error.c | 24 |
2 files changed, 32 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac index 5652aff..0ef84d7 100644 --- a/configure.ac +++ b/configure.ac @@ -106,6 +106,19 @@ dnl Platform feature tests m4_include(ax_pthread.m4) AX_PTHREAD([], [AC_MSG_ERROR([pthread support not detected])]) +AC_MSG_CHECKING([for sys_errlist]) +AC_LINK_IFELSE([ + AC_LANG_PROGRAM( + [ #include <stdio.h> + #include <errno.h> ], + [ const char *errstr = sys_errlist@<:@sys_nerr - 1@:>@; ] + )], + [AC_DEFINE([DMNSN_SYS_ERRLIST], [1]) + AC_MSG_RESULT([yes])], + [AC_DEFINE([DMNSN_SYS_ERRLIST], [0]) + AC_MSG_RESULT([no])] +) + AC_MSG_CHECKING([for sched_getaffinity()]) AC_LINK_IFELSE([ AC_LANG_PROGRAM( diff --git a/libdimension/error.c b/libdimension/error.c index 5b82548..c738639 100644 --- a/libdimension/error.c +++ b/libdimension/error.c @@ -25,8 +25,9 @@ #include "dimension-internal.h" #include <pthread.h> -#include <stdio.h> /* For fprintf() */ -#include <stdlib.h> /* For exit() */ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> /** Report internal errors in this file. */ #define DMNSN_LOCAL_ERROR(str) \ @@ -55,9 +56,11 @@ dmnsn_local_unlock_mutex_impl(pthread_mutex_t *mutex) } /** Lock a mutex, bailing out without dmnsn_error() on error. */ -#define dmnsn_local_lock_mutex(mutex) dmnsn_local_lock_mutex_impl((mutex)); { +#define dmnsn_local_lock_mutex(mutex) \ + dmnsn_local_lock_mutex_impl((mutex)); { /** Unlock a mutex, bailing out without dmnsn_error() on error. */ -#define dmnsn_local_unlock_mutex(mutex) dmnsn_local_unlock_mutex_impl((mutex)); } +#define dmnsn_local_unlock_mutex(mutex) \ + dmnsn_local_unlock_mutex_impl((mutex)); } /** The default fatal error handler. */ static void dmnsn_default_fatal_error_fn(void); @@ -69,7 +72,7 @@ static pthread_mutex_t dmnsn_fatal_mutex = PTHREAD_MUTEX_INITIALIZER; /** The current resilience. */ static bool dmnsn_always_die = false; -/** Mutex which protexts \c dmnsn_always_die. */ +/** Mutex which protects \c dmnsn_always_die. */ static pthread_mutex_t dmnsn_always_die_mutex = PTHREAD_MUTEX_INITIALIZER; /* Called by dmnsn_error macro (don't call directly) */ @@ -77,6 +80,8 @@ void dmnsn_report_error(bool die, const char *func, const char *file, unsigned int line, const char *str) { + int err = errno; + bool always_die; dmnsn_local_lock_mutex(&dmnsn_always_die_mutex); always_die = dmnsn_always_die; @@ -84,6 +89,15 @@ dmnsn_report_error(bool die, const char *func, const char *file, fprintf(stderr, "Dimension %s: %s, %s:%u: %s\n", die ? "ERROR" : "WARNING", func, file, line, str); + if (err != 0) { + fprintf(stderr, "Last error: %d", err); +#if DMNSN_SYS_ERRLIST + if (err >= 0 && err < sys_nerr) { + fprintf(stderr, " (%s)", sys_errlist[err]); + } +#endif + fprintf(stderr, "\n"); + } if (die || always_die) { /* Prevent infinite recursion if the fatal error function itself calls |