1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/*-
* See the file LICENSE for redistribution information.
*
* Copyright (c) 2008-2011 WiredTiger, Inc.
* All rights reserved.
*/
#include "wt_internal.h"
/*
* __wt_msg_call --
* Pass a message to a callback function.
*/
void
__wt_msgv(SESSION *session, const char *prefix1, const char *prefix2,
const char *fmt, va_list ap)
{
WT_EVENT_HANDLER *handler;
char *end, *p;
/*
* !!!
* SECURITY:
* Buffer placed at the end of the stack in case snprintf overflows.
*/
char s[2048];
p = s;
end = s + sizeof(s);
if (prefix1 != NULL && prefix2 != NULL && p < end)
p += snprintf(p, (size_t)(end - p),
"%s [%s]: ", prefix1, prefix2);
else if (prefix1 != NULL && p < end)
p += snprintf(p, (size_t)(end - p), "%s: ", prefix1);
else if (prefix2 != NULL && p < end)
p += snprintf(p, (size_t)(end - p), "%s: ", prefix2);
if (p < end)
p += vsnprintf(p, (size_t)(end - p), fmt, ap);
handler = session->event_handler;
(void)handler->handle_message(handler, s);
}
/*
* __wt_msg --
* Report a message.
*/
void
__wt_msg(SESSION *session, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
__wt_msgv(session,
(session->btree != NULL) ? session->btree->name : NULL,
session->name, fmt, ap);
va_end(ap);
}
#ifdef HAVE_DIAGNOSTIC
/*
* __wt_assert --
* Internal version of assert function.
*/
void
__wt_assert(
SESSION *session, const char *check, const char *file_name, int line_number)
{
__wt_errx(session,
"assertion failure: %s/%d: \"%s\"", file_name, line_number, check);
__wt_abort(session);
/* NOTREACHED */
}
#endif
/*
* __wt_api_args --
* Print a standard error message when an API function is passed illegal
* arguments.
*/
int
__wt_api_args(SESSION *session)
{
__wt_errx(session, "illegal API arguments or flag values specified");
return (WT_ERROR);
}
/*
* __wt_api_arg_min --
* Print a standard error message when an API function is passed a
* too-small argument.
*/
int
__wt_api_arg_min(SESSION *session, const char *arg_name,
uint64_t v, uint64_t min)
{
if (v >= min)
return (0);
__wt_errx(session, "%s argument %llu less than minimum value of %llu",
arg_name, (unsigned long long)v, (unsigned long long)min);
return (WT_ERROR);
}
/*
* __wt_api_arg_max --
* Print a standard error message when an API function is passed a
* too-large argument.
*/
int
__wt_api_arg_max(SESSION *session, const char *arg_name,
uint64_t v, uint64_t max)
{
if (v <= max)
return (0);
__wt_errx(session, "%s argument %llu larger than maximum value of %llu",
arg_name, (unsigned long long)v, (unsigned long long)max);
return (WT_ERROR);
}
/*
* __wt_file_method_type --
* Print a standard error message on attempts to call methods inappropriate
* for a file type.
*/
int
__wt_file_method_type(SESSION *session, int column_err)
{
__wt_errx(session,
"this method is not supported for a %s file",
column_err ? "column-store" : "row-store");
return (WT_ERROR);
}
/*
* __wt_file_wrong_fixed_size --
* Print a standard error message on attempts to put the wrong size element
* into a fixed-size file.
*/
int
__wt_file_wrong_fixed_size(SESSION *session, uint32_t len, uint32_t config_len)
{
__wt_errx(session,
"%s: length of %lu does not match fixed-length file configuration "
"of %lu",
session->name, (u_long)len, (u_long)config_len);
return (WT_ERROR);
}
/*
* __wt_file_readonly --
* Print a standard error message on attempts to modify a read-only file.
*/
int
__wt_file_readonly(SESSION *session)
{
__wt_errx(session,
"the file was opened read-only and may not be modified");
return (WT_READONLY);
}
/*
* __wt_file_format --
* Print a standard error message when a file format error is suddenly
* discovered.
*/
int
__wt_file_format(SESSION *session)
{
__wt_errx(session, "the file is corrupted; use the Db.salvage"
" method or the db_salvage utility to repair the file");
return (WT_ERROR);
}
/*
* __wt_file_item_too_big --
* Print a standard error message when an element is too large to store.
*/
int
__wt_file_item_too_big(SESSION *session)
{
__wt_errx(session, "the item is too large for the file to store");
return (WT_ERROR);
}
/*
* __wt_session_lockout --
* Standard SESSION handle lockout error message.
*/
int
__wt_session_lockout(SESSION *session)
{
__wt_errx(session,
"An unavailable handle method was called; the handle method is "
"not available for some reason, for example, handle methods are "
"restricted after an error, or configuration methods may be "
"restricted after the file or environment have been opened, "
"or operational methods may be restricted until the file or "
"environment has been opened.");
return (WT_ERROR);
}
/*
* __wt_btree_lockout --
* Standard BTREE handle lockout error message.
*/
int
__wt_btree_lockout(BTREE *btree)
{
return (__wt_connection_lockout(btree->conn));
}
/*
* __wt_connection_lockout --
* Standard CONNECTION handle lockout error message.
*/
int
__wt_connection_lockout(CONNECTION *conn)
{
return (__wt_session_lockout(&conn->default_session));
}
/*
* __wt_errv --
* Report an error (va_list version).
*/
void
__wt_errv(SESSION *session, int error,
const char *prefix1, const char *prefix2, const char *fmt, va_list ap)
{
WT_EVENT_HANDLER *handler;
char *end, *p;
/*
* !!!
* SECURITY:
* Buffer placed at the end of the stack in case snprintf overflows.
*/
char s[2048];
p = s;
end = s + sizeof(s);
if (prefix1 != NULL && prefix2 != NULL && p < end)
p += snprintf(p, (size_t)(end - p),
"%s [%s]: ", prefix1, prefix2);
else if (prefix1 != NULL && p < end)
p += snprintf(p, (size_t)(end - p), "%s: ", prefix1);
else if (prefix2 != NULL && p < end)
p += snprintf(p, (size_t)(end - p), "%s: ", prefix2);
if (p < end)
p += vsnprintf(p, (size_t)(end - p), fmt, ap);
if (error != 0 && p < end)
p += snprintf(p,
(size_t)(end - p), ": %s", wiredtiger_strerror(error));
handler = session->event_handler;
handler->handle_error(handler, error, s);
}
/*
* __wt_err --
* Report an error.
*/
void
__wt_err(SESSION *session, int error, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
__wt_errv(session, error,
(session->btree != NULL) ? session->btree->name : NULL,
session->name,
fmt, ap);
va_end(ap);
}
/*
* __wt_errx --
* Report an error with no error code.
*/
void
__wt_errx(SESSION *session, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
__wt_errv(session, 0,
(session->btree != NULL) ? session->btree->name : NULL,
session->name,
fmt, ap);
va_end(ap);
}
|