source: rtems/cpukit/libcsupport/src/error.c @ 1c6926c1

5
Last change on this file since 1c6926c1 was 2b0bbc4, checked in by Sebastian Huber <sebastian.huber@…>, on 05/04/15 at 07:29:38

libcsupport: Avoid Giant lock in rtems_verror()

  • Property mode set to 100644
File size: 2.5 KB
Line 
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
25int          rtems_panic_in_progress;
26
27int 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, "[%" PRIu32 "] ", _Configuration_MP_table->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
77int 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}
101
102void rtems_panic(
103  const char *printf_format,
104  ...
105)
106{
107  va_list arglist;
108
109  va_start(arglist, printf_format);
110  (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
111  va_end(arglist);
112
113  rtems_error(0, "fatal error, exiting");
114  _exit(errno);
115}
Note: See TracBrowser for help on using the repository browser.