vnconfig(8), bin/45754

Maxim Konovalov maxim at macomnet.ru
Wed May 14 02:47:32 PDT 2003


Hello,

I am going to commit a patch below, it fixes several cases when
vnconfig(8) fails but returns zero exit status.

Are there any objections?

http://www.freebsd.org/cgi/query-pr.cgi?pr=45754

Index: vnconfig.c
===================================================================
RCS file: /home/ncvs/src/usr.sbin/vnconfig/vnconfig.c,v
retrieving revision 1.13.2.6
diff -u -r1.13.2.6 vnconfig.c
--- vnconfig.c	7 Mar 2002 12:19:18 -0000	1.13.2.6
+++ vnconfig.c	13 May 2003 09:47:51 -0000
@@ -252,7 +252,7 @@
 	struct vndisk *vnp;
 {
 	char *dev, *file, *oarg;
-	int flags;
+	int flags, status;
 	struct vn_ioctl vnio;
 	register int rv;
 	char *rdev;
@@ -260,7 +260,7 @@
 	u_long l;
 	int pgsize = getpagesize();

-	rv = 0;
+	status = rv = 0;

 	/*
 	 * Prepend "/dev/" to the specified device name, if necessary.
@@ -333,6 +333,7 @@
 		if (flags & (VN_MOUNTRO|VN_MOUNTRW)) {
 			rv = unmount(oarg, 0);
 			if (rv) {
+				status--;
 				if (errno == EBUSY)
 					flags &= ~VN_UNCONFIG;
 				if ((flags & VN_UNCONFIG) == 0)
@@ -351,8 +352,10 @@
 				if (verbose)
 					printf("%s: not configured\n", dev);
 				rv = 0;
-			} else
+			} else {
+				status--;
 				warn("VNIOCDETACH");
+			}
 		} else if (verbose)
 			printf("%s: cleared\n", dev);
 	}
@@ -366,6 +369,7 @@
 		else
 			rv = ioctl(fileno(f), VNIOCUSET, &l);
 		if (rv) {
+			status--;
 			warn("VNIO[GU]SET");
 		} else if (verbose)
 			printf("%s: flags now=%08x\n",dev,l);
@@ -380,6 +384,7 @@
 		else
 			rv = ioctl(fileno(f), VNIOCUCLEAR, &l);
 		if (rv) {
+			status--;
 			warn("VNIO[GU]CLEAR");
 		} else if (verbose)
 			printf("%s: flags now=%08x\n",dev,l);
@@ -390,6 +395,7 @@
 	if (flags & VN_CONFIG) {
 		rv = ioctl(fileno(f), VNIOCATTACH, &vnio);
 		if (rv) {
+			status--;
 			warn("VNIOCATTACH");
 			flags &= ~VN_ENABLE;
 		} else {
@@ -417,6 +423,7 @@
 		else
 			rv = ioctl(fileno(f), VNIOCUSET, &l);
 		if (rv) {
+			status--;
 			warn("VNIO[GU]SET");
 		} else if (verbose)
 			printf("%s: flags now=%08lx\n",dev,l);
@@ -431,6 +438,7 @@
 		else
 			rv = ioctl(fileno(f), VNIOCUCLEAR, &l);
 		if (rv) {
+			status--;
 			warn("VNIO[GU]CLEAR");
 		} else if (verbose)
 			printf("%s: flags now=%08lx\n",dev,l);
@@ -447,8 +455,10 @@
 	if (flags & VN_ENABLE) {
 		if (flags & VN_SWAP) {
 			rv = swapon(dev);
-			if (rv)
+			if (rv) {
+				status--;
 				warn("swapon");
+			}
 			else if (verbose)
 				printf("%s: swapping enabled\n", dev);
 		}
@@ -459,15 +469,17 @@
 			args.fspec = dev;
 			mflags = (flags & VN_MOUNTRO) ? MNT_RDONLY : 0;
 			rv = mount("ufs", oarg, mflags, &args);
-			if (rv)
+			if (rv) {
+				status--;
 				warn("mount");
+			}
 			else if (verbose)
 				printf("%s: mounted on %s\n", dev, oarg);
 		}
 	}
 /* done: */
 	fflush(stdout);
-	return(rv < 0);
+	return(status < 0);
 }

 #define EOL(c)		((c) == '\0' || (c) == '\n')

%%%

--
Maxim Konovalov, maxim at macomnet.ru, maxim at FreeBSD.org


More information about the freebsd-stable mailing list