Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/sa - detect duplicate keys when initializing the da...
details: https://anonhg.NetBSD.org/src/rev/f345e64418fa
branches: trunk
changeset: 495492:f345e64418fa
user: christos <christos%NetBSD.org@localhost>
date: Sat Jul 29 19:15:40 2000 +0000
description:
- detect duplicate keys when initializing the database. abort if too many
duplicate keys are found indicating a corrupted database (avoids problem
where sa would loop forever).
- add open flags and mode in dbopen in case someone wants to debug...
diffstat:
usr.sbin/sa/pdb.c | 20 ++++++++++++++++----
usr.sbin/sa/usrdb.c | 20 ++++++++++++++++----
2 files changed, 32 insertions(+), 8 deletions(-)
diffs (111 lines):
diff -r fb504abd90f8 -r f345e64418fa usr.sbin/sa/pdb.c
--- a/usr.sbin/sa/pdb.c Sat Jul 29 19:13:34 2000 +0000
+++ b/usr.sbin/sa/pdb.c Sat Jul 29 19:15:40 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pdb.c,v 1.8 2000/06/14 17:26:24 cgd Exp $ */
+/* $NetBSD: pdb.c,v 1.9 2000/07/29 19:15:40 christos Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pdb.c,v 1.8 2000/06/14 17:26:24 cgd Exp $");
+__RCSID("$NetBSD: pdb.c,v 1.9 2000/07/29 19:15:40 christos Exp $");
#endif
#include <sys/types.h>
@@ -60,8 +60,9 @@
{
DB *saved_pacct_db;
int error;
+ int ndups = 0;
- pacct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, NULL);
+ pacct_db = dbopen(NULL, O_RDWR|O_CREAT|O_TRUNC, 0644, DB_BTREE, NULL);
if (pacct_db == NULL)
return (-1);
@@ -86,12 +87,23 @@
goto closeout;
}
while (serr == 0) {
- nerr = DB_PUT(pacct_db, &key, &data, 0);
+ nerr = DB_PUT(pacct_db, &key, &data, R_NOOVERWRITE);
if (nerr < 0) {
warn("initializing process accounting stats");
error = -1;
break;
}
+ if (nerr == 1) {
+ warnx("duplicate key in `%s': %s",
+ _PATH_SAVACCT, fmt(&key));
+ if (ndups++ == 5) {
+ warnx("too many duplicate keys;"
+ " `%s' possibly corrupted.",
+ _PATH_SAVACCT);
+ error = -1;
+ break;
+ }
+ }
serr = DB_SEQ(saved_pacct_db, &key, &data, R_NEXT);
if (serr < 0) {
diff -r fb504abd90f8 -r f345e64418fa usr.sbin/sa/usrdb.c
--- a/usr.sbin/sa/usrdb.c Sat Jul 29 19:13:34 2000 +0000
+++ b/usr.sbin/sa/usrdb.c Sat Jul 29 19:15:40 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usrdb.c,v 1.8 2000/06/14 17:26:24 cgd Exp $ */
+/* $NetBSD: usrdb.c,v 1.9 2000/07/29 19:15:40 christos Exp $ */
/*
* Copyright (c) 1994 Christopher G. Demetriou
@@ -36,7 +36,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: usrdb.c,v 1.8 2000/06/14 17:26:24 cgd Exp $");
+__RCSID("$NetBSD: usrdb.c,v 1.9 2000/07/29 19:15:40 christos Exp $");
#endif
#include <sys/types.h>
@@ -60,11 +60,12 @@
DB *saved_usracct_db;
BTREEINFO bti;
int error;
+ int ndups = 0;
memset(&bti, 0, sizeof(bti));
bti.compare = uid_compare;
- usracct_db = dbopen(NULL, O_RDWR, 0, DB_BTREE, &bti);
+ usracct_db = dbopen(NULL, O_RDWR|O_CREAT|O_TRUNC, 0644, DB_BTREE, &bti);
if (usracct_db == NULL)
return (-1);
@@ -89,12 +90,23 @@
goto closeout;
}
while (serr == 0) {
- nerr = DB_PUT(usracct_db, &key, &data, 0);
+ nerr = DB_PUT(usracct_db, &key, &data, R_NOOVERWRITE);
if (nerr < 0) {
warn("initializing user accounting stats");
error = -1;
break;
}
+ if (nerr == 1) {
+ warnx("duplicate key in `%s': %s",
+ _PATH_USRACCT, fmt(&key));
+ if (ndups++ == 5) {
+ warnx("too many duplicate keys;"
+ " `%s' possibly corrupted.",
+ _PATH_USRACCT);
+ error = -1;
+ break;
+ }
+ }
serr = DB_SEQ(saved_usracct_db, &key, &data, R_NEXT);
if (serr < 0) {
Home |
Main Index |
Thread Index |
Old Index