summaryrefslogtreecommitdiff
path: root/util/db_dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'util/db_dump.c')
-rw-r--r--util/db_dump.c82
1 files changed, 57 insertions, 25 deletions
diff --git a/util/db_dump.c b/util/db_dump.c
index 8c90d087..9b1fbb1c 100644
--- a/util/db_dump.c
+++ b/util/db_dump.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.
*
* $Id$
*/
@@ -14,7 +14,7 @@
#ifndef lint
static const char copyright[] =
- "Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.\n";
+ "Copyright (c) 1996, 2015 Oracle and/or its affiliates. All rights reserved.\n";
#endif
int db_init __P((DB_ENV *, char *, int, u_int32_t, int *));
@@ -40,7 +40,7 @@ main(argc, argv)
int ch;
int exitval, keyflag, lflag, mflag, nflag, pflag, sflag, private;
int ret, Rflag, rflag, resize;
- char *data_len, *dbname, *dopt, *filename, *home, *passwd;
+ char *blob_dir, *data_len, *dbname, *dopt, *filename, *home, *passwd;
if ((progname = __db_rpath(argv[0])) == NULL)
progname = argv[0];
@@ -57,9 +57,18 @@ main(argc, argv)
keyflag = 0;
cache = MEGABYTE;
private = 0;
- data_len = dbname = dopt = filename = home = passwd = NULL;
- while ((ch = getopt(argc, argv, "d:D:f:F:h:klL:m:NpP:rRs:V")) != EOF)
+ blob_dir = data_len = dbname = dopt = filename = home = passwd = NULL;
+ while ((ch = getopt(argc, argv, "b:d:D:f:F:h:klL:m:NpP:rRs:V")) != EOF)
switch (ch) {
+ case 'b':
+ if (blob_dir!= NULL) {
+ fprintf(stderr, DB_STR("5144",
+ "Blob directory may not be specified twice"));
+ goto err;
+ }
+ blob_dir = strdup(optarg);
+ memset(optarg, 0, strlen(optarg));
+ break;
case 'd':
dopt = optarg;
break;
@@ -71,7 +80,7 @@ main(argc, argv)
fprintf(stderr, DB_STR_A("5108",
"%s: %s: reopen: %s\n", "%s %s %s\n"),
progname, optarg, strerror(errno));
- return (EXIT_FAILURE);
+ goto err;
}
break;
case 'F':
@@ -100,8 +109,7 @@ main(argc, argv)
if (passwd != NULL) {
fprintf(stderr, DB_STR("5130",
"Password may not be specified twice"));
- free(passwd);
- return (EXIT_FAILURE);
+ goto err;
}
passwd = strdup(optarg);
memset(optarg, 0, strlen(optarg));
@@ -109,7 +117,7 @@ main(argc, argv)
fprintf(stderr, DB_STR_A("5109",
"%s: strdup: %s\n", "%s %s\n"),
progname, strerror(errno));
- return (EXIT_FAILURE);
+ goto err;
}
break;
case 'p':
@@ -128,10 +136,11 @@ main(argc, argv)
break;
case 'V':
printf("%s\n", db_version(NULL, NULL, NULL));
- return (EXIT_SUCCESS);
+ goto done;
case '?':
default:
- return (usage());
+ (void)usage();
+ goto err;
}
argc -= optind;
argv += optind;
@@ -144,40 +153,42 @@ main(argc, argv)
filename = NULL;
else if (argc == 1 && !mflag)
filename = argv[0];
- else
- return (usage());
+ else {
+ (void)usage();
+ goto err;
+ }
if (dopt != NULL && pflag) {
fprintf(stderr, DB_STR_A("5110",
"%s: the -d and -p options may not both be specified\n",
"%s\n"), progname);
- return (EXIT_FAILURE);
+ goto err;
}
if (lflag && sflag) {
fprintf(stderr, DB_STR_A("5111",
"%s: the -l and -s options may not both be specified\n",
"%s\n"), progname);
- return (EXIT_FAILURE);
+ goto err;
}
if ((lflag || sflag) && mflag) {
fprintf(stderr, DB_STR_A("5112",
"%s: the -m option may not be specified with -l or -s\n",
"%s\n"), progname);
- return (EXIT_FAILURE);
+ goto err;
}
if (keyflag && rflag) {
fprintf(stderr, DB_STR_A("5113",
"%s: the -k and -r or -R options may not both be specified\n",
"%s\n"), progname);
- return (EXIT_FAILURE);
+ goto err;
}
if (sflag && rflag) {
fprintf(stderr, DB_STR_A("5114",
"%s: the -r or R options may not be specified with -s\n",
"%s\n"), progname);
- return (EXIT_FAILURE);
+ goto err;
}
/* Handle possible interruptions. */
@@ -195,8 +206,6 @@ retry: if ((ret = db_env_create(&dbenv, 0)) != 0) {
dbenv->set_errfile(dbenv, stderr);
dbenv->set_errpfx(dbenv, progname);
- if (data_len != NULL)
- (void)dbenv->set_data_len(dbenv, (u_int32_t)atol(data_len));
if (nflag) {
if ((ret = dbenv->set_flags(dbenv, DB_NOLOCKING, 1)) != 0) {
@@ -214,10 +223,28 @@ retry: if ((ret = db_env_create(&dbenv, 0)) != 0) {
goto err;
}
+ /* Set the directory in which blob files are stored. */
+ if (blob_dir != NULL) {
+ if ((ret = dbenv->set_blob_dir(dbenv, blob_dir)) != 0) {
+ dbenv->err(dbenv, ret, "set_blob_dir");
+ goto err;
+ }
+ }
+
/* Initialize the environment. */
if (db_init(dbenv, home, rflag, cache, &private) != 0)
goto err;
+ /*
+ * Set data_len after environment opens. The value passed
+ * by -D takes priority.
+ */
+ if (data_len != NULL && (ret = dbenv->set_data_len(dbenv,
+ (u_int32_t)atol(data_len))) != 0) {
+ dbenv->err(dbenv, ret, "set_data_len");
+ goto err;
+ }
+
/* Create the DB object and open the file. */
if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
dbenv->err(dbenv, ret, "db_create");
@@ -310,6 +337,9 @@ done: if (dbp != NULL && (ret = dbp->close(dbp, 0)) != 0) {
if (passwd != NULL)
free(passwd);
+ if (blob_dir != NULL)
+ free(blob_dir);
+
/* Resend any caught signal. */
__db_util_sigresend();
@@ -352,7 +382,7 @@ db_init(dbenv, home, is_salvage, cache, is_privatep)
if ((ret = dbenv->open(dbenv, home,
DB_USE_ENVIRON | (is_salvage ? DB_INIT_MPOOL : 0), 0)) == 0)
return (0);
- if (ret == DB_VERSION_MISMATCH)
+ if (ret == DB_VERSION_MISMATCH || ret == DB_REP_LOCKOUT)
goto err;
/*
@@ -483,7 +513,7 @@ show_subs(dbp)
while ((ret = dbcp->get(dbcp, &key, &data,
DB_IGNORE_LEASE | DB_NEXT)) == 0) {
if ((ret = dbp->dbenv->prdbt(
- &key, 1, NULL, stdout, __db_pr_callback, 0, 0)) != 0) {
+ &key, 1, NULL, stdout, __db_pr_callback, 0, 0, 0)) != 0) {
dbp->errx(dbp, NULL);
return (1);
}
@@ -507,11 +537,13 @@ show_subs(dbp)
int
usage()
{
- (void)fprintf(stderr, "usage: %s [-klNprRV]\n\t%s\n",
+ (void)fprintf(stderr, "usage: %s [-bklNprRV]\n\t%s%s\n",
progname,
- "[-d ahr] [-f output] [-h home] [-P password] [-s database] db_file");
+ "[-b blob_dir] [-d ahr] [-f output] [-h home] ",
+ "[-P password] [-s database] db_file");
(void)fprintf(stderr, "usage: %s [-kNpV] %s\n",
- progname, "[-d ahr] [-f output] [-h home] -m database");
+ progname,
+ "[-d ahr] [-D data_len] [-f output] [-h home] -m database");
return (EXIT_FAILURE);
}