source: rtems/c/src/lib/libmisc/error/error.c @ 3a4ae6c

4.104.114.84.95
Last change on this file since 3a4ae6c was 3a4ae6c, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 11, 1995 at 7:35:39 PM

The word "RTEMS" almost completely removed from the core.

Configuration Table Template file added and all tests
modified to use this. All gvar.h and conftbl.h files
removed from test directories.

Configuration parameter maximum_devices added.

Core semaphore and mutex handlers added and RTEMS API Semaphore
Manager updated to reflect this.

Initialization sequence changed to invoke API specific initialization
routines. Initialization tasks table now owned by RTEMS Tasks Manager.

Added user extension for post-switch.

Utilized user extensions to implement API specific functionality
like signal dispatching.

Added extensions to the System Initialization Thread so that an
API can register a function to be invoked while the system
is being initialized. These are largely equivalent to the
pre-driver and post-driver hooks.

Added the Modules file oar-go32_p5, modified oar-go32, and modified
the file make/custom/go32.cfg to look at an environment varable which
determines what CPU model is being used.

All BSPs updated to reflect named devices and clock driver's IOCTL
used by the Shared Memory Driver. Also merged clock isr into
main file and removed ckisr.c where possible.

Updated spsize to reflect new and moved variables.

Makefiles for the executive source and include files updated to show
break down of files into Core, RTEMS API, and Neither.

Header and inline files installed into subdirectory based on whether
logically in the Core or a part of the RTEMS API.

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