Date: Tue, 26 Nov 2002 22:51:27 +0700 (KRAT) From: Eugene Grosbein <eugen@grosbein.pp.ru> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/45754: vnconfig(8) fails to return correct exit status Message-ID: <200211261551.gAQFpR5a001144@grosbein.pp.ru>
index | next in thread | raw e-mail
>Number: 45754
>Category: bin
>Synopsis: vnconfig(8) fails to return correct exit status
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Tue Nov 26 08:00:09 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Eugene Grosbein
>Release: FreeBSD 4.7-STABLE i386
>Organization:
Svyaz Service JSC
>Environment:
System: FreeBSD grosbein.pp.ru 4.7-STABLE FreeBSD 4.7-STABLE #22: Sun Oct 13 14:25:47 KRAST 2002 eu@grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV i386
$FreeBSD: src/usr.sbin/vnconfig/vnconfig.c,v 1.13.2.6 2002/03/07 12:19:18 dwmalone Exp $
>Description:
Sometimes vnconfig(8) fails but returns zero exit status
>How-To-Repeat:
Let's see right thing:
echo test >test
# vnconfig /dev/vn0 test; echo $?
0
# vnconfig /dev/vn0 test; echo $?
vnconfig: VNIOCATTACH: Device busy
1
Non-zero exit status; good. Now cleanup and let's see bad thing:
# vnconfig -u /dev/vn0
# vnconfig -c -s labels /dev/vn0 test; echo $?
0
# vnconfig -c -s labels /dev/vn0 test; echo $?
vnconfig: VNIOCATTACH: Device busy
0
That's bad.
>Fix:
Apply this patch to src/usr.sbin/vnconfig
--- vnconfig.c.orig Tue Nov 26 22:34:34 2002
+++ vnconfig.c Tue Nov 26 22:48:53 2002
@@ -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')
Eugene Grosbein
>Release-Note:
>Audit-Trail:
>Unformatted:
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200211261551.gAQFpR5a001144>
