00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef lint
00041 static const char RCSbomb[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/libbu/bomb.c,v 14.12 2006/08/31 05:50:24 lbutler Exp $ (ARL)";
00042 #endif
00043
00044 #include "common.h"
00045
00046 #include <stdlib.h>
00047 #include <stdio.h>
00048 #include <ctype.h>
00049 #ifdef HAVE_UNISTD_H
00050 # include <unistd.h>
00051 #endif
00052 #ifdef HAVE_STRING_H
00053 # include <string.h>
00054 #endif
00055 #ifdef HAVE_UNIX_IO
00056 # include <fcntl.h>
00057 #endif
00058
00059 #include "machine.h"
00060 #include "bu.h"
00061
00062 #if 1
00063 struct bu_hook_list bu_bomb_hook_list = {
00064 { BU_LIST_HEAD_MAGIC,
00065 &bu_bomb_hook_list.l,
00066 &bu_bomb_hook_list.l
00067 },
00068 BUHOOK_NULL,
00069 GENPTR_NULL
00070 };
00071 #else
00072 struct bu_hook_list bu_bomb_hook_list;
00073 #endif
00074
00075
00076
00077
00078
00079
00080 int bu_setjmp_valid = 0;
00081 jmp_buf bu_jmpbuf;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 void
00093 bu_bomb(const char *str)
00094 {
00095
00096
00097
00098
00099
00100 fprintf(stderr, "\n");
00101 fprintf(stderr, str);
00102 fprintf(stderr, "\n");
00103 fflush(stderr);
00104
00105
00106 if (BU_LIST_NON_EMPTY(&bu_bomb_hook_list.l)) {
00107 bu_call_hook(&bu_bomb_hook_list, (genptr_t)str);
00108 }
00109
00110 if( bu_setjmp_valid ) {
00111
00112 if( bu_is_parallel() ) {
00113 fprintf(stderr,"bu_bomb(): in parallel mode, could not longjmp up to application handler\n");
00114 } else {
00115
00116 fprintf(stderr,"bu_bomb(): taking longjmp up to application handler\n");
00117 #if __STDC__
00118 longjmp( (void *)(bu_jmpbuf), 1 );
00119 #else
00120 longjmp( (int *)(bu_jmpbuf), 1 );
00121 #endif
00122
00123 }
00124 }
00125
00126 #if defined(HAVE_UNIX_IO)
00127
00128
00129
00130
00131
00132 {
00133 int fd = open("/dev/tty", 1);
00134 if( fd >= 0 ) {
00135 write( fd, str, strlen(str) );
00136 close(fd);
00137 }
00138 }
00139 #endif
00140
00141
00142 bu_kill_parallel();
00143
00144 if( bu_debug & BU_DEBUG_COREDUMP ) {
00145 fprintf(stderr,"bu_bomb causing intentional core dump due to debug flag\n");
00146 fflush(stdout);
00147 fflush(stderr);
00148 abort();
00149 }
00150
00151 exit(12);
00152 }
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162