~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/db_verify/db_verify.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*-
2
 
 * See the file LICENSE for redistribution information.
3
 
 *
4
 
 * Copyright (c) 1996-2002
5
 
 *      Sleepycat Software.  All rights reserved.
6
 
 */
7
 
 
8
 
#include "db_config.h"
9
 
 
10
 
#ifndef lint
11
 
static const char copyright[] =
12
 
    "Copyright (c) 1996-2002\nSleepycat Software Inc.  All rights reserved.\n";
13
 
static const char revid[] =
14
 
    "$Id$";
15
 
#endif
16
 
 
17
 
#ifndef NO_SYSTEM_INCLUDES
18
 
#include <sys/types.h>
19
 
 
20
 
#include <stdio.h>
21
 
#include <stdlib.h>
22
 
#include <string.h>
23
 
#include <unistd.h>
24
 
#endif
25
 
 
26
 
#include "db_int.h"
27
 
 
28
 
int main __P((int, char *[]));
29
 
int usage __P((void));
30
 
int version_check __P((const char *));
31
 
 
32
 
int
33
 
main(argc, argv)
34
 
        int argc;
35
 
        char *argv[];
36
 
{
37
 
        extern char *optarg;
38
 
        extern int optind;
39
 
        const char *progname = "db_verify";
40
 
        DB *dbp, *dbp1;
41
 
        DB_ENV *dbenv;
42
 
        u_int32_t cache;
43
 
        int ch, d_close, e_close, exitval, nflag, oflag, private;
44
 
        int quiet, resize, ret, t_ret;
45
 
        char *home, *passwd;
46
 
 
47
 
        if ((ret = version_check(progname)) != 0)
48
 
                return (ret);
49
 
 
50
 
        dbenv = NULL;
51
 
        cache = MEGABYTE;
52
 
        d_close = e_close = exitval = nflag = oflag = quiet = 0;
53
 
        home = passwd = NULL;
54
 
        while ((ch = getopt(argc, argv, "h:NoP:qV")) != EOF)
55
 
                switch (ch) {
56
 
                case 'h':
57
 
                        home = optarg;
58
 
                        break;
59
 
                case 'N':
60
 
                        nflag = 1;
61
 
                        break;
62
 
                case 'P':
63
 
                        passwd = strdup(optarg);
64
 
                        memset(optarg, 0, strlen(optarg));
65
 
                        if (passwd == NULL) {
66
 
                                fprintf(stderr, "%s: strdup: %s\n",
67
 
                                    progname, strerror(errno));
68
 
                                return (EXIT_FAILURE);
69
 
                        }
70
 
                        break;
71
 
                case 'o':
72
 
                        oflag = 1;
73
 
                        break;
74
 
                case 'q':
75
 
                        quiet = 1;
76
 
                        break;
77
 
                case 'V':
78
 
                        printf("%s\n", db_version(NULL, NULL, NULL));
79
 
                        return (EXIT_SUCCESS);
80
 
                case '?':
81
 
                default:
82
 
                        return (usage());
83
 
                }
84
 
        argc -= optind;
85
 
        argv += optind;
86
 
 
87
 
        if (argc <= 0)
88
 
                return (usage());
89
 
 
90
 
        /* Handle possible interruptions. */
91
 
        __db_util_siginit();
92
 
 
93
 
        /*
94
 
         * Create an environment object and initialize it for error
95
 
         * reporting.
96
 
         */
97
 
retry:  if ((ret = db_env_create(&dbenv, 0)) != 0) {
98
 
                fprintf(stderr,
99
 
                    "%s: db_env_create: %s\n", progname, db_strerror(ret));
100
 
                goto shutdown;
101
 
        }
102
 
        e_close = 1;
103
 
 
104
 
        if (!quiet) {
105
 
                dbenv->set_errfile(dbenv, stderr);
106
 
                dbenv->set_errpfx(dbenv, progname);
107
 
        }
108
 
 
109
 
        if (nflag) {
110
 
                if ((ret = dbenv->set_flags(dbenv, DB_NOLOCKING, 1)) != 0) {
111
 
                        dbenv->err(dbenv, ret, "set_flags: DB_NOLOCKING");
112
 
                        goto shutdown;
113
 
                }
114
 
                if ((ret = dbenv->set_flags(dbenv, DB_NOPANIC, 1)) != 0) {
115
 
                        dbenv->err(dbenv, ret, "set_flags: DB_NOPANIC");
116
 
                        goto shutdown;
117
 
                }
118
 
        }
119
 
 
120
 
        if (passwd != NULL &&
121
 
            (ret = dbenv->set_encrypt(dbenv, passwd, DB_ENCRYPT_AES)) != 0) {
122
 
                dbenv->err(dbenv, ret, "set_passwd");
123
 
                goto shutdown;
124
 
        }
125
 
        /*
126
 
         * Attach to an mpool if it exists, but if that fails, attach to a
127
 
         * private region.  In the latter case, declare a reasonably large
128
 
         * cache so that we don't fail when verifying large databases.
129
 
         */
130
 
        private = 0;
131
 
        if ((ret =
132
 
            dbenv->open(dbenv, home, DB_INIT_MPOOL | DB_USE_ENVIRON, 0)) != 0) {
133
 
                if ((ret = dbenv->set_cachesize(dbenv, 0, cache, 1)) != 0) {
134
 
                        dbenv->err(dbenv, ret, "set_cachesize");
135
 
                        goto shutdown;
136
 
                }
137
 
                private = 1;
138
 
                if ((ret = dbenv->open(dbenv, home,
139
 
            DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0) {
140
 
                        dbenv->err(dbenv, ret, "open");
141
 
                        goto shutdown;
142
 
                }
143
 
        }
144
 
 
145
 
        for (; !__db_util_interrupted() && argv[0] != NULL; ++argv) {
146
 
                if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
147
 
                        dbenv->err(dbenv, ret, "%s: db_create", progname);
148
 
                        goto shutdown;
149
 
                }
150
 
                d_close = 1;
151
 
 
152
 
                /*
153
 
                 * We create a 2nd dbp to this database to get its pagesize
154
 
                 * because the dbp we're using for verify cannot be opened.
155
 
                 */
156
 
                if (private) {
157
 
                        if ((ret = db_create(&dbp1, dbenv, 0)) != 0) {
158
 
                                dbenv->err(
159
 
                                    dbenv, ret, "%s: db_create", progname);
160
 
                                goto shutdown;
161
 
                        }
162
 
 
163
 
                        if ((ret = dbp1->open(dbp1, NULL,
164
 
                            argv[0], NULL, DB_UNKNOWN, DB_RDONLY, 0)) != 0) {
165
 
                                dbenv->err(dbenv, ret, "DB->open: %s", argv[0]);
166
 
                                (void)dbp1->close(dbp1, 0);
167
 
                                goto shutdown;
168
 
                        }
169
 
                        /*
170
 
                         * If we get here, we can check the cache/page.
171
 
                         * !!!
172
 
                         * If we have to retry with an env with a larger
173
 
                         * cache, we jump out of this loop.  However, we
174
 
                         * will still be working on the same argv when we
175
 
                         * get back into the for-loop.
176
 
                         */
177
 
                        ret = __db_util_cache(dbenv, dbp1, &cache, &resize);
178
 
                        (void)dbp1->close(dbp1, 0);
179
 
                        if (ret != 0)
180
 
                                goto shutdown;
181
 
 
182
 
                        if (resize) {
183
 
                                (void)dbp->close(dbp, 0);
184
 
                                d_close = 0;
185
 
 
186
 
                                (void)dbenv->close(dbenv, 0);
187
 
                                e_close = 0;
188
 
                                goto retry;
189
 
                        }
190
 
                }
191
 
                if ((ret = dbp->verify(dbp,
192
 
                    argv[0], NULL, NULL, oflag ? DB_NOORDERCHK : 0)) != 0)
193
 
                        dbp->err(dbp, ret, "DB->verify: %s", argv[0]);
194
 
                if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0) {
195
 
                        dbenv->err(dbenv, ret, "DB->close: %s", argv[0]);
196
 
                        ret = t_ret;
197
 
                }
198
 
                d_close = 0;
199
 
                if (ret != 0)
200
 
                        goto shutdown;
201
 
        }
202
 
 
203
 
        if (0) {
204
 
shutdown:       exitval = 1;
205
 
        }
206
 
 
207
 
        if (d_close && (ret = dbp->close(dbp, 0)) != 0) {
208
 
                exitval = 1;
209
 
                dbenv->err(dbenv, ret, "close");
210
 
        }
211
 
        if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
212
 
                exitval = 1;
213
 
                fprintf(stderr,
214
 
                    "%s: dbenv->close: %s\n", progname, db_strerror(ret));
215
 
        }
216
 
 
217
 
        /* Resend any caught signal. */
218
 
        __db_util_sigresend();
219
 
 
220
 
        return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
221
 
}
222
 
 
223
 
int
224
 
usage()
225
 
{
226
 
        fprintf(stderr, "%s\n",
227
 
            "usage: db_verify [-NoqV] [-h home] [-P password] db_file ...");
228
 
        return (EXIT_FAILURE);
229
 
}
230
 
 
231
 
int
232
 
version_check(progname)
233
 
        const char *progname;
234
 
{
235
 
        int v_major, v_minor, v_patch;
236
 
 
237
 
        /* Make sure we're loaded with the right version of the DB library. */
238
 
        (void)db_version(&v_major, &v_minor, &v_patch);
239
 
        if (v_major != DB_VERSION_MAJOR ||
240
 
            v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
241
 
                fprintf(stderr,
242
 
        "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
243
 
                    progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
244
 
                    DB_VERSION_PATCH, v_major, v_minor, v_patch);
245
 
                return (EXIT_FAILURE);
246
 
        }
247
 
        return (0);
248
 
}