summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1995-12-11 13:56:07 +0000
committerpeter <peter@FreeBSD.org>1995-12-11 13:56:07 +0000
commitd20b5a1c02ba491671cfa7ff58c322ea8affb8b8 (patch)
tree4ebd51351fa8df00e3fe7d980b0624d2f67f82eb
parent286d95551f8211bbe15b8be12c6eaf9325c1232f (diff)
downloadFreeBSD-src-d20b5a1c02ba491671cfa7ff58c322ea8affb8b8.zip
FreeBSD-src-d20b5a1c02ba491671cfa7ff58c322ea8affb8b8.tar.gz
Fix yp_mkdb to do what the code suggests it's trying to do..
The code, as written, appears to load the new database data into a new hash file and renames the two. Due to a run of bugs and lack of error checking, it's going a whole mess of unlink() and rename() calls that are failing. It only worked in the first place because the data was being inserted into a "live" hash file. (I wonder how much stale data has assumulated?) Submitted by: Laurence Lopez <lopez@mv.mv.com>
-rw-r--r--gnu/usr.sbin/yp_mkdb/yp_mkdb.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/gnu/usr.sbin/yp_mkdb/yp_mkdb.c b/gnu/usr.sbin/yp_mkdb/yp_mkdb.c
index 5d2d4b3..29e5183 100644
--- a/gnu/usr.sbin/yp_mkdb/yp_mkdb.c
+++ b/gnu/usr.sbin/yp_mkdb/yp_mkdb.c
@@ -20,7 +20,7 @@
*/
/*
- * $Id: yp_mkdb.c,v 1.4 1995/10/11 14:30:51 wpaul Exp $
+ * $Id: yp_mkdb.c,v 1.5 1995/10/23 16:03:41 wpaul Exp $
*/
#define BUFFERSIZE 4096
@@ -102,9 +102,9 @@ load( char *FileName, char *DbName)
exit(1);
}
- sprintf(filename, "%s~.db", DbName);
+ sprintf(filename, "%s~", DbName);
- if ((dp = dbopen(DbName,O_RDWR|O_EXCL|O_CREAT, PERM_SECURE,
+ if ((dp = dbopen(filename,O_RDWR|O_EXCL|O_CREAT, PERM_SECURE,
DB_HASH, &openinfo)) == NULL) {
perror("dbopen");
fprintf(stderr, "%s: Cannot open\n", filename);
@@ -177,10 +177,14 @@ load( char *FileName, char *DbName)
}
(void)(dp->close)(dp);
- sprintf(filename, "%s.db", DbName);
- sprintf(filename2, "%s~.db", DbName);
+ sprintf(filename, "%s", DbName);
+ sprintf(filename2, "%s~", DbName);
unlink(filename);
- rename(filename2, filename);
+ if (rename(filename2, filename)) {
+ perror("rename");
+ fprintf(stderr, "Cannot rename %s to %s\n", filename2, filename);
+ exit(1);
+ }
}
static void
OpenPOWER on IntegriCloud