From arnej@math.ntnu.no  Tue Nov 17 06:31:34 1998
Received: from romberg.math.ntnu.no (romberg.math.ntnu.no [129.241.15.150])
          by hub.freebsd.org (8.8.8/8.8.8) with SMTP id GAA18630
          for <FreeBSD-gnats-submit@freebsd.org>; Tue, 17 Nov 1998 06:31:17 -0800 (PST)
          (envelope-from arnej@math.ntnu.no)
Received: (qmail 3396 invoked from network); 17 Nov 1998 14:30:35 -0000
Received: from fimfpc26.math.ntnu.no (129.241.15.26)
  by romberg.math.ntnu.no with SMTP; 17 Nov 1998 14:30:35 -0000
Received: (from arnej@localhost)
          by fimfpc26.math.ntnu.no (8.9.1/8.8.4)
	  id PAA03497; Tue, 17 Nov 1998 15:30:35 +0100 (CET)
Message-Id: <199811171430.PAA03497@fimfpc26.math.ntnu.no>
Date: Tue, 17 Nov 1998 15:30:35 +0100 (CET)
From: arnej@math.ntnu.no
Reply-To: arnej@math.ntnu.no
To: FreeBSD-gnats-submit@freebsd.org
Subject: mk-amd-map has several bugs and doesn't work at all
X-Send-Pr-Version: 3.2

>Number:         8728
>Category:       bin
>Synopsis:       mk-amd-map has several bugs and doesn't work at all
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    obrien
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 17 06:40:02 PST 1998
>Closed-Date:    Sun Nov 22 13:09:10 PST 1998
>Last-Modified:  Sun Nov 22 13:09:32 PST 1998
>Originator:     Arne Henrik Juul
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Norwegian University of Technology and Science
>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");
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->obrien 
Responsible-Changed-By: obrien 
Responsible-Changed-When: Thu Nov 19 23:47:46 PST 1998 
Responsible-Changed-Why:  
I did the new Amd import. 

From: "David O'Brien" <motminh@NUXI.com>
To: freebsd-gnats-submit@freebsd.org, arnej@math.ntnu.no
Cc:  Subject: Re: bin/8728: mk-amd-map has several bugs and doesn't work at all
Date: Thu, 19 Nov 1998 23:46:57 -0800

 Send me a diff agaist the latest mk-amd-map.c and I'll fix it right
 away.  Your diff is agaist am-utils 6.0a16 (our rev 1.4).
 
 I need one agaist mk-amd-map.c rev 1.5.
 
 -- David (obrien@FreeBSD.org)
State-Changed-From-To: open->closed 
State-Changed-By: obrien 
State-Changed-When: Sun Nov 22 13:09:10 PST 1998 
State-Changed-Why:  
seems to have been fixed in latest am-utils import 
>Unformatted:
