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

« back to all changes in this revision

Viewing changes to libdb/build_vxworks/db_recover/db_recover.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
 
#if TIME_WITH_SYS_TIME
21
 
#include <sys/time.h>
22
 
#include <time.h>
23
 
#else
24
 
#if HAVE_SYS_TIME_H
25
 
#include <sys/time.h>
26
 
#else
27
 
#include <time.h>
28
 
#endif
29
 
#endif
30
 
 
31
 
#include <stdlib.h>
32
 
#include <string.h>
33
 
#include <unistd.h>
34
 
#endif
35
 
 
36
 
#include "db_int.h"
37
 
#include "dbinc/txn.h"
38
 
 
39
 
int db_recover_main __P((int, char *[]));
40
 
int db_recover_read_timestamp __P((const char *, char *, time_t *));
41
 
int db_recover_usage __P((void));
42
 
int db_recover_version_check __P((const char *));
43
 
 
44
 
int
45
 
db_recover(args)
46
 
        char *args;
47
 
{
48
 
        int argc;
49
 
        char **argv;
50
 
 
51
 
        __db_util_arg("db_recover", args, &argc, &argv);
52
 
        return (db_recover_main(argc, argv) ? EXIT_FAILURE : EXIT_SUCCESS);
53
 
}
54
 
 
55
 
#include <stdio.h>
56
 
#define ERROR_RETURN    ERROR
57
 
 
58
 
int
59
 
db_recover_main(argc, argv)
60
 
        int argc;
61
 
        char *argv[];
62
 
{
63
 
        extern char *optarg;
64
 
        extern int optind, __db_getopt_reset;
65
 
        const char *progname = "db_recover";
66
 
        DB_ENV  *dbenv;
67
 
        DB_TXNREGION *region;
68
 
        time_t now, timestamp;
69
 
        u_int32_t flags;
70
 
        int ch, exitval, fatal_recover, ret, retain_env, verbose;
71
 
        char *home, *passwd;
72
 
 
73
 
        if ((ret = db_recover_version_check(progname)) != 0)
74
 
                return (ret);
75
 
 
76
 
        home = passwd = NULL;
77
 
        timestamp = 0;
78
 
        exitval = fatal_recover = retain_env = verbose = 0;
79
 
        __db_getopt_reset = 1;
80
 
        while ((ch = getopt(argc, argv, "ceh:P:t:Vv")) != EOF)
81
 
                switch (ch) {
82
 
                case 'c':
83
 
                        fatal_recover = 1;
84
 
                        break;
85
 
                case 'e':
86
 
                        retain_env = 1;
87
 
                        break;
88
 
                case 'h':
89
 
                        home = optarg;
90
 
                        break;
91
 
                case 'P':
92
 
                        passwd = strdup(optarg);
93
 
                        memset(optarg, 0, strlen(optarg));
94
 
                        if (passwd == NULL) {
95
 
                                fprintf(stderr, "%s: strdup: %s\n",
96
 
                                    progname, strerror(errno));
97
 
                                return (EXIT_FAILURE);
98
 
                        }
99
 
                        break;
100
 
                case 't':
101
 
                        if ((ret =
102
 
                            db_recover_read_timestamp(progname, optarg, &timestamp)) != 0)
103
 
                                return (ret);
104
 
                        break;
105
 
                case 'V':
106
 
                        printf("%s\n", db_version(NULL, NULL, NULL));
107
 
                        return (EXIT_SUCCESS);
108
 
                case 'v':
109
 
                        verbose = 1;
110
 
                        break;
111
 
                case '?':
112
 
                default:
113
 
                        return (db_recover_usage());
114
 
                }
115
 
        argc -= optind;
116
 
        argv += optind;
117
 
 
118
 
        if (argc != 0)
119
 
                return (db_recover_usage());
120
 
 
121
 
        /* Handle possible interruptions. */
122
 
        __db_util_siginit();
123
 
 
124
 
        /*
125
 
         * Create an environment object and initialize it for error
126
 
         * reporting.
127
 
         */
128
 
        if ((ret = db_env_create(&dbenv, 0)) != 0) {
129
 
                fprintf(stderr,
130
 
                    "%s: db_env_create: %s\n", progname, db_strerror(ret));
131
 
                return (EXIT_FAILURE);
132
 
        }
133
 
        dbenv->set_errfile(dbenv, stderr);
134
 
        dbenv->set_errpfx(dbenv, progname);
135
 
        if (verbose) {
136
 
                (void)dbenv->set_verbose(dbenv, DB_VERB_RECOVERY, 1);
137
 
                (void)dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT, 1);
138
 
        }
