summaryrefslogtreecommitdiff
path: root/db/db_recover
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-12-15 21:42:09 +0000
committerjbj <devnull@localhost>2003-12-15 21:42:09 +0000
commit8960e3895f7af91126465368dff8fbb36ab4e853 (patch)
tree3c515e39dde0e88edeb806ea87d08524ba25c761 /db/db_recover
parent752cac72e220dcad4e6fce39508e714e59e3e0a1 (diff)
downloadlibrpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.tar.gz
librpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.tar.bz2
librpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.zip
- upgrade to db-4.2.52.
CVS patchset: 6972 CVS date: 2003/12/15 21:42:09
Diffstat (limited to 'db/db_recover')
-rw-r--r--db/db_recover/db_recover.c138
1 files changed, 76 insertions, 62 deletions
diff --git a/db/db_recover/db_recover.c b/db/db_recover/db_recover.c
index 59ab8bcef..0a2f6b049 100644
--- a/db/db_recover/db_recover.c
+++ b/db/db_recover/db_recover.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2003
* Sleepycat Software. All rights reserved.
*/
@@ -9,9 +9,9 @@
#ifndef lint
static const char copyright[] =
- "Copyright (c) 1996-2000\nSleepycat Software Inc. All rights reserved.\n";
+ "Copyright (c) 1996-2003\nSleepycat Software Inc. All rights reserved.\n";
static const char revid[] =
- "$Id: db_recover.c,v 11.17 2001/01/18 18:36:58 bostic Exp $";
+ "$Id: db_recover.c,v 11.39 2003/09/04 18:06:46 bostic Exp $";
#endif
#ifndef NO_SYSTEM_INCLUDES
@@ -34,17 +34,11 @@ static const char revid[] =
#endif
#include "db_int.h"
-#include "common_ext.h"
-#include "txn.h"
-int main __P((int, char *[]));
-void read_timestamp __P((char *, time_t *));
-void usage __P((void));
-void version_check __P((void));
-
-DB_ENV *dbenv;
-const char
- *progname = "db_recover"; /* Program name. */
+int main __P((int, char *[]));
+int read_timestamp __P((const char *, char *, time_t *));
+int usage __P((void));
+int version_check __P((const char *));
int
main(argc, argv)
@@ -53,43 +47,59 @@ main(argc, argv)
{
extern char *optarg;
extern int optind;
- DB_TXNREGION *region;
- time_t now, timestamp;
+ const char *progname = "db_recover";
+ DB_ENV *dbenv;
+ time_t timestamp;
u_int32_t flags;
- int ch, exitval, fatal_recover, ret, verbose;
- char *home;
+ int ch, exitval, fatal_recover, ret, retain_env, verbose;
+ char *home, *passwd;
- version_check();
+ if ((ret = version_check(progname)) != 0)
+ return (ret);
- home = NULL;
+ home = passwd = NULL;
timestamp = 0;
- exitval = fatal_recover = verbose = 0;
- while ((ch = getopt(argc, argv, "ch:t:Vv")) != EOF)
+ exitval = fatal_recover = retain_env = verbose = 0;
+ while ((ch = getopt(argc, argv, "ceh:P:t:Vv")) != EOF)
switch (ch) {
case 'c':
fatal_recover = 1;
break;
+ case 'e':
+ retain_env = 1;
+ break;
case 'h':
home = optarg;
break;
+ case 'P':
+ passwd = strdup(optarg);
+ memset(optarg, 0, strlen(optarg));
+ if (passwd == NULL) {
+ fprintf(stderr, "%s: strdup: %s\n",
+ progname, strerror(errno));
+ return (EXIT_FAILURE);
+ }
+ break;
case 't':
- read_timestamp(optarg, &timestamp);
+ if ((ret =
+ read_timestamp(progname, optarg, &timestamp)) != 0)
+ return (ret);
break;
case 'V':
printf("%s\n", db_version(NULL, NULL, NULL));
- exit(0);
+ return (EXIT_SUCCESS);
case 'v':
verbose = 1;
break;
case '?':
default:
- usage();
+ return (usage());
}
argc -= optind;
argv += optind;
if (argc != 0)
- usage();
+ return (usage());
/* Handle possible interruptions. */
__db_util_siginit();
@@ -101,7 +111,7 @@ main(argc, argv)
if ((ret = db_env_create(&dbenv, 0)) != 0) {
fprintf(stderr,
"%s: db_env_create: %s\n", progname, db_strerror(ret));
- exit (1);
+ return (EXIT_FAILURE);
}
dbenv->set_errfile(dbenv, stderr);
dbenv->set_errpfx(dbenv, progname);
@@ -111,7 +121,13 @@ main(argc, argv)
}
if (timestamp &&
(ret = dbenv->set_tx_timestamp(dbenv, &timestamp)) != 0) {
- dbenv->err(dbenv, ret, "DBENV->set_timestamp");
+ dbenv->err(dbenv, ret, "DB_ENV->set_timestamp");
+ goto shutdown;
+ }
+
+ if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
+ passwd, DB_ENCRYPT_AES)) != 0) {
+ dbenv->err(dbenv, ret, "set_passwd");
goto shutdown;
}
@@ -119,31 +135,24 @@ main(argc, argv)
* Initialize the environment -- we don't actually do anything
* else, that all that's needed to run recovery.
*
- * Note that we specify a private environment, as we're about to
- * create a region, and we don't want to to leave it around. If
- * we leave the region around, the application that should create
- * it will simply join it instead, and will then be running with
- * incorrectly sized (and probably terribly small) caches.
+ * Note that unless the caller specified the -e option, we use a
+ * private environment, as we're about to create a region, and we
+ * don't want to to leave it around. If we leave the region around,
+ * the application that should create it will simply join it instead,
+ * and will then be running with incorrectly sized (and probably
+ * terribly small) caches. Applications that use -e should almost
+ * certainly use DB_CONFIG files in the directory.
*/
flags = 0;
LF_SET(DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
- DB_INIT_MPOOL | DB_INIT_TXN | DB_PRIVATE | DB_USE_ENVIRON);
+ DB_INIT_MPOOL | DB_INIT_TXN | DB_USE_ENVIRON);
LF_SET(fatal_recover ? DB_RECOVER_FATAL : DB_RECOVER);
+ LF_SET(retain_env ? 0 : DB_PRIVATE);
if ((ret = dbenv->open(dbenv, home, flags, 0)) != 0) {
- dbenv->err(dbenv, ret, "DBENV->open");
+ dbenv->err(dbenv, ret, "DB_ENV->open");
goto shutdown;
}
- if (verbose) {
- (void)time(&now);
- region = ((DB_TXNMGR *)dbenv->tx_handle)->reginfo.primary;
- dbenv->errx(dbenv, "Recovery complete at %.24s", ctime(&now));
- dbenv->errx(dbenv, "%s %lx %s [%lu][%lu]",
- "Maximum transaction id", (u_long)region->last_txnid,
- "Recovery checkpoint", (u_long)region->last_ckp.file,
- (u_long)region->last_ckp.offset);
- }
-
if (0) {
shutdown: exitval = 1;
}
@@ -154,11 +163,13 @@ shutdown: exitval = 1;
fprintf(stderr,
"%s: dbenv->close: %s\n", progname, db_strerror(ret));
}
+ if (passwd != NULL)
+ free(passwd);
/* Resend any caught signal. */
__db_util_sigresend();
- return (exitval);
+ return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
#define ATOI2(ar) ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
@@ -194,8 +205,9 @@ shutdown: exitval = 1;
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
-void
-read_timestamp(arg, timep)
+int
+read_timestamp(progname, arg, timep)
+ const char *progname;
char *arg;
time_t *timep;
{
@@ -208,7 +220,7 @@ read_timestamp(arg, timep)
if ((t = localtime(&now)) == NULL) {
fprintf(stderr,
"%s: localtime: %s\n", progname, strerror(errno));
- exit (1);
+ return (EXIT_FAILURE);
}
/* [[CC]YY]MMDDhhmm[.SS] */
if ((p = strchr(arg, '.')) == NULL)
@@ -221,12 +233,12 @@ read_timestamp(arg, timep)
}
yearset = 0;
- switch(strlen(arg)) {
+ switch (strlen(arg)) {
case 12: /* CCYYMMDDhhmm */
t->tm_year = ATOI2(arg);
t->tm_year *= 100;
yearset = 1;
- /* FALLTHOUGH */
+ /* FALLTHROUGH */
case 10: /* YYMMDDhhmm */
if (yearset) {
yearset = ATOI2(arg);
@@ -258,31 +270,33 @@ read_timestamp(arg, timep)
terr: fprintf(stderr,
"%s: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]",
progname);
- exit (1);
+ return (EXIT_FAILURE);
}
+ return (0);
}
-void
+int
usage()
{
- (void)fprintf(stderr,
- "usage: db_recover [-cVv] [-h home] [-t [[CC]YY]MMDDhhmm[.SS]]\n");
- exit(1);
+ (void)fprintf(stderr, "%s\n",
+"usage: db_recover [-ceVv] [-h home] [-P password] [-t [[CC]YY]MMDDhhmm[.SS]]");
+ return (EXIT_FAILURE);
}
-void
-version_check()
+int
+version_check(progname)
+ const char *progname;
{
int v_major, v_minor, v_patch;
/* Make sure we're loaded with the right version of the DB library. */
(void)db_version(&v_major, &v_minor, &v_patch);
- if (v_major != DB_VERSION_MAJOR ||
- v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
+ if (v_major != DB_VERSION_MAJOR || v_minor != DB_VERSION_MINOR) {
fprintf(stderr,
- "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
+ "%s: version %d.%d doesn't match library version %d.%d\n",
progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
- DB_VERSION_PATCH, v_major, v_minor, v_patch);
- exit (1);
+ v_major, v_minor);
+ return (EXIT_FAILURE);
}
+ return (0);
}