]> git.pld-linux.org Git - packages/rpm.git/blob - rpmdb_checkversion.c
- barf on any error, it's better to make one too many unneccessary
[packages/rpm.git] / rpmdb_checkversion.c
1 #include <sys/types.h>
2 #include <stddef.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <db.h>
7
8 const char *progname = "rpmdb_checkversion";            /* Program name. */
9
10 /*
11  * A very simple program to check for a Berkeley DB environment mismatch.
12  */
13 int
14 main(int argc, char *argv[])
15 {
16         extern char *optarg;
17         extern int optind;
18         const char *data_dir, *home;
19         int ch, quiet;
20         DB_ENV *dbenv;
21         int ret;
22
23         /*
24          * All of the shared database files live in home, but
25          * data files will live in data_dir.
26          */
27         quiet = 0;
28         home = "/var/lib/rpm";
29         data_dir = "/var/lib/rpm";
30         while ((ch = getopt(argc, argv, "h:d:q")) != EOF)
31                 switch (ch) {
32                 case 'h':
33                         home = optarg;
34                         break;
35                 case 'd':
36                         data_dir = optarg;
37                         break;
38                 case 'q':
39                         quiet = 1;
40                         break;
41                 case '?':
42                 default:
43                         (void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
44                         return (1);
45                 }
46         argc -= optind;
47         argv += optind;
48
49         if (argc != 0) {
50                 (void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
51                 return (1);
52         }
53
54         /*
55          * Create an environment object and initialize it for error
56          * reporting.
57          */
58         if ((ret = db_env_create(&dbenv, 0)) != 0) {
59                 if (!quiet)
60                         fprintf(stderr, "%s: %s\n", progname, db_strerror(ret));
61                 return (1);
62         }
63         if (quiet) {
64                 dbenv->set_errfile(dbenv, NULL);
65         } else {
66                 dbenv->set_errfile(dbenv, stderr);
67         }
68         dbenv->set_errpfx(dbenv, progname);
69
70         /*
71          * We want to specify the shared memory buffer pool cachesize,
72          * but everything else is the default.
73          */
74         if ((ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0)) != 0) {
75                 dbenv->err(dbenv, ret, "set_cachesize");
76                 dbenv->close(dbenv, 0);
77                 return (1);
78         }
79
80         /* Databases are in a subdirectory. */
81         (void)dbenv->set_data_dir(dbenv, data_dir);
82
83         /* Open the environment with full transactional support. */
84         ret = dbenv->open(dbenv, home, DB_INIT_MPOOL, 0644);
85         /* Close the environment handle. */
86         dbenv->close(dbenv, 0);
87 #if 0
88         if (ret == DB_VERSION_MISMATCH) {
89 #else
90         if (ret != 0) {
91 #endif
92                 return (1);
93         }
94
95         return (0);
96 }
This page took 0.03617 seconds and 4 git commands to generate.