Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

log_debug.c

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 1999-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: log_debug.c,v 1.5 2005/10/14 01:17:09 bostic Exp $
00008  */
00009 
00010 #include "db_config.h"
00011 
00012 #ifndef NO_SYSTEM_INCLUDES
00013 #include <sys/types.h>
00014 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #endif
00018 
00019 #include "db_int.h"
00020 #include "dbinc/db_page.h"
00021 #include "dbinc/db_am.h"
00022 #include "dbinc/log.h"
00023 
00024 static int __log_printf_int __P((DB_ENV *, DB_TXN *, const char *, va_list));
00025 
00026 /*
00027  * __log_printf_capi --
00028  *      Write a printf-style format string into the DB log.
00029  *
00030  * PUBLIC: int __log_printf_capi __P((DB_ENV *, DB_TXN *, const char *, ...))
00031  * PUBLIC:    __attribute__ ((__format__ (__printf__, 3, 4)));
00032  */
00033 int
00034 #ifdef STDC_HEADERS
00035 __log_printf_capi(DB_ENV *dbenv, DB_TXN *txnid, const char *fmt, ...)
00036 #else
00037 __log_printf_capi(dbenv, txnid, fmt, va_alist)
00038         DB_ENV *dbenv;
00039         DB_TXN *txnid;
00040         const char *fmt;
00041         va_dcl
00042 #endif
00043 {
00044         va_list ap;
00045         int ret;
00046 
00047 #ifdef STDC_HEADERS
00048         va_start(ap, fmt);
00049 #else
00050         va_start(ap);
00051 #endif
00052         ret = __log_printf_pp(dbenv, txnid, fmt, ap);
00053         va_end(ap);
00054 
00055         return (ret);
00056 }
00057 
00058 /*
00059  * __log_printf_pp --
00060  *      Handle the arguments and call an internal routine to do the work.
00061  *
00062  *      The reason this routine isn't just folded into __log_printf_capi
00063  *      is because the C++ API has to call a C API routine, and you can
00064  *      only pass variadic arguments to a single routine.
00065  *
00066  * PUBLIC: int __log_printf_pp
00067  * PUBLIC:     __P((DB_ENV *, DB_TXN *, const char *, va_list));
00068  */
00069 int
00070 __log_printf_pp(dbenv, txnid, fmt, ap)
00071         DB_ENV *dbenv;
00072         DB_TXN *txnid;
00073         const char *fmt;
00074         va_list ap;
00075 {
00076         DB_THREAD_INFO *ip;
00077         int rep_check, ret, t_ret;
00078 
00079         PANIC_CHECK(dbenv);
00080         ENV_REQUIRES_CONFIG(dbenv,
00081             dbenv->lg_handle, "DB_ENV->log_printf", DB_INIT_LOG);
00082 
00083         ENV_ENTER(dbenv, ip);
00084         rep_check = IS_ENV_REPLICATED(dbenv) ? 1 : 0;
00085         if (rep_check && (ret = __env_rep_enter(dbenv, 0)) != 0)
00086                 return (ret);
00087 
00088         ret = __log_printf_int(dbenv, txnid, fmt, ap);
00089 
00090         if (rep_check && (t_ret = __env_db_rep_exit(dbenv)) != 0 && (ret) == 0)
00091                 ret = t_ret;
00092         va_end(ap);
00093         ENV_LEAVE(dbenv, ip);
00094 
00095         return (ret);
00096 }
00097 
00098 /*
00099  * __log_printf --
00100  *      Write a printf-style format string into the DB log.
00101  *
00102  * PUBLIC: int __log_printf __P((DB_ENV *, DB_TXN *, const char *, ...))
00103  * PUBLIC:    __attribute__ ((__format__ (__printf__, 3, 4)));
00104  */
00105 int
00106 #ifdef STDC_HEADERS
00107 __log_printf(DB_ENV *dbenv, DB_TXN *txnid, const char *fmt, ...)
00108 #else
00109 __log_printf(dbenv, txnid, fmt, va_alist)
00110         DB_ENV *dbenv;
00111         DB_TXN *txnid;
00112         const char *fmt;
00113         va_dcl
00114 #endif
00115 {
00116         va_list ap;
00117         int ret;
00118 
00119 #ifdef STDC_HEADERS
00120         va_start(ap, fmt);
00121 #else
00122         va_start(ap);
00123 #endif
00124         ret = __log_printf_int(dbenv, txnid, fmt, ap);
00125         va_end(ap);
00126 
00127         return (ret);
00128 }
00129 
00130 /*
00131  * __log_printf_int --
00132  *      Write a printf-style format string into the DB log (internal).
00133  */
00134 static int
00135 __log_printf_int(dbenv, txnid, fmt, ap)
00136         DB_ENV *dbenv;
00137         DB_TXN *txnid;
00138         const char *fmt;
00139         va_list ap;
00140 {
00141         DBT opdbt, msgdbt;
00142         DB_LSN lsn;
00143         char __logbuf[2048];    /* !!!: END OF THE STACK DON'T TRUST SPRINTF. */
00144 
00145         if (!DBENV_LOGGING(dbenv)) {
00146                 __db_err(dbenv, "Logging not currently permitted");
00147                 return (EAGAIN);
00148         }
00149 
00150         memset(&opdbt, 0, sizeof(opdbt));
00151         opdbt.data = "DIAGNOSTIC";
00152         opdbt.size = sizeof("DIAGNOSTIC") - 1;
00153 
00154         memset(&msgdbt, 0, sizeof(msgdbt));
00155         msgdbt.data = __logbuf;
00156         msgdbt.size = (u_int32_t)vsnprintf(__logbuf, sizeof(__logbuf), fmt, ap);
00157 
00158         return (__db_debug_log(
00159             dbenv, txnid, &lsn, 0, &opdbt, -1, &msgdbt, NULL, 0));
00160 }

Generated on Sun Dec 25 12:14:40 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2