2 * See the file LICENSE for redistribution information.
4 * Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.
14 static const char copyright[] =
15 "Copyright (c) 1996, 2012 Oracle and/or its affiliates. All rights reserved.\n";
18 int main __P((int, char *[]));
19 int usage __P((void));
20 int version_check __P((void));
33 int ch, exitval, ret, verbose;
34 char **file, *home, **list, *passwd;
36 if ((progname = __db_rpath(argv[0])) == NULL)
41 if ((ret = version_check()) != 0)
46 exitval = verbose = 0;
49 while ((ch = getopt(argc, argv, "adh:lP:sVv")) != EOF)
55 LF_SET(DB_ARCH_REMOVE);
65 fprintf(stderr, DB_STR("5135",
66 "Password may not be specified twice"));
68 return (EXIT_FAILURE);
70 passwd = strdup(optarg);
71 memset(optarg, 0, strlen(optarg));
73 fprintf(stderr, DB_STR_A("5119",
74 "%s: strdup: %s\n", "%s %s\n"),
75 progname, strerror(errno));
76 return (EXIT_FAILURE);
83 printf("%s\n", db_version(NULL, NULL, NULL));
84 return (EXIT_SUCCESS);
88 * The verbose flag no longer actually does anything,
89 * but it's left rather than adding it back at some
104 /* Handle possible interruptions. */
108 * Create an environment object and initialize it for error
111 if ((ret = db_env_create(&dbenv, 0)) != 0) {
113 "%s: db_env_create: %s\n", progname, db_strerror(ret));
117 dbenv->set_errfile(dbenv, stderr);
118 dbenv->set_errpfx(dbenv, progname);
120 if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
121 passwd, DB_ENCRYPT_AES)) != 0) {
122 dbenv->err(dbenv, ret, "set_passwd");
126 * If attaching to a pre-existing environment fails, create a
127 * private one and try again.
129 if ((ret = dbenv->open(dbenv, home, DB_USE_ENVIRON, 0)) != 0 &&
130 (ret == DB_VERSION_MISMATCH ||
131 (ret = dbenv->open(dbenv, home, DB_CREATE |
132 DB_INIT_LOG | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0)) {
133 dbenv->err(dbenv, ret, "DB_ENV->open");
137 /* Get the list of names. */
138 if ((ret = dbenv->log_archive(dbenv, &list, flags)) != 0) {
139 dbenv->err(dbenv, ret, "DB_ENV->log_archive");
143 /* Print the list of names. */
145 for (file = list; *file != NULL; ++file)
146 printf("%s\n", *file);
153 if (dbenv != NULL && (ret = dbenv->close(dbenv, 0)) != 0) {
156 "%s: dbenv->close: %s\n", progname, db_strerror(ret));
162 /* Resend any caught signal. */
163 __db_util_sigresend();
165 return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
171 (void)fprintf(stderr,
172 "usage: %s [-adlsVv] [-h home] [-P password]\n", progname);
173 return (EXIT_FAILURE);
179 int v_major, v_minor, v_patch;
181 /* Make sure we're loaded with the right version of the DB library. */
182 (void)db_version(&v_major, &v_minor, &v_patch);
183 if (v_major != DB_VERSION_MAJOR || v_minor != DB_VERSION_MINOR) {
184 fprintf(stderr, DB_STR_A("5120",
185 "%s: version %d.%d doesn't match library version %d.%d\n",
186 "%s %d %d %d %d\n"), progname, DB_VERSION_MAJOR,
187 DB_VERSION_MINOR, v_major, v_minor);
188 return (EXIT_FAILURE);