139
 
        if (timestamp &&
140
 
            (ret = dbenv->set_tx_timestamp(dbenv, &timestamp)) != 0) {
141
 
                dbenv->err(dbenv, ret, "DB_ENV->set_timestamp");
142
 
                goto shutdown;
143
 
        }
144
 
 
145
 
        if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
146
 
            passwd, DB_ENCRYPT_AES)) != 0) {
147
 
                dbenv->err(dbenv, ret, "set_passwd");
148
 
                goto shutdown;
149
 
        }
150
 
 
151
 
        /*
152
 
         * Initialize the environment -- we don't actually do anything
153
 
         * else, that all that's needed to run recovery.
154
 
         *
155
 
         * Note that unless the caller specified the -e option, we use a
156
 
         * private environment, as we're about to create a region, and we
157
 
         * don't want to to leave it around.  If we leave the region around,
158
 
         * the application that should create it will simply join it instead,
159
 
         * and will then be running with incorrectly sized (and probably
160
 
         * terribly small) caches.  Applications that use -e should almost
161
 
         * certainly use DB_CONFIG files in the directory.
162
 
         */
163
 
        flags = 0;
164
 
        LF_SET(DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG |
165
 
            DB_INIT_MPOOL | DB_INIT_TXN | DB_USE_ENVIRON);
166
 
        LF_SET(fatal_recover ? DB_RECOVER_FATAL : DB_RECOVER);
167
 
        LF_SET(retain_env ? 0 : DB_PRIVATE);
168
 
        if ((ret = dbenv->open(dbenv, home, flags, 0)) != 0) {
169
 
                dbenv->err(dbenv, ret, "DB_ENV->open");
170
 
                goto shutdown;
171
 
        }
172
 
 
173
 
        if (verbose) {
174
 
                (void)time(&now);
175
 
                region = ((DB_TXNMGR *)dbenv->tx_handle)->reginfo.primary;
176
 
                dbenv->errx(dbenv, "Recovery complete at %.24s", ctime(&now));
177
 
                dbenv->errx(dbenv, "%s %lx %s [%lu][%lu]",
178
 
                    "Maximum transaction id", (u_long)region->last_txnid,
179
 
                    "Recovery checkpoint", (u_long)region->last_ckp.file,
180
 
                    (u_long)region->last_ckp.offset);
181
 
        }
182
 
 
183
 
        if (0) {
184
 
shutdown:       exitval = 1;
185
 
        }
186
 
 
187
 
        /* Clean up the environment. */
188
 
        if ((ret = dbenv->close(dbenv, 0)) != 0) {
189
 
                exitval = 1;
190
 
                fprintf(stderr,
191
 
                    "%s: dbenv->close: %s\n", progname, db_strerror(ret));
192
 
        }
193
 
 
194
 
        /* Resend any caught signal. */
195
 
        __db_util_sigresend();
196
 
 
197
 
        return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
198
 
}
199
 
 
200
 
#define ATOI2(ar)       ((ar)[0] - '0') * 10 + ((ar)[1] - '0'); (ar) += 2;
201
 
 
202
 
/*
203
 
 * read_timestamp --
204
 
 *      Convert a time argument to Epoch seconds.
205
 
 *
206
 
 * Copyright (c) 1993
207
 
 *      The Regents of the University of California.  All rights reserved.
208
 
 *
209
 
 * Redistribution and use in source and binary forms, with or without
210
 
 * modification, are permitted provided that the following conditions
211
 
 * are met:
212
 
 * 1. Redistributions of source code must retain the above copyright
213
 
 *    notice, this list of conditions and the following disclaimer.
214
 
 * 2. Redistributions in binary form must reproduce the above copyright
215
 
 *    notice, this list of conditions and the following disclaimer in the
216
 
 *    documentation and/or other materials provided with the distribution.
217
 
 * 3. Neither the name of the University nor the names of its contributors
218
 
 *    may be used to endorse or promote products derived from this software
219
 
 *    without specific prior written permission.
220
 
 *
221
 
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
222
 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
223
 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
224
 
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
225
 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
226
 
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
227
 
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
228
 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
229
 
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
230
 
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
231
 
 * SUCH DAMAGE.
232
 
 */
