243.1.17
by Jay Pipes
FINAL PHASE removal of mysql_priv.h (Bye, bye my friend.) |
1 |
/* Copyright (C) 2000-2003 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
#ifndef ERROR_INJECT_SUPPORT
|
|
17 |
/**
|
|
18 |
* @file
|
|
19 |
*
|
|
20 |
* Simple compile-time error injection module to enable easy
|
|
21 |
* error printing in case of a crash
|
|
22 |
*/
|
|
23 |
#ifndef DRIZZLE_SERVER_ERROR_INJECTION_H
|
|
24 |
#define DRIZZLE_SERVER_ERROR_INJECTION_H
|
|
25 |
||
26 |
/*
|
|
27 |
Error injector Macros to enable easy testing of recovery after failures
|
|
28 |
in various error cases.
|
|
29 |
*/
|
|
30 |
#define ERROR_INJECT(x) 0
|
|
31 |
#define ERROR_INJECT_ACTION(x,action) 0
|
|
32 |
#define ERROR_INJECT_CRASH(x) 0
|
|
33 |
#define ERROR_INJECT_VALUE(x) 0
|
|
34 |
#define ERROR_INJECT_VALUE_ACTION(x,action) 0
|
|
35 |
#define ERROR_INJECT_VALUE_CRASH(x) 0
|
|
36 |
#define SET_ERROR_INJECT_VALUE(x)
|
|
37 |
||
38 |
#else
|
|
39 |
||
40 |
inline bool check_and_unset_keyword(const char *dbug_str) |
|
41 |
{
|
|
42 |
const char *extra_str= "-d,"; |
|
43 |
char total_str[200]; |
|
44 |
if (_db_strict_keyword_ (dbug_str)) |
|
45 |
{
|
|
46 |
strxmov(total_str, extra_str, dbug_str, NullS); |
|
47 |
return 1; |
|
48 |
}
|
|
49 |
return 0; |
|
50 |
}
|
|
51 |
||
52 |
||
53 |
inline bool |
|
54 |
check_and_unset_inject_value(int value) |
|
55 |
{
|
|
56 |
THD *thd= current_thd; |
|
57 |
if (thd->error_inject_value == (uint)value) |
|
58 |
{
|
|
59 |
thd->error_inject_value= 0; |
|
60 |
return 1; |
|
61 |
}
|
|
62 |
return 0; |
|
63 |
}
|
|
64 |
||
65 |
/*
|
|
66 |
ERROR INJECT MODULE:
|
|
67 |
--------------------
|
|
68 |
These macros are used to insert macros from the application code.
|
|
69 |
The event that activates those error injections can be activated
|
|
70 |
from SQL by using:
|
|
71 |
SET SESSION dbug=+d,code;
|
|
72 |
||
73 |
After the error has been injected, the macros will automatically
|
|
74 |
remove the debug code, thus similar to using:
|
|
75 |
SET SESSION dbug=-d,code
|
|
76 |
from SQL.
|
|
77 |
||
78 |
ERROR_INJECT_CRASH will inject a crash of the MySQL Server if code
|
|
79 |
is set when macro is called. ERROR_INJECT_CRASH can be used in
|
|
80 |
if-statements, it will always return false unless of course it
|
|
81 |
crashes in which case it doesn't return at all.
|
|
82 |
||
83 |
ERROR_INJECT_ACTION will inject the action specified in the action
|
|
84 |
parameter of the macro, before performing the action the code will
|
|
85 |
be removed such that no more events occur. ERROR_INJECT_ACTION
|
|
86 |
can also be used in if-statements and always returns FALSE.
|
|
87 |
ERROR_INJECT can be used in a normal if-statement, where the action
|
|
88 |
part is performed in the if-block. The macro returns TRUE if the
|
|
89 |
error was activated and otherwise returns FALSE. If activated the
|
|
90 |
code is removed.
|
|
91 |
||
92 |
Sometimes it is necessary to perform error inject actions as a serie
|
|
93 |
of events. In this case one can use one variable on the THD object.
|
|
94 |
Thus one sets this value by using e.g. SET_ERROR_INJECT_VALUE(100).
|
|
95 |
Then one can later test for it by using ERROR_INJECT_CRASH_VALUE,
|
|
96 |
ERROR_INJECT_ACTION_VALUE and ERROR_INJECT_VALUE. This have the same
|
|
97 |
behaviour as the above described macros except that they use the
|
|
98 |
error inject value instead of a code used by debug macros.
|
|
99 |
*/
|
|
100 |
#define SET_ERROR_INJECT_VALUE(x) \
|
|
101 |
current_thd->error_inject_value= (x)
|
|
102 |
#define ERROR_INJECT_ACTION(code, action) \
|
|
103 |
(check_and_unset_keyword(code) ? ((action), 0) : 0)
|
|
104 |
#define ERROR_INJECT(code) \
|
|
105 |
check_and_unset_keyword(code)
|
|
106 |
#define ERROR_INJECT_VALUE(value) \
|
|
107 |
check_and_unset_inject_value(value)
|
|
108 |
#define ERROR_INJECT_VALUE_ACTION(value,action) \
|
|
109 |
(check_and_unset_inject_value(value) ? (action) : 0)
|
|
110 |
#define ERROR_INJECT_VALUE_CRASH(value) \
|
|
111 |
ERROR_INJECT_VALUE_ACTION(value, (abort(), 0))
|
|
112 |
||
113 |
#endif /* DRIZZLE_SERVER_ERROR_INJECTION_H */ |
|
114 |
#endif /* ERROR_INJECT_SUPPORT */ |