Subject: Re: PR#3615 status...
To: Brian C. Grayson <bgrayson@marvin.ece.utexas.edu>
From: Matthew Orgass <darkstar@pgh.net>
List: tech-userlevel
Date: 04/21/1999 05:29:21
On Wed, 21 Apr 1999, Brian C. Grayson wrote:

>   I don't remember what the seg fault is from, or if it has been
> fixed in -current, but -R seems to do the trick for me.

  Hmm... PR#6182.  I don't quite agree with this solution, however.  I
think whoever implemented -R had it skip too much code.  How about this:

--- sbin/umount/umount.c.bak	Tue Apr 20 21:49:50 1999
+++ sbin/umount/umount.c	Tue Apr 20 23:23:49 1999
@@ -213,70 +213,68 @@
 	hp = NULL;
 	delimp = NULL;
 
-	if (raw) {
-		mntpt = name;
-	} else {
-
+	if (raw)
+		strncpy(rname, name, MAXPATHLEN)[MAXPATHLEN-1] = '\0';
+	else
 		if (realpath(name, rname) == NULL) {
-			warn("%s", rname);
+			warn("Path resolution error on %s", rname);
 			return (1);
 		}
 
-		what = MNTANY;
-		mntpt = name = rname;
+	mntpt = name = rname;
+	what = MNTANY;
 
-		if (stat(name, &sb) == 0) {
-			if (S_ISBLK(sb.st_mode))
-				what = MNTON;
-			else if (S_ISDIR(sb.st_mode))
-				what = MNTFROM;
-		}
+	if (stat(name, &sb) == 0) {
+		if (S_ISBLK(sb.st_mode))
+			what = MNTON;
+		else if (S_ISDIR(sb.st_mode))
+			what = MNTFROM;
+	}
 
-		switch (what) {
-		case MNTON:
+	switch (what) {
+	case MNTON:
+		if ((mntpt = getmntname(name, MNTON, &type)) == NULL) {
+			warnx("%s: not currently mounted", name);
+			return (1);
+		}
+		break;
+	case MNTFROM:
+		if ((name = getmntname(mntpt, MNTFROM, &type)) == NULL) {
+			warnx("%s: not currently mounted", mntpt);
+			return (1);
+		}
+		break;
+	default:
+		if ((name = getmntname(mntpt, MNTFROM, &type)) == NULL) {
+			name = rname;
 			if ((mntpt = getmntname(name, MNTON, &type)) == NULL) {
 				warnx("%s: not currently mounted", name);
 				return (1);
 			}
-			break;
-		case MNTFROM:
-			if ((name = getmntname(mntpt, MNTFROM, &type)) == NULL) {
-				warnx("%s: not currently mounted", mntpt);
-				return (1);
-			}
-			break;
-		default:
-			if ((name = getmntname(mntpt, MNTFROM, &type)) == NULL) {
-				name = rname;
-				if ((mntpt = getmntname(name, MNTON, &type)) == NULL) {
-					warnx("%s: not currently mounted", name);
-					return (1);
-				}
-			}
 		}
+	}
 
-		if (checkvfsname(type, typelist))
-			return (1);
+	if (checkvfsname(type, typelist))
+		return (1);
 
-		hp = NULL;
-		if (!strncmp(type, MOUNT_NFS, MFSNAMELEN)) {
-			if ((delimp = strchr(name, '@')) != NULL) {
-				hostp = delimp + 1;
-				*delimp = '\0';
-				hp = gethostbyname(hostp);
-				*delimp = '@';
-			} else if ((delimp = strchr(name, ':')) != NULL) {
-				*delimp = '\0';
-				hostp = name;
-				hp = gethostbyname(hostp);
-				name = delimp + 1;
-				*delimp = ':';
-			}
+	hp = NULL;
+	if (!strncmp(type, MOUNT_NFS, MFSNAMELEN)) {
+		if ((delimp = strchr(name, '@')) != NULL) {
+			hostp = delimp + 1;
+			*delimp = '\0';
+			hp = gethostbyname(hostp);
+			*delimp = '@';
+		} else if ((delimp = strchr(name, ':')) != NULL) {
+			*delimp = '\0';
+			hostp = name;
+			hp = gethostbyname(hostp);
+			name = delimp + 1;
+			*delimp = ':';
 		}
-
-		if (!namematch(hp))
-			return (1);
 	}
+
+	if (!namematch(hp))
+		return (1);
 
 	if (verbose)
 		(void)printf("%s: unmount from %s\n", name, mntpt);