1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Error and Panic Report Support |
---|
5 | * @ingroup ErrorPanicSupport |
---|
6 | */ |
---|
7 | |
---|
8 | #if HAVE_CONFIG_H |
---|
9 | #include "config.h" |
---|
10 | #endif |
---|
11 | |
---|
12 | #include <rtems.h> |
---|
13 | #include <rtems/error.h> |
---|
14 | #include <rtems/assoc.h> |
---|
15 | #include <rtems/score/sysstate.h> |
---|
16 | #include <rtems/score/threadimpl.h> |
---|
17 | #include <inttypes.h> |
---|
18 | #include <stdio.h> |
---|
19 | #include <stdarg.h> |
---|
20 | #include <errno.h> |
---|
21 | #include <stdlib.h> |
---|
22 | #include <string.h> |
---|
23 | #include <unistd.h> /* _exit() */ |
---|
24 | |
---|
25 | int rtems_panic_in_progress; |
---|
26 | |
---|
27 | int rtems_verror( |
---|
28 | rtems_error_code_t error_flag, |
---|
29 | const char *printf_format, |
---|
30 | va_list arglist |
---|
31 | ) |
---|
32 | { |
---|
33 | int local_errno = 0; |
---|
34 | int chars_written = 0; |
---|
35 | rtems_status_code status; |
---|
36 | |
---|
37 | if (error_flag & RTEMS_ERROR_PANIC) { |
---|
38 | if (rtems_panic_in_progress++) |
---|
39 | _Thread_Dispatch_disable(); /* disable task switches */ |
---|
40 | |
---|
41 | /* don't aggravate things */ |
---|
42 | if (rtems_panic_in_progress > 2) |
---|
43 | return 0; |
---|
44 | } |
---|
45 | |
---|
46 | (void) fflush(stdout); /* in case stdout/stderr same */ |
---|
47 | |
---|
48 | status = error_flag & ~RTEMS_ERROR_MASK; |
---|
49 | if (error_flag & RTEMS_ERROR_ERRNO) /* include errno? */ |
---|
50 | local_errno = errno; |
---|
51 | |
---|
52 | #if defined(RTEMS_MULTIPROCESSING) |
---|
53 | if (_System_state_Is_multiprocessing) |
---|
54 | fprintf(stderr, "[%" PRIu16 "] ", rtems_object_get_local_node()); |
---|
55 | #endif |
---|
56 | |
---|
57 | chars_written += vfprintf(stderr, printf_format, arglist); |
---|
58 | |
---|
59 | if (status) |
---|
60 | chars_written += |
---|
61 | fprintf(stderr, " (status: %s)", rtems_status_text(status)); |
---|
62 | |
---|
63 | if (local_errno) { |
---|
64 | if ((local_errno > 0) && *strerror(local_errno)) |
---|
65 | chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno)); |
---|
66 | else |
---|
67 | chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno); |
---|
68 | } |
---|
69 | |
---|
70 | chars_written += fprintf(stderr, "\n"); |
---|
71 | |
---|
72 | (void) fflush(stderr); |
---|
73 | |
---|
74 | return chars_written; |
---|
75 | } |
---|
76 | |
---|
77 | int rtems_error( |
---|
78 | rtems_error_code_t error_flag, |
---|
79 | const char *printf_format, |
---|
80 | ... |
---|
81 | ) |
---|
82 | { |
---|
83 | va_list arglist; |
---|
84 | int chars_written; |
---|
85 | |
---|
86 | va_start(arglist, printf_format); |
---|
87 | chars_written = rtems_verror(error_flag, printf_format, arglist); |
---|
88 | va_end(arglist); |
---|
89 | |
---|
90 | if (error_flag & RTEMS_ERROR_PANIC) { |
---|
91 | rtems_error(0, "fatal error, exiting"); |
---|
92 | _exit(errno); |
---|
93 | } |
---|
94 | if (error_flag & RTEMS_ERROR_ABORT) { |
---|
95 | rtems_error(0, "fatal error, aborting"); |
---|
96 | abort(); |
---|
97 | } |
---|
98 | |
---|
99 | return chars_written; |
---|
100 | } |
---|