xref: /titanic_41/usr/src/cmd/sendmail/db/db/db_err.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*-
2*7c478bd9Sstevel@tonic-gate  * See the file LICENSE for redistribution information.
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1996, 1997, 1998
5*7c478bd9Sstevel@tonic-gate  *	Sleepycat Software.  All rights reserved.
6*7c478bd9Sstevel@tonic-gate  */
7*7c478bd9Sstevel@tonic-gate 
8*7c478bd9Sstevel@tonic-gate #include "config.h"
9*7c478bd9Sstevel@tonic-gate 
10*7c478bd9Sstevel@tonic-gate #ifndef lint
11*7c478bd9Sstevel@tonic-gate static const char sccsid[] = "@(#)db_err.c	10.42 (Sleepycat) 11/24/98";
12*7c478bd9Sstevel@tonic-gate #endif /* not lint */
13*7c478bd9Sstevel@tonic-gate 
14*7c478bd9Sstevel@tonic-gate #ifndef NO_SYSTEM_INCLUDES
15*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <errno.h>
18*7c478bd9Sstevel@tonic-gate #include <stdio.h>
19*7c478bd9Sstevel@tonic-gate #include <string.h>
20*7c478bd9Sstevel@tonic-gate 
21*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
22*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
23*7c478bd9Sstevel@tonic-gate #else
24*7c478bd9Sstevel@tonic-gate #include <varargs.h>
25*7c478bd9Sstevel@tonic-gate #endif
26*7c478bd9Sstevel@tonic-gate #endif
27*7c478bd9Sstevel@tonic-gate 
28*7c478bd9Sstevel@tonic-gate #include "db_int.h"
29*7c478bd9Sstevel@tonic-gate #include "shqueue.h"
30*7c478bd9Sstevel@tonic-gate #include "db_shash.h"
31*7c478bd9Sstevel@tonic-gate #include "lock.h"
32*7c478bd9Sstevel@tonic-gate #include "lock_ext.h"
33*7c478bd9Sstevel@tonic-gate #include "log.h"
34*7c478bd9Sstevel@tonic-gate #include "log_ext.h"
35*7c478bd9Sstevel@tonic-gate #include "mp.h"
36*7c478bd9Sstevel@tonic-gate #include "mp_ext.h"
37*7c478bd9Sstevel@tonic-gate #include "txn.h"
38*7c478bd9Sstevel@tonic-gate #include "txn_ext.h"
39*7c478bd9Sstevel@tonic-gate #include "common_ext.h"
40*7c478bd9Sstevel@tonic-gate #include "clib_ext.h"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * __db_fchk --
44*7c478bd9Sstevel@tonic-gate  *	General flags checking routine.
45*7c478bd9Sstevel@tonic-gate  *
46*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_fchk __P((DB_ENV *, const char *, u_int32_t, u_int32_t));
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate int
__db_fchk(dbenv,name,flags,ok_flags)49*7c478bd9Sstevel@tonic-gate __db_fchk(dbenv, name, flags, ok_flags)
50*7c478bd9Sstevel@tonic-gate 	DB_ENV *dbenv;
51*7c478bd9Sstevel@tonic-gate 	const char *name;
52*7c478bd9Sstevel@tonic-gate 	u_int32_t flags, ok_flags;
53*7c478bd9Sstevel@tonic-gate {
54*7c478bd9Sstevel@tonic-gate 	return (flags & ~ok_flags ?  __db_ferr(dbenv, name, 0) : 0);
55*7c478bd9Sstevel@tonic-gate }
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate /*
58*7c478bd9Sstevel@tonic-gate  * __db_fcchk --
59*7c478bd9Sstevel@tonic-gate  *	General combination flags checking routine.
60*7c478bd9Sstevel@tonic-gate  *
61*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_fcchk
62*7c478bd9Sstevel@tonic-gate  * PUBLIC:    __P((DB_ENV *, const char *, u_int32_t, u_int32_t, u_int32_t));
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate int
__db_fcchk(dbenv,name,flags,flag1,flag2)65*7c478bd9Sstevel@tonic-gate __db_fcchk(dbenv, name, flags, flag1, flag2)
66*7c478bd9Sstevel@tonic-gate 	DB_ENV *dbenv;
67*7c478bd9Sstevel@tonic-gate 	const char *name;
68*7c478bd9Sstevel@tonic-gate 	u_int32_t flags, flag1, flag2;
69*7c478bd9Sstevel@tonic-gate {
70*7c478bd9Sstevel@tonic-gate 	return ((flags & flag1) &&
71*7c478bd9Sstevel@tonic-gate 	    (flags & flag2) ?  __db_ferr(dbenv, name, 1) : 0);
72*7c478bd9Sstevel@tonic-gate }
73*7c478bd9Sstevel@tonic-gate 
74*7c478bd9Sstevel@tonic-gate /*
75*7c478bd9Sstevel@tonic-gate  * __db_ferr --
76*7c478bd9Sstevel@tonic-gate  *	Common flag errors.
77*7c478bd9Sstevel@tonic-gate  *
78*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_ferr __P((const DB_ENV *, const char *, int));
79*7c478bd9Sstevel@tonic-gate  */
80*7c478bd9Sstevel@tonic-gate int
__db_ferr(dbenv,name,iscombo)81*7c478bd9Sstevel@tonic-gate __db_ferr(dbenv, name, iscombo)
82*7c478bd9Sstevel@tonic-gate 	const DB_ENV *dbenv;
83*7c478bd9Sstevel@tonic-gate 	const char *name;
84*7c478bd9Sstevel@tonic-gate 	int iscombo;
85*7c478bd9Sstevel@tonic-gate {
86*7c478bd9Sstevel@tonic-gate 	__db_err(dbenv, "illegal flag %sspecified to %s",
87*7c478bd9Sstevel@tonic-gate 	    iscombo ? "combination " : "", name);
88*7c478bd9Sstevel@tonic-gate 	return (EINVAL);
89*7c478bd9Sstevel@tonic-gate }
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate /*
92*7c478bd9Sstevel@tonic-gate  * __db_err --
93*7c478bd9Sstevel@tonic-gate  *	Standard DB error routine.
94*7c478bd9Sstevel@tonic-gate  *
95*7c478bd9Sstevel@tonic-gate  * PUBLIC: #ifdef __STDC__
96*7c478bd9Sstevel@tonic-gate  * PUBLIC: void __db_err __P((const DB_ENV *dbenv, const char *fmt, ...));
97*7c478bd9Sstevel@tonic-gate  * PUBLIC: #else
98*7c478bd9Sstevel@tonic-gate  * PUBLIC: void __db_err();
99*7c478bd9Sstevel@tonic-gate  * PUBLIC: #endif
100*7c478bd9Sstevel@tonic-gate  */
101*7c478bd9Sstevel@tonic-gate void
102*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
__db_err(const DB_ENV * dbenv,const char * fmt,...)103*7c478bd9Sstevel@tonic-gate __db_err(const DB_ENV *dbenv, const char *fmt, ...)
104*7c478bd9Sstevel@tonic-gate #else
105*7c478bd9Sstevel@tonic-gate __db_err(dbenv, fmt, va_alist)
106*7c478bd9Sstevel@tonic-gate 	const DB_ENV *dbenv;
107*7c478bd9Sstevel@tonic-gate 	const char *fmt;
108*7c478bd9Sstevel@tonic-gate 	va_dcl
109*7c478bd9Sstevel@tonic-gate #endif
110*7c478bd9Sstevel@tonic-gate {
111*7c478bd9Sstevel@tonic-gate 	va_list ap;
112*7c478bd9Sstevel@tonic-gate 	char errbuf[2048];	/* XXX: END OF THE STACK DON'T TRUST SPRINTF. */
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate 	if (dbenv == NULL)
115*7c478bd9Sstevel@tonic-gate 		return;
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate 	if (dbenv->db_errcall != NULL) {
118*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
119*7c478bd9Sstevel@tonic-gate          	va_start(ap, fmt);
120*7c478bd9Sstevel@tonic-gate #else
121*7c478bd9Sstevel@tonic-gate 	        va_start(ap);
122*7c478bd9Sstevel@tonic-gate #endif
123*7c478bd9Sstevel@tonic-gate 		(void)vsnprintf(errbuf, sizeof(errbuf), fmt, ap);
124*7c478bd9Sstevel@tonic-gate 		dbenv->db_errcall(dbenv->db_errpfx, errbuf);
125*7c478bd9Sstevel@tonic-gate 		va_end(ap);
126*7c478bd9Sstevel@tonic-gate 	}
127*7c478bd9Sstevel@tonic-gate 	if (dbenv->db_errfile != NULL) {
128*7c478bd9Sstevel@tonic-gate 		if (dbenv->db_errpfx != NULL)
129*7c478bd9Sstevel@tonic-gate 			(void)fprintf(dbenv->db_errfile, "%s: ",
130*7c478bd9Sstevel@tonic-gate 			    dbenv->db_errpfx);
131*7c478bd9Sstevel@tonic-gate #ifdef __STDC__
132*7c478bd9Sstevel@tonic-gate          	va_start(ap, fmt);
133*7c478bd9Sstevel@tonic-gate #else
134*7c478bd9Sstevel@tonic-gate 	        va_start(ap);
135*7c478bd9Sstevel@tonic-gate #endif
136*7c478bd9Sstevel@tonic-gate 		(void)vfprintf(dbenv->db_errfile, fmt, ap);
137*7c478bd9Sstevel@tonic-gate 		(void)fprintf(dbenv->db_errfile, "\n");
138*7c478bd9Sstevel@tonic-gate 		(void)fflush(dbenv->db_errfile);
139*7c478bd9Sstevel@tonic-gate 		va_end(ap);
140*7c478bd9Sstevel@tonic-gate 	}
141*7c478bd9Sstevel@tonic-gate }
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate /*
144*7c478bd9Sstevel@tonic-gate  * __db_pgerr --
145*7c478bd9Sstevel@tonic-gate  *	Error when unable to retrieve a specified page.
146*7c478bd9Sstevel@tonic-gate  *
147*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_pgerr __P((DB *, db_pgno_t));
148*7c478bd9Sstevel@tonic-gate  */
149*7c478bd9Sstevel@tonic-gate int
__db_pgerr(dbp,pgno)150*7c478bd9Sstevel@tonic-gate __db_pgerr(dbp, pgno)
151*7c478bd9Sstevel@tonic-gate 	DB *dbp;
152*7c478bd9Sstevel@tonic-gate 	db_pgno_t pgno;
153*7c478bd9Sstevel@tonic-gate {
154*7c478bd9Sstevel@tonic-gate 	/*
155*7c478bd9Sstevel@tonic-gate 	 * Three things are certain:
156*7c478bd9Sstevel@tonic-gate 	 * Death, taxes, and lost data.
157*7c478bd9Sstevel@tonic-gate 	 * Guess which has occurred.
158*7c478bd9Sstevel@tonic-gate 	 */
159*7c478bd9Sstevel@tonic-gate 	__db_err(dbp->dbenv,
160*7c478bd9Sstevel@tonic-gate 	    "unable to create/retrieve page %lu", (u_long)pgno);
161*7c478bd9Sstevel@tonic-gate 	return (__db_panic(dbp->dbenv, EIO));
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate 
164*7c478bd9Sstevel@tonic-gate /*
165*7c478bd9Sstevel@tonic-gate  * __db_pgfmt --
166*7c478bd9Sstevel@tonic-gate  *	Error when a page has the wrong format.
167*7c478bd9Sstevel@tonic-gate  *
168*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_pgfmt __P((DB *, db_pgno_t));
169*7c478bd9Sstevel@tonic-gate  */
170*7c478bd9Sstevel@tonic-gate int
__db_pgfmt(dbp,pgno)171*7c478bd9Sstevel@tonic-gate __db_pgfmt(dbp, pgno)
172*7c478bd9Sstevel@tonic-gate 	DB *dbp;
173*7c478bd9Sstevel@tonic-gate 	db_pgno_t pgno;
174*7c478bd9Sstevel@tonic-gate {
175*7c478bd9Sstevel@tonic-gate 	__db_err(dbp->dbenv,
176*7c478bd9Sstevel@tonic-gate 	    "page %lu: illegal page type or format", (u_long)pgno);
177*7c478bd9Sstevel@tonic-gate 	return (__db_panic(dbp->dbenv, EINVAL));
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate  * __db_panic --
182*7c478bd9Sstevel@tonic-gate  *	Lock out the tree due to unrecoverable error.
183*7c478bd9Sstevel@tonic-gate  *
184*7c478bd9Sstevel@tonic-gate  * PUBLIC: int __db_panic __P((DB_ENV *, int));
185*7c478bd9Sstevel@tonic-gate  */
186*7c478bd9Sstevel@tonic-gate int
__db_panic(dbenv,errval)187*7c478bd9Sstevel@tonic-gate __db_panic(dbenv, errval)
188*7c478bd9Sstevel@tonic-gate 	DB_ENV *dbenv;
189*7c478bd9Sstevel@tonic-gate 	int errval;
190*7c478bd9Sstevel@tonic-gate {
191*7c478bd9Sstevel@tonic-gate 	if (dbenv != NULL) {
192*7c478bd9Sstevel@tonic-gate 		dbenv->db_panic = errval;
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate 		(void)__log_panic(dbenv);
195*7c478bd9Sstevel@tonic-gate 		(void)__memp_panic(dbenv);
196*7c478bd9Sstevel@tonic-gate 		(void)__lock_panic(dbenv);
197*7c478bd9Sstevel@tonic-gate 		(void)__txn_panic(dbenv);
198*7c478bd9Sstevel@tonic-gate 
199*7c478bd9Sstevel@tonic-gate 		__db_err(dbenv, "PANIC: %s", strerror(errval));
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate 		if (dbenv->db_paniccall != NULL)
202*7c478bd9Sstevel@tonic-gate 			dbenv->db_paniccall(dbenv, errval);
203*7c478bd9Sstevel@tonic-gate 	}
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	/*
206*7c478bd9Sstevel@tonic-gate 	 * Chaos reigns within.
207*7c478bd9Sstevel@tonic-gate 	 * Reflect, repent, and reboot.
208*7c478bd9Sstevel@tonic-gate 	 * Order shall return.
209*7c478bd9Sstevel@tonic-gate 	 */
210*7c478bd9Sstevel@tonic-gate 	return (DB_RUNRECOVERY);
211*7c478bd9Sstevel@tonic-gate }
212