00001
00002
00003
00004
00005
00006
00007
00008 #include "config.h"
00009
00010 #ifndef lint
00011 static const char revid[] = "$Id: db__err_8c-source.html,v 1.1 2008/06/08 10:17:27 sebdiaz Exp $";
00012 #endif
00013
00014 #ifndef NO_SYSTEM_INCLUDES
00015 #include <sys/types.h>
00016
00017 #include <errno.h>
00018 #include <stdio.h>
00019 #include <stdlib.h>
00020 #include <string.h>
00021 #endif
00022
00023 #include "db_int.h"
00024 #include "db_shash.h"
00025 #include "lock.h"
00026 #include "lock_ext.h"
00027 #include "log.h"
00028 #include "log_ext.h"
00029 #include "mp.h"
00030 #include "mp_ext.h"
00031 #include "txn.h"
00032 #include "txn_ext.h"
00033 #include "common_ext.h"
00034 #include "db_auto.h"
00035
00036 static void __db_errcall __P((const DB_ENV *, int, int, const char *, va_list));
00037 static void __db_errfile __P((const DB_ENV *, int, int, const char *, va_list));
00038
00039
00040
00041
00042
00043
00044
00045 int
00046 CDB___db_fchk(dbenv, name, flags, ok_flags)
00047 DB_ENV *dbenv;
00048 const char *name;
00049 u_int32_t flags, ok_flags;
00050 {
00051 return (LF_ISSET(~ok_flags) ? CDB___db_ferr(dbenv, name, 0) : 0);
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061 int
00062 CDB___db_fcchk(dbenv, name, flags, flag1, flag2)
00063 DB_ENV *dbenv;
00064 const char *name;
00065 u_int32_t flags, flag1, flag2;
00066 {
00067 return (LF_ISSET(flag1) &&
00068 LF_ISSET(flag2) ? CDB___db_ferr(dbenv, name, 1) : 0);
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 int
00078 CDB___db_ferr(dbenv, name, iscombo)
00079 const DB_ENV *dbenv;
00080 const char *name;
00081 int iscombo;
00082 {
00083 CDB___db_err(dbenv, "illegal flag %sspecified to %s",
00084 iscombo ? "combination " : "", name);
00085 return (EINVAL);
00086 }
00087
00088
00089
00090
00091
00092
00093
00094 int
00095 CDB___db_pgerr(dbp, pgno)
00096 DB *dbp;
00097 db_pgno_t pgno;
00098 {
00099
00100
00101
00102
00103
00104 CDB___db_err(dbp->dbenv,
00105 "unable to create/retrieve page %lu", (u_long)pgno);
00106 return (CDB___db_panic(dbp->dbenv, EIO));
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 int
00116 CDB___db_pgfmt(dbp, pgno)
00117 DB *dbp;
00118 db_pgno_t pgno;
00119 {
00120 CDB___db_err(dbp->dbenv,
00121 "page %lu: illegal page type or format", (u_long)pgno);
00122 return (CDB___db_panic(dbp->dbenv, EINVAL));
00123 }
00124
00125
00126
00127
00128
00129
00130
00131 int
00132 CDB___db_eopnotsup(dbenv)
00133 const DB_ENV *dbenv;
00134 {
00135 CDB___db_err(dbenv, "operation not supported");
00136 #ifdef EOPNOTSUPP
00137 return (EOPNOTSUPP);
00138 #else
00139 return (EINVAL);
00140 #endif
00141 }
00142
00143 #ifdef DIAGNOSTIC
00144
00145
00146
00147
00148
00149
00150
00151
00152 void
00153 __db_assert(failedexpr, file, line)
00154 const char *failedexpr, *file;
00155 int line;
00156 {
00157 (void)fprintf(stderr,
00158 "__db_assert: \"%s\" failed: file \"%s\", line %d\n",
00159 failedexpr, file, line);
00160 fflush(stderr);
00161
00162
00163 abort();
00164
00165
00166 }
00167 #endif
00168
00169
00170
00171
00172
00173
00174
00175 int
00176 CDB___db_panic_msg(dbenv)
00177 DB_ENV *dbenv;
00178 {
00179 CDB___db_err(dbenv, "region error detected; run recovery.");
00180 return (DB_RUNRECOVERY);
00181 }
00182
00183
00184
00185
00186
00187
00188
00189 int
00190 CDB___db_panic(dbenv, errval)
00191 DB_ENV *dbenv;
00192 int errval;
00193 {
00194
00195
00196
00197
00198
00199 DB_ASSERT(0);
00200
00201 if (dbenv != NULL) {
00202 ((REGENV *)((REGINFO *)dbenv->reginfo)->addr)->panic = 1;
00203
00204 dbenv->db_panic = errval;
00205
00206 CDB___db_err(dbenv, "PANIC: %s", CDB_db_strerror(errval));
00207
00208 if (dbenv->db_paniccall != NULL)
00209 dbenv->db_paniccall(dbenv, errval);
00210 }
00211
00212
00213
00214
00215
00216
00217 return (DB_RUNRECOVERY);
00218 }
00219
00220
00221
00222
00223
00224 char *
00225 CDB_db_strerror(error)
00226 int error;
00227 {
00228 if (error == 0)
00229 return ("Successful return: 0");
00230 if (error > 0)
00231 return (strerror(error));
00232
00233
00234
00235
00236
00237
00238
00239
00240 switch (error) {
00241 case DB_INCOMPLETE:
00242 return ("DB_INCOMPLETE: Cache flush was unable to complete");
00243 case DB_KEYEMPTY:
00244 return ("DB_KEYEMPTY: Non-existent key/data pair");
00245 case DB_KEYEXIST:
00246 return ("DB_KEYEXIST: Key/data pair already exists");
00247 case DB_LOCK_DEADLOCK:
00248 return
00249 ("DB_LOCK_DEADLOCK: Locker killed to resolve a deadlock");
00250 case DB_LOCK_NOTGRANTED:
00251 return ("DB_LOCK_NOTGRANTED: Lock not granted");
00252 case DB_NOSERVER:
00253 return ("DB_NOSERVER: Fatal error, no server");
00254 case DB_NOSERVER_HOME:
00255 return ("DB_NOSERVER_HOME: Home unrecognized at server");
00256 case DB_NOSERVER_ID:
00257 return ("DB_NOSERVER_ID: Identifier unrecognized at server");
00258 case DB_NOTFOUND:
00259 return ("DB_NOTFOUND: No matching key/data pair found");
00260 case DB_OLD_VERSION:
00261 return ("DB_OLDVERSION: Database requires a version upgrade");
00262 case DB_RUNRECOVERY:
00263 return ("DB_RUNRECOVERY: Fatal error, run database recovery");
00264 case DB_VERIFY_BAD:
00265 return ("DB_VERIFY_BAD: Database verification failed");
00266 default: {
00267
00268
00269
00270
00271
00272
00273 static char ebuf[40];
00274
00275 (void)snprintf(ebuf, sizeof(ebuf), "Unknown error: %d", error);
00276 return(ebuf);
00277 }
00278 }
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 void
00293 #ifdef __STDC__
00294 CDB___db_err(const DB_ENV *dbenv, const char *fmt, ...)
00295 #else
00296 CDB___db_err(dbenv, fmt, va_alist)
00297 const DB_ENV *dbenv;
00298 const char *fmt;
00299 va_dcl
00300 #endif
00301 {
00302 va_list ap;
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 #ifdef __STDC__
00332 va_start(ap, fmt);
00333 #else
00334 va_start(ap);
00335 #endif
00336 CDB___db_real_err(dbenv, 0, 0, 0, fmt, ap);
00337
00338 va_end(ap);
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348 void
00349 CDB___db_real_err(dbenv, error, error_set, stderr_default, fmt, ap)
00350 const DB_ENV *dbenv;
00351 int error, error_set, stderr_default;
00352 const char *fmt;
00353 va_list ap;
00354 {
00355 if (dbenv != NULL && dbenv->db_errcall != NULL)
00356 __db_errcall(dbenv, error, error_set, fmt, ap);
00357
00358 if (dbenv != NULL && dbenv->db_errfile != NULL)
00359 __db_errfile(dbenv, error, error_set, fmt, ap);
00360
00361 if (stderr_default && (dbenv == NULL ||
00362 (dbenv->db_errcall == NULL && dbenv->db_errfile == NULL)))
00363 __db_errfile(NULL, error, error_set, fmt, ap);
00364 }
00365
00366
00367
00368
00369
00370 static void
00371 __db_errcall(dbenv, error, error_set, fmt, ap)
00372 const DB_ENV *dbenv;
00373 int error, error_set;
00374 const char *fmt;
00375 va_list ap;
00376 {
00377 char *p;
00378 char __errbuf[2048];
00379
00380 p = __errbuf;
00381 if (fmt != NULL) {
00382 p += vsnprintf(__errbuf, sizeof(__errbuf), fmt, ap);
00383 if (error_set) {
00384 *p++ = ':';
00385 *p++ = ' ';
00386 }
00387 }
00388 if (error_set)
00389 (void)strcpy(p, CDB_db_strerror(error));
00390
00391 dbenv->db_errcall(dbenv->db_errpfx, __errbuf);
00392 }
00393
00394
00395
00396
00397
00398 static void
00399 __db_errfile(dbenv, error, error_set, fmt, ap)
00400 const DB_ENV *dbenv;
00401 int error, error_set;
00402 const char *fmt;
00403 va_list ap;
00404 {
00405 FILE *fp;
00406
00407 fp = dbenv == NULL ||
00408 dbenv->db_errfile == NULL ? stderr : dbenv->db_errfile;
00409
00410 if (dbenv != NULL && dbenv->db_errpfx != NULL)
00411 (void)fprintf(fp, "%s: ", dbenv->db_errpfx);
00412 if (fmt != NULL) {
00413 (void)vfprintf(fp, fmt, ap);
00414 if (error_set)
00415 (void)fprintf(fp, ": ");
00416 }
00417 if (error_set)
00418 (void)fprintf(fp, "%s", CDB_db_strerror(error));
00419 (void)fprintf(fp, "\n");
00420 (void)fflush(fp);
00421 }
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434 void
00435 #ifdef __STDC__
00436 CDB___db_logmsg(const DB_ENV *dbenv,
00437 DB_TXN *txnid, const char *opname, u_int32_t flags, const char *fmt, ...)
00438 #else
00439 CDB___db_logmsg(dbenv, txnid, opname, flags, fmt, va_alist)
00440 const DB_ENV *dbenv;
00441 DB_TXN *txnid;
00442 const char *opname, *fmt;
00443 u_int32_t flags;
00444 va_dcl
00445 #endif
00446 {
00447 va_list ap;
00448
00449 #ifdef __STDC__
00450 va_start(ap, fmt);
00451 #else
00452 va_start(ap);
00453 #endif
00454 CDB___db_real_log(dbenv, txnid, opname, flags, fmt, ap);
00455
00456 va_end(ap);
00457 }
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 void
00471 #ifdef __STDC__
00472 CDB___db_real_log(const DB_ENV *dbenv, DB_TXN *txnid,
00473 const char *opname, u_int32_t flags, const char *fmt, va_list ap)
00474 #else
00475 CDB___db_real_log(dbenv, txnid, opname, flags, fmt, ap)
00476 const DB_ENV *dbenv;
00477 DB_TXN *txnid;
00478 const char *opname, *fmt;
00479 u_int32_t flags;
00480 va_list ap;
00481 #endif
00482 {
00483 DBT opdbt, msgdbt;
00484 DB_LSN lsn;
00485 char __logbuf[2048];
00486
00487 if (!LOGGING_ON(dbenv))
00488 return;
00489
00490 memset(&opdbt, 0, sizeof(opdbt));
00491 opdbt.data = (void *)opname;
00492 opdbt.size = strlen(opname) + 1;
00493
00494 memset(&msgdbt, 0, sizeof(msgdbt));
00495 msgdbt.data = __logbuf;
00496 msgdbt.size = vsnprintf(__logbuf, sizeof(__logbuf), fmt, ap);
00497
00498
00499
00500
00501
00502
00503 CDB___db_debug_log(
00504 (DB_ENV *)dbenv, txnid, &lsn, flags, &opdbt, -1, &msgdbt, NULL, 0);
00505 }
00506
00507
00508
00509
00510
00511
00512 int
00513 CDB___db_unknown_flag(dbenv, routine, flag)
00514 DB_ENV *dbenv;
00515 char *routine;
00516 u_int32_t flag;
00517 {
00518 CDB___db_err(dbenv, "%s: Unknown flag: 0x%x", routine, flag);
00519 DB_ASSERT(0);
00520 return (EINVAL);
00521 }
00522
00523
00524
00525
00526
00527
00528 int
00529 CDB___db_unknown_type(dbenv, routine, type)
00530 DB_ENV *dbenv;
00531 char *routine;
00532 u_int32_t type;
00533 {
00534 CDB___db_err(dbenv, "%s: Unknown db type: 0x%x", routine, type);
00535 DB_ASSERT(0);
00536 return (EINVAL);
00537 }
00538
00539
00540
00541
00542
00543
00544 int
00545 CDB___db_child_active_err(dbenv)
00546 DB_ENV *dbenv;
00547 {
00548 CDB___db_err(dbenv, "Child transaction is active");
00549 return (EPERM);
00550 }