]> git.pld-linux.org Git - packages/rpm.git/blob - rpmdb_checkversion.c
- updated javadeps patch, removed namespaceccompare (code differs to much)
[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 int     version_check __P((void));
9
10 const char *progname = "rpmdb_checkversion";            /* Program name. */
11
12 /*
13  * A very simple program to check for a Berkeley DB environment mismatch.
14  */
15 int
16 main(int argc, char *argv[])
17 {
18         extern char *optarg;
19         extern int optind;
20         const char *data_dir, *home;
21         int ch, quiet;
22         DB_ENV *dbenv;
23         int ret;
24
25         if ((ret = version_check()) != 0)
26                 return (EXIT_FAILURE);
27
28         /*
29          * All of the shared database files live in home, but
30          * data files will live in data_dir.
31          */
32         quiet = 0;
33         home = "/var/lib/rpm";
34         data_dir = "/var/lib/rpm";
35         while ((ch = getopt(argc, argv, "h:d:qV")) != EOF)
36                 switch (ch) {
37                 case 'h':
38                         home = optarg;
39                         break;
40                 case 'd':
41                         data_dir = optarg;
42                         break;
43                 case 'q':
44                         quiet = 1;
45                         break;
46                 case 'V':
47                         printf("%s\n", db_version(NULL, NULL, NULL));
48                         return (EXIT_SUCCESS);
49                 case '?':
50                 default:
51                         (void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
52                         return (1);
53                 }
54         argc -= optind;
55         argv += optind;
56
57         if (argc != 0) {
58                 (void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname);
59                 return (1);
60         }
61
62         /*
63          * Create an environment object and initialize it for error
64          * reporting.
65          */
66         if ((ret = db_env_create(&dbenv, 0)) != 0) {
67                 if (!quiet)
68                         fprintf(stderr, "%s: %s\n", progname, db_strerror(ret));
69                 return (1);
70         }
71         if (quiet) {
72                 dbenv->set_errfile(dbenv, NULL);
73         } else {
74                 dbenv->set_errfile(dbenv, stderr);
75         }
76         dbenv->set_errpfx(dbenv, progname);
77
78         /*
79          * We want to specify the shared memory buffer pool cachesize,
80          * but everything else is the default.
81          */
82         if ((ret = dbenv->set_cachesize(dbenv, 0, 64 * 1024, 0)) != 0) {
83                 dbenv->err(dbenv, ret, "set_cachesize");
84                 dbenv->close(dbenv, 0);
85                 return (1);
86         }
87
88         /* Databases are in a subdirectory. */
89         (void)dbenv->set_data_dir(dbenv, data_dir);
90
91         /* Open the environment with full transactional support. */
92         ret = dbenv->open(dbenv, home, DB_INIT_MPOOL, 0644);
93         /* Close the environment handle. */
94         dbenv->close(dbenv, 0);
95 #if 0
96         if (ret == DB_VERSION_MISMATCH) {
97 #else
98         if (ret != 0) {
99 #endif
100                 return (1);
101         }
102
103         return (0);
104 }
105
106 int
107 version_check()
108 {
109         int v_major, v_minor, v_patch;
110
111         /* Make sure we're loaded with the right version of the DB library. */
112         (void)db_version(&v_major, &v_minor, &v_patch);
113         if (v_major != DB_VERSION_MAJOR || v_minor != DB_VERSION_MINOR) {
114                 fprintf(stderr,
115                     "%s: version %d.%d doesn't match library version %d.%d\n",
116                     progname, DB_VERSION_MAJOR,
117                     DB_VERSION_MINOR, v_major, v_minor);
118                 return (EXIT_FAILURE);
119         }
120         return (0);
121 }
This page took 0.033629 seconds and 3 git commands to generate.