summaryrefslogtreecommitdiff
path: root/bdb/db_deadlock
diff options
context:
space:
mode:
authorram@mysql.r18.ru <>2002-10-30 15:57:05 +0400
committerram@mysql.r18.ru <>2002-10-30 15:57:05 +0400
commit5e09392faa62ea38baa4bd46de5e4183da538e79 (patch)
tree6881a3cca88bea0bb9eeffd5aae34be437152786 /bdb/db_deadlock
parent1c0f1712ca4869b537ada297930ef01dcb039bb9 (diff)
downloadmariadb-git-5e09392faa62ea38baa4bd46de5e4183da538e79.tar.gz
BDB 4.1.24
Diffstat (limited to 'bdb/db_deadlock')
-rw-r--r--bdb/db_deadlock/db_deadlock.c118
1 files changed, 65 insertions, 53 deletions
diff --git a/bdb/db_deadlock/db_deadlock.c b/bdb/db_deadlock/db_deadlock.c
index ac151db127a..523918b9ea4 100644
--- a/bdb/db_deadlock/db_deadlock.c
+++ b/bdb/db_deadlock/db_deadlock.c
@@ -1,7 +1,7 @@
/*-
* See the file LICENSE for redistribution information.
*
- * Copyright (c) 1996, 1997, 1998, 1999, 2000
+ * Copyright (c) 1996-2002
* Sleepycat Software. All rights reserved.
*/
@@ -9,9 +9,9 @@
#ifndef lint
static const char copyright[] =
- "Copyright (c) 1996-2000\nSleepycat Software Inc. All rights reserved.\n";
+ "Copyright (c) 1996-2002\nSleepycat Software Inc. All rights reserved.\n";
static const char revid[] =
- "$Id: db_deadlock.c,v 11.19 2001/01/18 18:36:57 bostic Exp $";
+ "$Id: db_deadlock.c,v 11.38 2002/08/08 03:50:32 bostic Exp $";
#endif
#ifndef NO_SYSTEM_INCLUDES
@@ -31,19 +31,15 @@ static const char revid[] =
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#endif
#include "db_int.h"
-#include "clib_ext.h"
-int main __P((int, char *[]));
-void usage __P((void));
-void version_check __P((void));
-
-DB_ENV *dbenv;
-const char
- *progname = "db_deadlock"; /* Program name. */
+int main __P((int, char *[]));
+int usage __P((void));
+int version_check __P((const char *));
int
main(argc, argv)
@@ -52,36 +48,49 @@ main(argc, argv)
{
extern char *optarg;
extern int optind;
+ const char *progname = "db_deadlock";
+ DB_ENV *dbenv;
u_int32_t atype;
time_t now;
- long usecs;
- u_int32_t flags;
+ long secs, usecs;
int ch, e_close, exitval, ret, verbose;
- char *home, *logfile;
+ char *home, *logfile, *str;
- version_check();
+ if ((ret = version_check(progname)) != 0)
+ return (ret);
atype = DB_LOCK_DEFAULT;
home = logfile = NULL;
- usecs = 0;
- flags = 0;
+ secs = usecs = 0;
e_close = exitval = verbose = 0;
while ((ch = getopt(argc, argv, "a:h:L:t:Vvw")) != EOF)
switch (ch) {
case 'a':
switch (optarg[0]) {
+ case 'e':
+ atype = DB_LOCK_EXPIRE;
+ break;
+ case 'm':
+ atype = DB_LOCK_MAXLOCKS;
+ break;
+ case 'n':
+ atype = DB_LOCK_MINLOCKS;
+ break;
case 'o':
atype = DB_LOCK_OLDEST;
break;
+ case 'w':
+ atype = DB_LOCK_MINWRITE;
+ break;
case 'y':
atype = DB_LOCK_YOUNGEST;
break;
default:
- usage();
+ return (usage());
/* NOTREACHED */
}
if (optarg[1] != '\0')
- usage();
+ return (usage());
break;
case 'h':
home = optarg;
@@ -90,42 +99,40 @@ main(argc, argv)
logfile = optarg;
break;
case 't':
- (void)__db_getlong(NULL,
- progname, optarg, 1, LONG_MAX, &usecs);
- usecs *= 1000000;
+ if ((str = strchr(optarg, '.')) != NULL) {
+ *str++ = '\0';
+ if (*str != '\0' && __db_getlong(
+ NULL, progname, str, 0, LONG_MAX, &usecs))
+ return (EXIT_FAILURE);
+ }
+ if (*optarg != '\0' && __db_getlong(
+ NULL, progname, optarg, 0, LONG_MAX, &secs))
+ return (EXIT_FAILURE);
+ if (secs == 0 && usecs == 0)
+ return (usage());
+
break;
+
case 'V':
printf("%s\n", db_version(NULL, NULL, NULL));
- exit(0);
+ return (EXIT_SUCCESS);
case 'v':
verbose = 1;
break;
- case 'w':
- LF_SET(DB_LOCK_CONFLICT);
+ case 'w': /* Undocumented. */
+ /* Detect every 100ms (100000 us) when polling. */
+ secs = 0;
+ usecs = 100000;
break;
case '?':
default:
- usage();
+ return (usage());
}
argc -= optind;
argv += optind;
if (argc != 0)
- usage();
-
- if (usecs == 0 && !LF_ISSET(DB_LOCK_CONFLICT)) {
- fprintf(stderr,
- "%s: at least one of -t and -w must be specified\n",
- progname);
- exit(1);
- }
-
- /*
- * We detect every 100ms (100000 us) when we're running in
- * DB_LOCK_CONFLICT mode.
- */
- if (usecs == 0)
- usecs = 100000;
+ return (usage());
/* Handle possible interruptions. */
__db_util_siginit();
@@ -166,13 +173,15 @@ main(argc, argv)
dbenv->errx(dbenv, "running at %.24s", ctime(&now));
}
- if ((ret = lock_detect(dbenv, flags, atype, NULL)) != 0) {
- dbenv->err(dbenv, ret, "lock_detect");
+ if ((ret = dbenv->lock_detect(dbenv, 0, atype, NULL)) != 0) {
+ dbenv->err(dbenv, ret, "DB_ENV->lock_detect");
goto shutdown;
}
- /* Make a pass every "usecs" usecs. */
- (void)__os_sleep(dbenv, 0, usecs);
+ /* Make a pass every "secs" secs and "usecs" usecs. */
+ if (secs == 0 && usecs == 0)
+ break;
+ (void)__os_sleep(dbenv, secs, usecs);
}
if (0) {
@@ -193,19 +202,21 @@ shutdown: exitval = 1;
/* Resend any caught signal. */
__db_util_sigresend();
- return (exitval);
+ return (exitval == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}
-void
+int
usage()
{
- (void)fprintf(stderr,
- "usage: db_deadlock [-Vvw] [-a o | y] [-h home] [-L file] [-t sec]\n");
- exit(1);
+ (void)fprintf(stderr, "%s\n\t%s\n",
+ "usage: db_deadlock [-Vv]",
+ "[-a e | m | n | o | w | y] [-h home] [-L file] [-t sec.usec]");
+ return (EXIT_FAILURE);
}
-void
-version_check()
+int
+version_check(progname)
+ const char *progname;
{
int v_major, v_minor, v_patch;
@@ -217,6 +228,7 @@ version_check()
"%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
DB_VERSION_PATCH, v_major, v_minor, v_patch);
- exit (1);
+ return (EXIT_FAILURE);
}
+ return (0);
}