summaryrefslogtreecommitdiff
path: root/db/db_deadlock
diff options
context:
space:
mode:
authorjbj <devnull@localhost>2003-12-15 21:42:09 +0000
committerjbj <devnull@localhost>2003-12-15 21:42:09 +0000
commit8960e3895f7af91126465368dff8fbb36ab4e853 (patch)
tree3c515e39dde0e88edeb806ea87d08524ba25c761 /db/db_deadlock
parent752cac72e220dcad4e6fce39508e714e59e3e0a1 (diff)
downloadlibrpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.tar.gz
librpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.tar.bz2
librpm-tizen-8960e3895f7af91126465368dff8fbb36ab4e853.zip
- upgrade to db-4.2.52.
CVS patchset: 6972 CVS date: 2003/12/15 21:42:09
Diffstat (limited to 'db/db_deadlock')
-rw-r--r--db/db_deadlock/db_deadlock.c135
1 files changed, 73 insertions, 62 deletions
diff --git a/db/db_deadlock/db_deadlock.c b/db/db_deadlock/db_deadlock.c
index ac151db12..8a6f7b7c2 100644
--- a/db/db_deadlock/db_deadlock.c
+++ b/db/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-2003
* 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-2003\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.41 2003/06/17 14:36:44 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,50 @@ 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;
- int ch, e_close, exitval, ret, verbose;
- char *home, *logfile;
+ u_long secs, usecs;
+ int ch, exitval, ret, verbose;
+ char *home, *logfile, *str;
- version_check();
+ if ((ret = version_check(progname)) != 0)
+ return (ret);
+ dbenv = NULL;
atype = DB_LOCK_DEFAULT;
home = logfile = NULL;
- usecs = 0;
- flags = 0;
- e_close = exitval = verbose = 0;
+ secs = usecs = 0;
+ 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 +100,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_getulong(
+ NULL, progname, str, 0, LONG_MAX, &usecs))
+ return (EXIT_FAILURE);
+ }
+ if (*optarg != '\0' && __db_getulong(
+ 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();
@@ -143,7 +151,6 @@ main(argc, argv)
"%s: db_env_create: %s\n", progname, db_strerror(ret));
goto shutdown;
}
- e_close = 1;
dbenv->set_errfile(dbenv, stderr);
dbenv->set_errpfx(dbenv, progname);
@@ -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) {
@@ -181,10 +190,10 @@ shutdown: exitval = 1;
/* Clean up the logfile. */
if (logfile != NULL)
- remove(logfile);
+ (void)remove(logfile);
/* Clean up the environment. */
- if (e_close && (ret = dbenv->close(dbenv, 0)) != 0) {
+ if (dbenv != NULL && (ret = dbenv->close(dbenv, 0)) != 0) {
exitval = 1;
fprintf(stderr,
"%s: dbenv->close: %s\n", progname, db_strerror(ret));
@@ -193,30 +202,32 @@ 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;
/* Make sure we're loaded with the right version of the DB library. */
(void)db_version(&v_major, &v_minor, &v_patch);
- if (v_major != DB_VERSION_MAJOR ||
- v_minor != DB_VERSION_MINOR || v_patch != DB_VERSION_PATCH) {
+ if (v_major != DB_VERSION_MAJOR || v_minor != DB_VERSION_MINOR) {
fprintf(stderr,
- "%s: version %d.%d.%d doesn't match library version %d.%d.%d\n",
+ "%s: version %d.%d doesn't match library version %d.%d\n",
progname, DB_VERSION_MAJOR, DB_VERSION_MINOR,
- DB_VERSION_PATCH, v_major, v_minor, v_patch);
- exit (1);
+ v_major, v_minor);
+ return (EXIT_FAILURE);
}
+ return (0);
}