~ubuntu-branches/ubuntu/edgy/rpm/edgy

« back to all changes in this revision

Viewing changes to db/db_archive/db_archive.c

  • Committer: Bazaar Package Importer
  • Author(s): Joey Hess
  • Date: 2002-01-22 20:56:57 UTC
  • Revision ID: james.westby@ubuntu.com-20020122205657-l74j50mr9z8ofcl5
Tags: upstream-4.0.3
ImportĀ upstreamĀ versionĀ 4.0.3

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-2001
 
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-2001\nSleepycat Software Inc.  All rights reserved.\n";
 
13
static const char revid[] =
 
14
    "$Id: db_archive.c,v 11.23 2001/05/10 17:13:55 bostic Exp $";
 
15
#endif
 
16
 
 
17
#ifndef NO_SYSTEM_INCLUDES
 
18
#include <sys/types.h>
 
19
 
 
20
#include <stdlib.h>
 
21
#include <stdio.h>
 
22
#include <unistd.h>
 
23
#endif
 
24
 
 
25
#include "db_int.h"
 
26
#include "common_ext.h"
 
27
#include "clib_ext.h"
 
28
 
 
29
int      main __P((int, char *[]));
 
30
void     usage __P((void));
 
31
void     version_check __P((void));
 
32
 
 
33
DB_ENV  *dbenv;
 
34
const char
 
35
        *progname = "db_archive";                       /* Program name. */
 
36
 
 
37
int
 
38
main(argc, argv)
 
39
        int argc;
 
40
        char *argv[];
 
41
{
 
42
        extern char *optarg;
 
43
        extern int optind;
 
44
        u_int32_t flags;
 
45
        int ch, e_close, exitval, ret, verbose;
 
46
        char **file, *home, **list;
 
47
 
 
48
        version_check();
 
49
 
 
50
        flags = 0;
 
51
        e_close = exitval = verbose = 0;
 
52
        home = NULL;
 
53
        while ((ch = getopt(argc, argv, "ah:lsVv")) != EOF)
 
54
                switch (ch) {
 
55
                case 'a':
 
56
                        LF_SET(DB_ARCH_ABS);
 
57
                        break;
 
58
                case 'h':
 
59
                        home = optarg;
 
60
                        break;
 
61
                case 'l':
 
62
                        LF_SET(DB_ARCH_LOG);
 
63
                        break;
 
64
                case 's':
 
65
                        LF_SET(DB_ARCH_DATA);
 
66
                        break;
 
67
                case 'V':
 
68
                        printf("%s\n", db_version(NULL, NULL, NULL));
 
69
                        return (EXIT_SUCCESS);
 
70
                case 'v':
 
71
                        verbose = 1;
 
72
                        break;
 
73
                case '?':
 
74
                default:
 
75
                        usage();
 
76
                }
 
77
        argc -= optind;
 
78
        argv += optind;
 
79
 
 
80
        if (argc != 0)
 
81
                usage();
 
82
 
 
83
        /* Handle possible interruptions. */
 
84
        __db_util_siginit();
 
85
 
 
86
        /*
 
87
         * Create an environment object and initialize it for error
 
88
         * reporting.
 
89
         */
 
90
        if ((ret = db_env_create(&dbenv, 0)) != 0) {
 
91
                fprintf(stderr,
 
92
                    "%s: db_env_create: %s\n", progname, db_strerror(ret));
 
93
                goto shutdown;
 
94
        }
 
95
        e_close = 1;
 
96
 
 
97
        dbenv->set_errfile(dbenv, stderr);
 
98
        dbenv->set_errpfx(dbenv, progname);
 
99
 
 
100
        if (verbose)
 
101
                (void)dbenv->set_verbose(dbenv, DB_VERB_CHKPOINT, 1);
 
102
 
 
103
        /*
 
104
         * If attaching to a pre-existing environment fails, create a
 
105
         * private one and try again.
 
106
         */
 
107
        if ((ret = dbenv->open(dbenv,
 
108
            home, DB_JOINENV | DB_USE_ENVIRON, 0)) != 0 &&
 
109
            (ret = dbenv->open(dbenv, home, DB_CREATE |
 
110
            DB_INIT_LOG | DB_INIT_TXN | DB_PRIVATE | DB_USE_ENVIRON, 0)) != 0) {
 
111
                dbenv->err(dbenv, ret, "open");
 
112
                goto shutdown;
 
113
        }
 
114
 
 
115
        /* Get the list of names. */
 
116
        if ((ret = log_archive(dbenv, &list, flags)) != 0) {
 
117
                dbenv->err(dbenv, ret, "log_archive");
 
118
                goto shutdown;
 
119
        }
 
120
 
 
121
        /* Print the list of names. */
 
122
        if (list != NULL) {
 
123
                for (file = list; *file != NULL; ++file)
 
124
                        printf("%s\n", *file);
 
125
                __os_free(dbenv, list, 0);
 
126
        }
 
127
 
 
128
        if (0) {
 
129
shutdown:       exitval = 1;
 
130
        }
 
131
        if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
 
132
                exitval = 1;
 
133
                fprintf(stderr,
 
134
                    "%s: dbenv->close: %s\n", progname, db_strerror(ret));
 
135
        }
 
136
 
 
137
        /* Resend any caught signal. */
 
138
        __db_util_sigresend();
 
139
 
 
140
        return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
 
141
}
 
142
 
 
143
void
 
144
usage()
 
145
{
 
146
        (void)fprintf(stderr, "usage: db_archive [-alsVv] [-h home]\n");
 
147
        exit(EXIT_FAILURE);
 
148
}
 
149
 
 
150
void
 
151
version_check()
 
152
{
 
153
        int v_major, v_minor, v_patch;
 
154
 
 
155
        /* Make sure we're loaded with the right version of the DB library. */
 
156
        (void)db_version(&v_major, &v_minor, &v_patch);
 
157
        if (v_major != DB_VERSION_MAJOR ||
 
158
            v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
 
159
                fprintf(stderr,
 
160
        "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
 
161
                    progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
 
162
                    DB_VERSION_PATCH, v_major, v_minor, v_patch);
 
163
                exit(EXIT_FAILURE);
 
164
        }
 
165
}