source: rtems/cpukit/libcsupport/src/error.c @ da154e14

4.115
Last change on this file since da154e14 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 6.1 KB
Line 
1/*
2 *  report errors and panics to RTEMS' stderr.
3 *  Currently just used by RTEMS monitor.
4 */
5
6#if HAVE_CONFIG_H
7#include "config.h"
8#endif
9
10/*
11 * These routines provide general purpose error reporting.
12 * rtems_error reports an error to stderr and allows use of
13 * printf style formatting.  A newline is appended to all messages.
14 *
15 * error_flag can be specified as any of the following:
16 *
17 *  RTEMS_ERROR_ERRNO       -- include errno text in output
18 *  RTEMS_ERROR_PANIC       -- halts local system after output
19 *  RTEMS_ERROR_ABORT       -- abort after output
20 *
21 * It can also include a rtems_status value which can be OR'd
22 * with the above flags. *
23 *
24 * EXAMPLE
25 *  #include <rtems.h>
26 *  #include <rtems/error.h>
27 *  rtems_error(0, "stray interrupt %d", intr);
28 *
29 * EXAMPLE
30 *        if ((status = rtems_task_create(...)) != RTEMS_SUCCCESSFUL)
31 *        {
32 *            rtems_error(status | RTEMS_ERROR_ABORT,
33 *                        "could not create task");
34 *        }
35 *
36 * EXAMPLE
37 *        if ((fd = open(pathname, O_RDNLY)) < 0)
38 *        {
39 *            rtems_error(RTEMS_ERROR_ERRNO, "open of '%s' failed", pathname);
40 *            goto failed;
41 *        }
42 */
43
44/* This is always defined on RTEMS Scheduler Simulator and thus
45 * we get a redefined warning if this is not present.
46 */
47#ifndef __RTEMS_VIOLATE_KERNEL_VISIBILITY__
48  #define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
49#endif
50#include <rtems.h>
51
52#include <rtems/error.h>
53#include <rtems/assoc.h>
54#include <inttypes.h>
55#include <stdio.h>
56#include <stdarg.h>
57#include <errno.h>
58#include <stdlib.h>
59#include <string.h>
60#include <unistd.h>     /* _exit() */
61
62int          rtems_panic_in_progress;
63
64const rtems_assoc_t rtems_status_assoc[] = {
65  { "successful completion",              RTEMS_SUCCESSFUL, 0 },
66  { "returned from a thread",             RTEMS_TASK_EXITTED, 0 },
67  { "multiprocessing not configured",     RTEMS_MP_NOT_CONFIGURED, 0 },
68  { "invalid object name",                RTEMS_INVALID_NAME, 0 },
69  { "invalid object id",                  RTEMS_INVALID_ID, 0 },
70  { "too many",                           RTEMS_TOO_MANY, 0 },
71  { "timed out waiting",                  RTEMS_TIMEOUT, 0 },
72  { "object deleted while waiting",       RTEMS_OBJECT_WAS_DELETED, 0 },
73  { "specified size was invalid",         RTEMS_INVALID_SIZE, 0 },
74  { "address specified is invalid",       RTEMS_INVALID_ADDRESS, 0 },
75  { "number was invalid",                 RTEMS_INVALID_NUMBER, 0 },
76  { "item has not been initialized",      RTEMS_NOT_DEFINED, 0 },
77  { "resources still outstanding",        RTEMS_RESOURCE_IN_USE, 0 },
78  { "request not satisfied",              RTEMS_UNSATISFIED, 0 },
79  { "thread is in wrong state",           RTEMS_INCORRECT_STATE, 0 },
80  { "thread already in state",            RTEMS_ALREADY_SUSPENDED, 0 },
81  { "illegal on calling thread",          RTEMS_ILLEGAL_ON_SELF, 0 },
82  { "illegal for remote object",          RTEMS_ILLEGAL_ON_REMOTE_OBJECT, 0 },
83  { "called from wrong environment",      RTEMS_CALLED_FROM_ISR, 0 },
84  { "invalid thread priority",            RTEMS_INVALID_PRIORITY, 0 },
85  { "invalid date/time",                  RTEMS_INVALID_CLOCK, 0 },
86  { "invalid node id",                    RTEMS_INVALID_NODE, 0 },
87  { "directive not configured",           RTEMS_NOT_CONFIGURED, 0 },
88  { "not owner of resource",              RTEMS_NOT_OWNER_OF_RESOURCE , 0 },
89  { "directive not implemented",          RTEMS_NOT_IMPLEMENTED, 0 },
90  { "RTEMS inconsistency detected",       RTEMS_INTERNAL_ERROR, 0 },
91  { "could not get enough memory",        RTEMS_NO_MEMORY, 0 },
92  { "driver IO error",                    RTEMS_IO_ERROR, 0 },
93  { "internal multiprocessing only",      THREAD_STATUS_PROXY_BLOCKING, 0 },
94  { 0, 0, 0 },
95};
96
97
98const char *rtems_status_text(
99  rtems_status_code status
100)
101{
102  return rtems_assoc_name_by_local(rtems_status_assoc, status);
103}
104
105
106static int rtems_verror(
107  rtems_error_code_t  error_flag,
108  const char         *printf_format,
109  va_list             arglist
110)
111{
112  int               local_errno = 0;
113  int               chars_written = 0;
114  rtems_status_code status;
115
116  if (error_flag & RTEMS_ERROR_PANIC) {
117    if (rtems_panic_in_progress++)
118      _Thread_Disable_dispatch();       /* disable task switches */
119
120    /* don't aggravate things */
121    if (rtems_panic_in_progress > 2)
122      return 0;
123  }
124
125  (void) fflush(stdout);            /* in case stdout/stderr same */
126
127  status = error_flag & ~RTEMS_ERROR_MASK;
128  if (error_flag & RTEMS_ERROR_ERRNO)     /* include errno? */
129    local_errno = errno;
130
131  #if defined(RTEMS_MULTIPROCESSING)
132    if (_System_state_Is_multiprocessing)
133      fprintf(stderr, "[%" PRIu32 "] ", _Configuration_MP_table->node);
134  #endif
135
136  chars_written += vfprintf(stderr, printf_format, arglist);
137
138  if (status)
139    chars_written +=
140      fprintf(stderr, " (status: %s)", rtems_status_text(status));
141
142  if (local_errno) {
143    if ((local_errno > 0) && *strerror(local_errno))
144      chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
145    else
146      chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
147  }
148
149  chars_written += fprintf(stderr, "\n");
150
151  (void) fflush(stderr);
152
153  return chars_written;
154}
155
156
157/*
158 * Report an error.
159 * error_flag is as above; printf_format is a normal
160 * printf(3) format string, with its concommitant arguments.
161 *
162 * Returns the number of characters written.
163 */
164
165int rtems_error(
166  rtems_error_code_t error_flag,
167  const char *printf_format,
168  ...
169)
170{
171  va_list arglist;
172  int chars_written;
173
174  va_start(arglist, printf_format);
175  chars_written = rtems_verror(error_flag, printf_format, arglist);
176  va_end(arglist);
177
178  if (error_flag & RTEMS_ERROR_PANIC) {
179    rtems_error(0, "fatal error, exiting");
180    _exit(errno);
181  }
182  if (error_flag & RTEMS_ERROR_ABORT) {
183    rtems_error(0, "fatal error, aborting");
184    abort();
185  }
186
187  return chars_written;
188}
189
190/*
191 * rtems_panic is shorthand for rtems_error(RTEMS_ERROR_PANIC, ...)
192 */
193
194void rtems_panic(
195  const char *printf_format,
196  ...
197)
198{
199  va_list arglist;
200
201  va_start(arglist, printf_format);
202  (void) rtems_verror(RTEMS_ERROR_PANIC, printf_format, arglist);
203  va_end(arglist);
204
205  rtems_error(0, "fatal error, exiting");
206  _exit(errno);
207}
Note: See TracBrowser for help on using the repository browser.