libjf API reference guide

Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

jf_crash_simul.c

Go to the documentation of this file.
00001 /* 00002 * Copyright 2005 Tiian 00003 * {In real life Tiian is Christian Ferrari} 00004 * This file is part of "libjf" package. 00005 * 00006 * "libjf" is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2.1 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * "libjf" is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with ; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 */ 00020 #include <jf/jf_config.h> 00021 00022 00023 00024 #ifdef HAVE_STDIO_H 00025 # include <stdio.h> 00026 #endif /* HAVE_STDIO_H */ 00027 #ifdef HAVE_STDLIB_H 00028 # include <stdlib.h> 00029 #endif /* HAVE_STDLIB_H */ 00030 #ifdef HAVE_STRING_H 00031 # include <string.h> 00032 #endif /* HAVE_STRING_H */ 00033 00034 #include <jf/jf_errors.h> 00035 #include <jf/jf_crash_simul.h> 00036 00037 00038 00039 /* set module trace flag */ 00040 #ifdef JF_TRACE_MODULE 00041 # undef JF_TRACE_MODULE 00042 #endif /* JF_TRACE_MODULE */ 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 /* NOTE: critical operation, possibly dangerous */ 00090 jf_crash_simul_count++; 00091 JF_TRACE(("jf_crash_simul: count is %ld/%ld\n", 00092 jf_crash_simul_count, count)); 00093 /* abort program if crash simulation has to be performed */ 00094 if (jf_crash_simul_count == count) { 00095 JF_TRACE(("jf_crash_simul: count completed, " 00096 "ABORTING program!\n")); 00097 abort(); 00098 } /* if (count == 0) */ 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 } /* switch (excp) */ 00120 } /* TRY-CATCH */ 00121 JF_TRACE(("jf_crash_simul/excp=%d/ret_cod=%d/errno=%d\n", 00122 excp, ret_cod, errno)); 00123 return; 00124 } 00125 #endif /* _CRASH_SIMUL */

Copyright 2005 © Tiian