233
 
int
234
 
db_recover_read_timestamp(progname, arg, timep)
235
 
        const char *progname;
236
 
        char *arg;
237
 
        time_t *timep;
238
 
{
239
 
        struct tm *t;
240
 
        time_t now;
241
 
        int yearset;
242
 
        char *p;
243
 
                                        /* Start with the current time. */
244
 
        (void)time(&now);
245
 
        if ((t = localtime(&now)) == NULL) {
246
 
                fprintf(stderr,
247
 
                    "%s: localtime: %s\n", progname, strerror(errno));
248
 
                return (EXIT_FAILURE);
249
 
        }
250
 
                                        /* [[CC]YY]MMDDhhmm[.SS] */
251
 
        if ((p = strchr(arg, '.')) == NULL)
252
 
                t->tm_sec = 0;          /* Seconds defaults to 0. */
253
 
        else {
254
 
                if (strlen(p + 1) != 2)
255
 
                        goto terr;
256
 
                *p++ = '\0';
257
 
                t->tm_sec = ATOI2(p);
258
 
        }
259
 
 
260
 
        yearset = 0;
261
 
        switch(strlen(arg)) {
262
 
        case 12:                        /* CCYYMMDDhhmm */
263
 
                t->tm_year = ATOI2(arg);
264
 
                t->tm_year *= 100;
265
 
                yearset = 1;
266
 
                /* FALLTHROUGH */
267
 
        case 10:                        /* YYMMDDhhmm */
268
 
                if (yearset) {
269
 
                        yearset = ATOI2(arg);
270
 
                        t->tm_year += yearset;
271
 
                } else {
272
 
                        yearset = ATOI2(arg);
273
 
                        if (yearset < 69)
274
 
                                t->tm_year = yearset + 2000;
275
 
                        else
276
 
                                t->tm_year = yearset + 1900;
277
 
                }
278
 
                t->tm_year -= 1900;     /* Convert to UNIX time. */
279
 
                /* FALLTHROUGH */
280
 
        case 8:                         /* MMDDhhmm */
281
 
                t->tm_mon = ATOI2(arg);
282
 
                --t->tm_mon;            /* Convert from 01-12 to 00-11 */
283
 
                t->tm_mday = ATOI2(arg);
284
 
                t->tm_hour = ATOI2(arg);
285
 
                t->tm_min = ATOI2(arg);
286
 
                break;
287
 
        default:
288
 
                goto terr;
289
 
        }
290
 
 
291
 
        t->tm_isdst = -1;               /* Figure out DST. */
292
 
 
293
 
        *timep = mktime(t);
294
 
        if (*timep == -1) {
295
 
terr:           fprintf(stderr,
296
 
        "%s: out of range or illegal time specification: [[CC]YY]MMDDhhmm[.SS]",
297
 
                    progname);
298
 
                return (EXIT_FAILURE);
299
 
        }
300
 
        return (0);
301
 
}
302
 
 
303
 
int
304
 
db_recover_usage()
305
 
{
306
 
        (void)fprintf(stderr, "%s\n",
307
 
"usage: db_recover [-ceVv] [-h home] [-P password] [-t [[CC]YY]MMDDhhmm[.SS]]");
308
 
        return (EXIT_FAILURE);
309
 
}
310
 
 
311
 
int
312
 
db_recover_version_check(progname)
313
 
        const char *progname;
314
 
{
315
 
        int v_major, v_minor, v_patch;
316
 
 
317
 
        /* Make sure we're loaded with the right version of the DB library. */
318
 
        (void)db_version(&v_major, &v_minor, &v_patch);
319
 
        if (v_major != DB_VERSION_MAJOR ||
320
 
            v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
321
 
                fprintf(stderr,
322
 
        "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
323
 
                    progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
324
 
                    DB_VERSION_PATCH, v_major, v_minor, v_patch);
325
 
                return (EXIT_FAILURE);
326
 
        }
327
 
        return (0);
328
 
}