From 5318395661fa6bd728120f2a5ee524ef344b192d Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Mon, 11 Dec 1995 13:56:07 +0000 Subject: 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 --- gnu/usr.sbin/yp_mkdb/yp_mkdb.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gnu/usr.sbin') diff --git a/gnu/usr.sbin/yp_mkdb/yp_mkdb.c b/gnu/usr.sbin/yp_mkdb/yp_mkdb.c index 5d2d4b3a5dba..29e51836d5ca 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 -- cgit v1.3