]> sourceware.org Git - glibc.git/blob - db2/progs/db_archive/db_archive.c
Update.
[glibc.git] / db2 / progs / db_archive / db_archive.c
1 /*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 1996, 1997
5 * Sleepycat Software. All rights reserved.
6 */
7
8 #include "config.h"
9
10 #ifndef lint
11 static const char copyright[] =
12 "@(#) Copyright (c) 1997\n\
13 Sleepycat Software Inc. All rights reserved.\n";
14 static const char sccsid[] = "@(#)db_archive.c 10.12 (Sleepycat) 7/25/97";
15 #endif
16
17 #ifndef NO_SYSTEM_INCLUDES
18 #include <sys/types.h>
19
20 #include <errno.h>
21 #include <signal.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <unistd.h>
26 #endif
27
28 #include "db_int.h"
29 #include "shqueue.h"
30 #include "log.h"
31 #include "db_dispatch.h"
32 #include "clib_ext.h"
33 #include "common_ext.h"
34
35 DB_ENV *db_init __P((char *, int));
36 void onint __P((int));
37 void siginit __P((void));
38 void usage __P((void));
39 int main __P((int, char *[]));
40
41 int interrupted;
42 const char *progname = "db_archive"; /* Program name. */
43
44 int
45 main(argc, argv)
46 int argc;
47 char *argv[];
48 {
49 extern char *optarg;
50 extern int optind;
51 DB_ENV *dbenv;
52 int ch, flags, verbose;
53 char *home, **list;
54
55 flags = verbose = 0;
56 home = NULL;
57 while ((ch = getopt(argc, argv, "ah:lsv")) != EOF)
58 switch (ch) {
59 case 'a':
60 flags |= DB_ARCH_ABS;
61 break;
62 case 'h':
63 home = optarg;
64 break;
65 case 'l':
66 flags |= DB_ARCH_LOG;
67 break;
68 case 's':
69 flags |= DB_ARCH_DATA;
70 break;
71 case 'v':
72 verbose = 1;
73 break;
74 case '?':
75 default:
76 usage();
77 }
78 argc -= optind;
79 argv += optind;
80
81 if (argc != 0)
82 usage();
83
84 /* Initialize the environment. */
85 dbenv = db_init(home, verbose);
86
87 /* Get the list of names. */
88 if ((errno = log_archive(dbenv->lg_info, &list, flags, NULL)) != 0) {
89 (void)db_appexit(dbenv);
90 err(1, "log_archive");
91 }
92
93 /* Print the names. */
94 if (list != NULL)
95 for (; *list != NULL; ++list)
96 printf("%s\n", *list);
97
98 return (db_appexit(dbenv) ? 1 : 0);
99 }
100
101 /*
102 * db_init --
103 * Initialize the environment.
104 */
105 DB_ENV *
106 db_init(home, verbose)
107 char *home;
108 int verbose;
109 {
110 DB_ENV *dbenv;
111
112 if ((dbenv = (DB_ENV *)calloc(sizeof(DB_ENV), 1)) == NULL) {
113 errno = ENOMEM;
114 err(1, NULL);
115 }
116 dbenv->db_errfile = stderr;
117 dbenv->db_errpfx = progname;
118 dbenv->db_verbose = verbose;
119
120 if ((errno = db_appinit(home, NULL, dbenv,
121 DB_CREATE | DB_INIT_LOG | DB_INIT_TXN | DB_USE_ENVIRON)) != 0)
122 err(1, "db_appinit");
123
124 siginit();
125
126 return (dbenv);
127 }
128
129 /*
130 * siginit --
131 * Initialize the set of signals for which we want to clean up.
132 * Generally, we try not to leave the shared regions locked if
133 * we can.
134 */
135 void
136 siginit()
137 {
138 #ifdef SIGHUP
139 (void)signal(SIGHUP, onint);
140 #endif
141 (void)signal(SIGINT, onint);
142 #ifdef SIGKILL
143 (void)signal(SIGKILL, onint);
144 #endif
145 (void)signal(SIGTERM, onint);
146 }
147
148 /*
149 * oninit --
150 * Interrupt signal handler.
151 */
152 void
153 onint(signo)
154 int signo;
155 {
156 if ((interrupted = signo) == 0)
157 interrupted = SIGINT;
158 }
159
160 void
161 usage()
162 {
163 (void)fprintf(stderr, "usage: db_archive [-alsv] [-h home]\n");
164 exit(1);
165 }
This page took 0.040927 seconds and 5 git commands to generate.