File indexing completed on 2025-05-11 08:24:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034 #ifdef HAVE_CONFIG_H
0035 #include "config.h"
0036 #endif
0037
0038 #include <rtems.h>
0039 #include <rtems/error.h>
0040 #include <rtems/assoc.h>
0041 #include <rtems/score/sysstate.h>
0042 #include <rtems/score/threadimpl.h>
0043 #include <inttypes.h>
0044 #include <stdio.h>
0045 #include <stdarg.h>
0046 #include <errno.h>
0047 #include <stdlib.h>
0048 #include <string.h>
0049 #include <unistd.h> /* _exit() */
0050
0051 int rtems_panic_in_progress;
0052
0053 int rtems_verror(
0054 rtems_error_code_t error_flag,
0055 const char *printf_format,
0056 va_list arglist
0057 )
0058 {
0059 int local_errno = 0;
0060 int chars_written = 0;
0061 rtems_status_code status;
0062
0063 if (error_flag & RTEMS_ERROR_PANIC) {
0064 if (rtems_panic_in_progress++)
0065 _Thread_Dispatch_disable();
0066
0067
0068 if (rtems_panic_in_progress > 2)
0069 return 0;
0070 }
0071
0072 (void) fflush(stdout);
0073
0074 status = error_flag & ~RTEMS_ERROR_MASK;
0075 if (error_flag & RTEMS_ERROR_ERRNO)
0076 local_errno = errno;
0077
0078 #if defined(RTEMS_MULTIPROCESSING)
0079 if (_System_state_Is_multiprocessing)
0080 fprintf(stderr, "[%" PRIu16 "] ", rtems_object_get_local_node());
0081 #endif
0082
0083 chars_written += vfprintf(stderr, printf_format, arglist);
0084
0085 if (status)
0086 chars_written +=
0087 fprintf(stderr, " (status: %s)", rtems_status_text(status));
0088
0089 if (local_errno) {
0090 if ((local_errno > 0) && *strerror(local_errno))
0091 chars_written += fprintf(stderr, " (errno: %s)", strerror(local_errno));
0092 else
0093 chars_written += fprintf(stderr, " (unknown errno=%d)", local_errno);
0094 }
0095
0096 chars_written += fprintf(stderr, "\n");
0097
0098 (void) fflush(stderr);
0099
0100 return chars_written;
0101 }
0102
0103 int rtems_error(
0104 rtems_error_code_t error_flag,
0105 const char *printf_format,
0106 ...
0107 )
0108 {
0109 va_list arglist;
0110 int chars_written;
0111
0112 va_start(arglist, printf_format);
0113 chars_written = rtems_verror(error_flag, printf_format, arglist);
0114 va_end(arglist);
0115
0116 if (error_flag & RTEMS_ERROR_PANIC) {
0117 rtems_error(0, "fatal error, exiting");
0118 _exit(errno);
0119 }
0120 if (error_flag & RTEMS_ERROR_ABORT) {
0121 rtems_error(0, "fatal error, aborting");
0122 abort();
0123 }
0124
0125 return chars_written;
0126 }