Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Nov 1998 15:30:35 +0100 (CET)
From:      arnej@math.ntnu.no
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   bin/8728: mk-amd-map has several bugs and doesn't work at all
Message-ID:  <199811171430.PAA03497@fimfpc26.math.ntnu.no>

next in thread | raw e-mail | index | archive | help

>Number:         8728
>Category:       bin
>Synopsis:       mk-amd-map has several bugs and doesn't work at all
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 17 06:40:02 PST 1998
>Last-Modified:
>Originator:     Arne Henrik Juul
>Organization:
Norwegian University of Technology and Science
>Release:        FreeBSD 3.0-CURRENT i386
>Environment:

	Running 3.0 current as of november 1998.

>Description:

	The program mk-amd-map as imported (from NetBSD?) and modified
	doesn't work, and it can't have been tested as far as I can see.
	(I actually use it in daily operations, so I noticed at once
	when I upgraded to 3.0-current).
	There are some code to use mkstemp if available in here that's
	so completely bogus I just removed it, it would need a complete
	rethink.  (As it was it opened the output database file *instead*
	of the input text file).  Also, the conversion from .dir/.pag files
	to just a .db file wasn't really complete, and one error message
	was just wrong.

>How-To-Repeat:

	Try to run mk-amd-map and check the resulting database, or
	run mk-amd-map -p and watch the resulting lossage.

>Fix:
	
	Apply following patch:

Index: contrib/amd/mk-amd-map/mk-amd-map.c
===================================================================
RCS file: /usr/cvs/src/contrib/amd/mk-amd-map/mk-amd-map.c,v
retrieving revision 1.4
diff -u -r1.4 mk-amd-map.c
--- mk-amd-map.c	1998/08/27 07:25:25	1.4
+++ mk-amd-map.c	1998/11/17 14:03:44
@@ -263,16 +263,10 @@
       perror("mk-amd-map: malloc");
       exit(1);
     }
-#ifdef HAVE_MKSTEMP
-    mapfd = mkstemp(maptmp);
-#else /* not HAVE_MKSTEMP */
-    map = mktemp(maptmp);
-    if (!maptmp) {
+    if (!mktemp(maptmp)) {
       fprintf(stderr, "cannot create temporary file\n");
       exit(1);
     }
-    mapfd = open(map, O_RDONLY);
-#endif /* not HAVE_MKSTEMP */
 
     /* open DBM files */
     sprintf(maptdb, "%s.db", maptmp);
@@ -283,6 +277,7 @@
     }
   }
   /* open and check if map file was opened OK */
+  mapfd = open(map, O_RDONLY);
   mapf = fdopen(mapfd, "r");
   if (mapf && !printit)
     mapd = dbm_open(maptmp, O_RDWR|O_CREAT, 0444);
@@ -298,21 +293,14 @@
     int error = read_file(mapf, map, mapd);
     (void) close(mapfd);
     (void) fclose(mapf);
-	dbm_close(mapd);
-    if (printit) {
-      if (error) {
-	fprintf(stderr, "Error creating ndbm map for %s\n", map);
-	rc = 1;
-      }
-    } else {
-
-      if (error) {
+    if (error) {
 	fprintf(stderr, "Error reading source file  %s\n", map);
 	rc = 1;
-      } else {
+    }
+    if (!printit) {
+      dbm_close(mapd);
+      if (!error) {
 	sprintf(mapdb, "%s.db", map);
-	if (unlink(mapdb) == 0)
-	  fprintf(stderr, "WARNING: existing map \"%s.db\" destroyed\n", map);
 	if (rename(maptdb, mapdb) < 0) {
 	  fprintf(stderr, "Couldn't rename %s to ", maptdb);
 	  perror(mapdb);
@@ -322,7 +310,6 @@
 	}
       }
     }
-
   } else {
     fprintf(stderr, "Can't open \"%s.db\" for ", map);
     perror("writing");
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199811171430.PAA03497>