00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include <jf/jf_config.h>
00021
00022
00023
00024
#ifdef HAVE_STDIO_H
00025
# include <stdio.h>
00026
#endif
00027
#ifdef HAVE_STDLIB_H
00028
# include <stdlib.h>
00029
#endif
00030
#ifdef HAVE_STRING_H
00031
# include <string.h>
00032
#endif
00033
00034
#include <jf/jf_errors.h>
00035
#include <jf/jf_crash_simul.h>
00036
00037
00038
00039
00040
#ifdef JF_TRACE_MODULE
00041
# undef JF_TRACE_MODULE
00042
#endif
00043 #define JF_TRACE_MODULE JF_TRACE_MOD_LIB_CRASH_SIMUL
00044
00045
00046
00047
#ifdef _CRASH_SIMUL
00048
00054
static long jf_crash_simul_count = 0;
00055
00056
00057
00058
void jf_crash_simul(
const char *crash_type)
00059 {
00060
enum Exception { NULL_SIMUL_POINT
00061 , DIFFERENT_POINT
00062 , NULL_SIMUL_COUNT
00063 , NON_POSITIVE_COUNT
00064 , NONE } excp;
00065
int ret_cod =
JF_RC_INTERNAL_ERROR;
00066
00067
JF_TRACE((
"jf_crash_simul: crash_type = '%s'\n", crash_type));
00068 TRY {
00069
char *simul_point, *simul_count;
00070
long count = 0;
00071
00072 simul_point = getenv(
JF_CRASH_SIMUL_POINT_ENV_VAR);
00073
if (simul_point == NULL)
00074
THROW(NULL_SIMUL_POINT);
00075
JF_TRACE((
"jf_crash_simul: %s content is '%s'\n",
00076
JF_CRASH_SIMUL_POINT_ENV_VAR, simul_point));
00077
if (strcmp(simul_point, crash_type) != 0)
00078
THROW(DIFFERENT_POINT);
00079
00080 simul_count = getenv(
JF_CRASH_SIMUL_COUNT_ENV_VAR);
00081
if (simul_count == NULL)
00082
THROW(NULL_SIMUL_COUNT);
00083
JF_TRACE((
"jf_crash_simul: %s content is '%s'\n",
00084
JF_CRASH_SIMUL_COUNT_ENV_VAR, simul_count));
00085 count = strtol(simul_count, NULL, 10);
00086
if (count <= 0)
00087
THROW(NON_POSITIVE_COUNT);
00088
00089
00090 jf_crash_simul_count++;
00091
JF_TRACE((
"jf_crash_simul: count is %ld/%ld\n",
00092 jf_crash_simul_count, count));
00093
00094
if (jf_crash_simul_count == count) {
00095
JF_TRACE((
"jf_crash_simul: count completed, "
00096
"ABORTING program!\n"));
00097 abort();
00098 }
00099
THROW(NONE);
00100 }
CATCH {
00101
switch (excp) {
00102
case NULL_SIMUL_POINT:
00103 ret_cod =
JF_RC_OBJ_NOT_FOUND;
00104
break;
00105
case DIFFERENT_POINT:
00106 ret_cod =
JF_RC_OK;
00107
break;
00108
case NULL_SIMUL_COUNT:
00109 ret_cod =
JF_RC_OBJ_NOT_FOUND;
00110
break;
00111
case NON_POSITIVE_COUNT:
00112 ret_cod =
JF_RC_OUT_OF_RANGE;
00113
break;
00114
case NONE:
00115 ret_cod =
JF_RC_OK;
00116
break;
00117
default:
00118 ret_cod =
JF_RC_INTERNAL_ERROR;
00119 }
00120 }
00121
JF_TRACE((
"jf_crash_simul/excp=%d/ret_cod=%d/errno=%d\n",
00122 excp, ret_cod, errno));
00123
return;
00124 }
00125
#endif