]>
Commit | Line | Data |
---|---|---|
91ee86a9 JR |
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 | ||
fb95de52 JR |
8 | int version_check __P((void)); |
9 | ||
91ee86a9 JR |
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 | ||
fb95de52 JR |
25 | if ((ret = version_check()) != 0) |
26 | return (EXIT_FAILURE); | |
27 | ||
91ee86a9 JR |
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"; | |
fb95de52 | 35 | while ((ch = getopt(argc, argv, "h:d:qV")) != EOF) |
91ee86a9 JR |
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; | |
fb95de52 JR |
46 | case 'V': |
47 | printf("%s\n", db_version(NULL, NULL, NULL)); | |
48 | return (EXIT_SUCCESS); | |
91ee86a9 JR |
49 | case '?': |
50 | default: | |
51 | (void)fprintf(stderr, "usage: %s [-h home] [-d data_dir]\n", progname); | |
ce677e41 | 52 | return (1); |
91ee86a9 JR |
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); | |
ce677e41 | 59 | return (1); |
91ee86a9 JR |
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)); | |
ce677e41 | 69 | return (1); |
91ee86a9 JR |
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); | |
ce677e41 | 85 | return (1); |
91ee86a9 JR |
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); | |
ce677e41 | 95 | #if 0 |
91ee86a9 | 96 | if (ret == DB_VERSION_MISMATCH) { |
ce677e41 JR |
97 | #else |
98 | if (ret != 0) { | |
99 | #endif | |
91ee86a9 JR |
100 | return (1); |
101 | } | |
102 | ||
103 | return (0); | |
104 | } | |
fb95de52 JR |
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 | } |