~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to libdb/build_vxworks/db_deadlock/db_deadlock.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

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-2002
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-2002\nSleepycat Software Inc.  All rights reserved.\n";
13
 
static const char revid[] =
14
 
    "$Id$";
15
 
#endif
16
 
 
17
 
#ifndef NO_SYSTEM_INCLUDES
18
 
#include <sys/types.h>
19
 
 
20
 
#if TIME_WITH_SYS_TIME
21
 
#include <sys/time.h>
22
 
#include <time.h>
23
 
#else
24
 
#if HAVE_SYS_TIME_H
25
 
#include <sys/time.h>
26
 
#else
27
 
#include <time.h>
28
 
#endif
29
 
#endif
30
 
 
31
 
#include <limits.h>
32
 
#include <stdio.h>
33
 
#include <stdlib.h>
34
 
#include <string.h>
35
 
#include <unistd.h>
36
 
#endif
37
 
 
38
 
#include "db_int.h"
39
 
 
40
 
int db_deadlock_main __P((int, char *[]));
41
 
int db_deadlock_usage __P((void));
42
 
int db_deadlock_version_check __P((const char *));
43
 
 
44
 
int
45
 
db_deadlock(args)
46
 
        char *args;
47
 
{
48
 
        int argc;
49
 
        char **argv;
50
 
 
51
 
        __db_util_arg("db_deadlock", args, &argc, &argv);
52
 
        return (db_deadlock_main(argc, argv) ? EXIT_FAILURE : EXIT_SUCCESS);
53
 
}
54
 
 
55
 
#include <stdio.h>
56
 
#define ERROR_RETURN    ERROR
57
 
 
58
 
int
59
 
db_deadlock_main(argc, argv)
60
 
        int argc;
61
 
        char *argv[];
62
 
