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

« back to all changes in this revision

Viewing changes to libdb/db_upgrade/db_upgrade.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_upgrade";
40
 
        DB *dbp;
41
 
        DB_ENV *dbenv;
42
 
        u_int32_t flags;
43
 
        int ch, e_close, exitval, nflag, ret, t_ret;
44
 
        char *home, *passwd;
45
 
 
46
 
        if ((ret = version_check(progname)) != 0)
47
 
                return (ret);
48
 
 
49
 
        dbenv = NULL;
50
 
        flags = nflag = 0;
51
 
        e_close = exitval = 0;
52
 
        home = passwd = NULL;
53
 
        while ((ch = getopt(argc, argv, "h:NP:sV")) != EOF)
54
 
                switch (ch) {
55
 
                case 'h':
56
 
                        home = optarg;
57
 
                        break;
58
 
                case 'N':
59
 
                        nflag = 1;
60
 
                        break;
61
 
                case 'P':
62
 
                        passwd = strdup(optarg);
63
 
                        memset(optarg, 0, strlen(optarg));
64
 
                        if (passwd == NULL) {
65
 
                                fprintf(stderr, "%s: strdup: %s\n",
66
 
                                    progname, strerror(errno));
67
 
                                return (EXIT_FAILURE);
68
 
                        }
69
 
                        break;
70
 
                case 's':
71
 
                        LF_SET(DB_DUPSORT);
72
 
                        break;
73
 
                case 'V':
74
 
                        printf("%s\n", db_version(NULL, NULL, NULL));
75
 
                        return (EXIT_SUCCESS);
76
 
                case '?':
77
 
                default:
78
 
                        return (usage());
79
 
                }
80
 
        argc -= optind;
81
 
        argv += optind;
82
 
 
83
 
        if (argc <= 0)
84
 
                return (usage());
85
 
 
86
 
        /* Handle possible interruptions. */
87
 
        __db_util_siginit();
88
 
 
89
 
        /*
90
 
         * Create an environment object and initialize it for error
91
 
         * reporting.
92
 
         */
93
 
        if ((ret = db_env_create(&dbenv, 0)) != 0) {
94
 
                fprintf(stderr, "%s: db_env_create: %s\n",
95
 
                    progname, db_strerror(ret));
96
 
                goto shutdown;
97
 
        }
98
 
        e_close = 1;
99
 
 
100
 
        dbenv->set_errfile(dbenv, stderr);
101
 
        dbenv->set_errpfx(dbenv, progname);
102
 
 
103
 
        if (nflag) {
104
 
                if ((ret = dbenv->set_flags(dbenv, DB_NOLOCKING, 1)) != 0) {
105
 
                        dbenv->err(dbenv, ret, "set_flags: DB_NOLOCKING");
106
 
                        goto shutdown;
107
 
                }
108
 
                if ((ret = dbenv->set_flags(dbenv, DB_NOPANIC, 1)) != 0) {
109
 
                        dbenv->err(dbenv, ret, "set_flags: DB_NOPANIC");
110
 
                        goto shutdown;
111
 
                }
112
 
        }
113
 
 
114
 
        if (passwd != NULL && (ret = dbenv->set_encrypt(dbenv,
115
 
            passwd, DB_ENCRYPT_AES)) != 0) {
116
 
                dbenv->err(dbenv, ret, "set_passwd");
117
 
                goto shutdown;
118
 
        }
119
 
 
120
 
        /*
121
 
         * If attaching to a pre-existing environment fails, create a
122
 
         * private one and try again.
123
 
         */
124
 
        if ((ret = dbenv->open(dbenv,
125
 
            home, DB_JOINENV | DB_USE_ENVIRON, 0)) != 0 &&
126
 
            (ret = dbenv->open(dbenv, home,
127
 
            DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0) {
128
 
                dbenv->err(dbenv, ret, "open");
129
 
                goto shutdown;
130
 
        }
131
 
 
132
 
        for (; !__db_util_interrupted() && argv[0] != NULL; ++argv) {
133
 
                if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
134
 
                        fprintf(stderr,
135
 
                            "%s: db_create: %s\n", progname, db_strerror(ret));
136
 
                        goto shutdown;
137
 
                }
138
 
                dbp->set_errfile(dbp, stderr);
139
 
                dbp->set_errpfx(dbp, progname);
140
 
                if ((ret = dbp->upgrade(dbp, argv[0], flags)) != 0)
141
 
                        dbp->err(dbp, ret, "DB->upgrade: %s", argv[0]);
142
 
                if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0) {
143
 
                        dbenv->err(dbenv, ret, "DB->close: %s", argv[0]);
144
 
                        ret = t_ret;
145
 
                }
146
 
                if (ret != 0)
147
 
                        goto shutdown;
148
 
        }
149
 
 
150
 
        if (0) {
151
 
shutdown:       exitval = 1;
152
 
        }
153
 
        if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
154
 
                exitval = 1;
155
 
                fprintf(stderr,
156
 
                    "%s: dbenv->close: %s\n", progname, db_strerror(ret));
157
 
        }
158
 
 
159
 
        /* Resend any caught signal. */
160
 
        __db_util_sigresend();
161
 
 
162
 
        return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
163
 
}
164
 
 
165
 
int
166
 
usage()
167
 
{
168
 
        fprintf(stderr, "%s\n",
169
 
            "usage: db_upgrade [-NsV] [-h home] [-P password] db_file ...");
170
 
        return (EXIT_FAILURE);
171
 
}
172
 
 
173
 
int
174
 
version_check(progname)
175
 
        const char *progname;
176
 
{
177
 
        int v_major, v_minor, v_patch;
178
 
 
179
 
        /* Make sure we're loaded with the right version of the DB library. */
180
 
        (void)db_version(&v_major, &v_minor, &v_patch);
181
 
        if (v_major != DB_VERSION_MAJOR ||
182
 
            v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
183
 
                fprintf(stderr,
184
 
        "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
185
 
                    progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
186
 
                    DB_VERSION_PATCH, v_major, v_minor, v_patch);
187
 
                return (EXIT_FAILURE);
188
 
        }
189
 
        return (0);
190
 
}