From f7918064ff36c85b787c08c3e4f0dd9622f1090a Mon Sep 17 00:00:00 2001 From: Jeff Squyres Date: Wed, 9 Feb 2005 03:08:13 +0000 Subject: [PATCH] Always flush to get a slightly better guarantee of getting the error message out. Use stderr, and put a "yes, we're done with the error message" marker at the end of the error message so that you know if you saw it all or the message was truncated. This commit was SVN r4333. --- src/util/stacktrace.c | 69 ++++++++++++++++++++++++------------------- src/util/stacktrace.h | 2 ++ 2 files changed, 41 insertions(+), 30 deletions(-) diff --git a/src/util/stacktrace.c b/src/util/stacktrace.c index ddb34b73e8..1e4fc33d4a 100644 --- a/src/util/stacktrace.c +++ b/src/util/stacktrace.c @@ -15,6 +15,11 @@ #include "ompi_config.h" #include "include/constants.h" +#include +#ifdef HAVE_UNISTD_H +#include +#endif + #ifdef HAVE_EXECINFO_H #include #endif @@ -62,6 +67,7 @@ static void ompi_show_stackframe (int signo, siginfo_t * info, void * p) int size = sizeof (print_buffer); int ret; char * str=""; + char eof_msg[] = "*** End of error message ***\n"; /* * Yes, we are doing printf inside a signal-handler. @@ -204,41 +210,46 @@ static void ompi_show_stackframe (int signo, siginfo_t * info, void * p) case SIGFPE: case SIGSEGV: case SIGBUS: - { - ret = snprintf (tmp, size, "Failing at addr:%p\n", - info->si_addr); - size -= ret; - tmp += ret; - break; - } + { + ret = snprintf (tmp, size, "Failing at addr:%p\n", + info->si_addr); + size -= ret; + tmp += ret; + break; + } case SIGCHLD: { - ret = snprintf (tmp, size, "si_pid:%d si_uid:%d si_status:%d\n", - info->si_pid, info->si_uid, info->si_status); - size -= ret; - tmp += ret; - break; + ret = snprintf (tmp, size, "si_pid:%d si_uid:%d si_status:%d\n", + info->si_pid, info->si_uid, info->si_status); + size -= ret; + tmp += ret; + break; } #ifdef SIGPOLL case SIGPOLL: { - ret = snprintf (tmp, size, "si_band:%ld si_fd:%d\n", - info->si_band, info->si_fd); - size -= ret; - tmp += ret; - break; + ret = snprintf (tmp, size, "si_band:%ld si_fd:%d\n", + info->si_band, info->si_fd); + size -= ret; + tmp += ret; + break; } #endif } - - printf ("%s", print_buffer); - fflush(stdout); + + write(1, print_buffer, size); + fflush(stderr); #ifdef __GLIBC__ trace_size = backtrace (trace, 32); messages = backtrace_symbols (trace, trace_size); - for (i = 0; i < trace_size; i++) - printf ("[%d] func:%s\n", i, messages[i]); + for (i = 0; i < trace_size; i++) { + fprintf(stderr, "[%d] func:%s\n", i, messages[i]); + fflush(stderr); + } #endif + + write(1, eof_msg, sizeof(eof_msg)); + fflush(stderr); } #endif /* WIN32 */ @@ -283,25 +294,23 @@ int ompi_util_register_stackhandlers (void) int ret; sig = strtol (tmp, &next, 10); - /* - printf ("ompi_util_register_stackhandlers: sig:%d tmp:%p next:%p " - "tmp:[%s] next:[%s] _NSIG:%d\n", - sig, tmp, next, tmp, next, _NSIG); - */ /* * If there is no sensible number in the string, exit. * Similarly for any number which is not in the signal-number range */ - if (((0 == sig) && (tmp == next)) || (0 > sig) || (_NSIG <= sig)) + if (((0 == sig) && (tmp == next)) || (0 > sig) || (_NSIG <= sig)) { return OMPI_ERR_BAD_PARAM; + } - if ((next == NULL) || ((*next != ',') && (*next != '\0'))) + if ((next == NULL) || ((*next != ',') && (*next != '\0'))) { return OMPI_ERR_BAD_PARAM; + } ret = sigaction (sig, &act, NULL); - if (ret != 0) + if (ret != 0) { return OMPI_ERR_IN_ERRNO; + } } #endif /* WIN32 */ return OMPI_SUCCESS; diff --git a/src/util/stacktrace.h b/src/util/stacktrace.h index 5fd7a29f3e..0dbbee2c41 100644 --- a/src/util/stacktrace.h +++ b/src/util/stacktrace.h @@ -10,6 +10,8 @@ * Additional copyrights may follow * * $HEADER$ + * + * @file */ #ifndef OMPI_STACKTRACE_H