{
63
 
        extern char *optarg;
64
 
        extern int optind, __db_getopt_reset;
65
 
        const char *progname = "db_deadlock";
66
 
        DB_ENV  *dbenv;
67
 
        u_int32_t atype;
68
 
        time_t now;
69
 
        long secs, usecs;
70
 
        int ch, e_close, exitval, ret, verbose;
71
 
        char *home, *logfile, *str;
72
 
 
73
 
        if ((ret = db_deadlock_version_check(progname)) != 0)
74
 
                return (ret);
75
 
 
76
 
        atype = DB_LOCK_DEFAULT;
77
 
        home = logfile = NULL;
78
 
        secs = usecs = 0;
79
 
        e_close = exitval = verbose = 0;
80
 
        __db_getopt_reset = 1;
81
 
        while ((ch = getopt(argc, argv, "a:h:L:t:Vvw")) != EOF)
82
 
                switch (ch) {
83
 
                case 'a':
84
 
                        switch (optarg[0]) {
85
 
                        case 'e':
86
 
                                atype = DB_LOCK_EXPIRE;
87
 
                                break;
88
 
                        case 'm':
89
 
                                atype = DB_LOCK_MAXLOCKS;
90
 
                                break;
91
 
                        case 'n':
92
 
                                atype = DB_LOCK_MINLOCKS;
93
 
                                break;
94
 
                        case 'o':
95
 
                                atype = DB_LOCK_OLDEST;
96
 
                                break;
97
 
                        case 'w':
98
 
                                atype = DB_LOCK_MINWRITE;
99
 
                                break;
100
 
                        case 'y':
101
 
                                atype = DB_LOCK_YOUNGEST;
102
 
                                break;
103
 
                        default:
104
 
                                return (db_deadlock_usage());
105
 
                                /* NOTREACHED */
106
 
                        }
107
 
                        if (optarg[1] != '\0')
108
 
                                return (db_deadlock_usage());
109
 
                        break;
110
 
                case 'h':
111
 
                        home = optarg;
112
 
                        break;
113
 
                case 'L':
114
 
                        logfile = optarg;
115
 
                        break;
116
 
                case 't':
117
 
                        if ((str = strchr(optarg, '.')) != NULL) {
118
 
                                *str++ = '\0';
119
 
                                if (*str != '\0' && __db_getlong(
120
 
                                    NULL, progname, str, 0, LONG_MAX, &usecs))
121
 
                                        return (EXIT_FAILURE);
122
 
                        }
123
 
                        if (*optarg != '\0' && __db_getlong(
124
 
                            NULL, progname, optarg, 0, LONG_MAX, &secs))
125
 
                                return (EXIT_FAILURE);
126
 
                        if (secs == 0 && usecs == 0)
127
 
                                return (db_deadlock_usage());
128
 
 
129
 
                        break;
130
 
 
131
 
                case 'V':
132
 
                        printf("%s\n", db_version(NULL, NULL, NULL));
133
 
                        return (EXIT_SUCCESS);
134
 
                case 'v':
135
 
                        verbose = 1;
136
 
                        break;
137
 
                case 'w':                       /* Undocumented. */
138
 
                        /* Detect every 100ms (100000 us) when polling. */
139
 
                        secs = 0;
140
 
                        usecs = 100000;
141
 
                        break;
142
 
                case '?':
143
 
                default:
144
 
                        return (db_deadlock_usage());
145
 
                }
146
 
        argc -= optind;
147
 
        argv += optind;
148
 
 
149
 
        if (argc != 0)
150
 
                return (db_deadlock_usage());
151
 
 
152
 
        /* Handle possible interruptions. */
153
 
        __db_util_siginit();
154
 
 
155
 
        /* Log our process ID. */
156
 
        if (logfile != NULL && __db_util_logset(progname, logfile))
157
 
                goto shutdown;
158
 
 
159
 
        /*
160
 
         * Create an environment object and initialize it for error
161
 
         * reporting.
162
 
         */
163
 
        if ((ret = db_env_create(&dbenv, 0)) != 0) {
164
 
                fprintf(stderr,
165
 
                    "%s: db_env_create: %s\n", progname, db_strerror(ret));
166
 
                goto shutdown;
167
 
        }
168
 
        e_close = 1;
169
 
 
170
 
        dbenv->set_errfile(dbenv, stderr);
171
 
        dbenv->set_errpfx(dbenv, progname);
172
 
 
173
 
        if (verbose) {
174
 
                (void)dbenv->set_verbose(dbenv, DB_VERB_DEADLOCK, 1);
175
 
                (void)dbenv->set_verbose(dbenv, DB_VERB_WAITSFOR, 1);
176
 
        }
177
 
 
178
 
        /* An environment is required. */
179
 
        if ((ret = dbenv->open(dbenv, home,
180
 
            DB_JOINENV | DB_USE_ENVIRON, 0)) != 0) {
181
 
                dbenv->err(dbenv, ret, "open");
182
 
                goto shutdown;
183
 
        }
184
 
 
185
 
        while (!__db_util_interrupted()) {
186
 
                if (verbose) {
187
 
                        (void)time(&now);
188
 
                        dbenv->errx(dbenv, "running at %.24s", ctime(&now));
189
 
                }
190
 
 
191
 
                if ((ret = dbenv->lock_detect(dbenv, 0, atype, NULL)) != 0) {
192
 
                        dbenv->err(dbenv, ret, "DB_ENV->lock_detect");
193
 
                        goto shutdown;
194
 
                }
195
 
 
196
 
                /* Make a pass every "secs" secs and "usecs" usecs. */
197
 
                if (secs == 0 && usecs == 0)
198
 
                        break;
199
 
                (void)__os_sleep(dbenv, secs, usecs);
200
 
        }
201
 
 
202
 
        if (0) {
203
 
shutdown:       exitval = 1;
204
 
        }
205
 
 
206
 
        /* Clean up the logfile. */
207
 
        if (logfile != NULL)
208
 
                remove(logfile);
209
 
 
210
 
        /* Clean up the environment. */
211
 
        if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
212
 
                exitval = 1;
213
 
                fprintf(stderr,
214
 
                    "%s: dbenv->close: %s\n", progname, db_strerror(ret));
215
 
        }
216
 
 
217
 
        /* Resend any caught signal. */
218
 
        __db_util_sigresend();
219
 
 
220
 
        return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
221
 
}
222
 
 
223
 
int
224
 
db_deadlock_usage()
225
 
{
226
 
        (void)fprintf(stderr, "%s\n\t%s\n",
227
 
            "usage: db_deadlock [-Vv]",
228
 
            "[-a e | m | n | o | w | y] [-h home] [-L file] [-t sec.usec]");
229
 
        return (EXIT_FAILURE);
230
 
}
231
 
 
232
 
int
233
 
db_deadlock_version_check(progname)
234
 
        const char *progname;
235
 
{
236
 
        int v_major, v_minor, v_patch;
237
 
 
238
 
        /* Make sure we're loaded with the right version of the DB library. */
239
 
        (void)db_version(&v_major, &v_minor, &v_patch);
240
 
        if (v_major != DB_VERSION_MAJOR ||
241
 
            v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
242
 
                fprintf(stderr,
243
 
        "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
244
 
                    progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
245
 
                    DB_VERSION_PATCH, v_major, v_minor, v_patch);
246
 
                return (EXIT_FAILURE);
247
 
        }
248
 
        return (0);
249
 
}