Date: Sun, 3 Oct 2010 20:32:01 -0700 From: Garrett Cooper <yanegomi@gmail.com> To: John Baldwin <jhb@freebsd.org>, scottl@freebsd.org, sbruno@freebsd.org Cc: freebsd-hackers@freebsd.org Subject: Re: Make mfiutil(8) more robust Message-ID: <AANLkTimhH6ALXGsXkQfFQJ%2BC4LmCfKKAQz0NQVveHavF@mail.gmail.com> In-Reply-To: <AANLkTik%2BKHCCtHeOOOqL6k%2B7kta3-pGWEukD=v7DsgMv@mail.gmail.com> References: <AANLkTik%2BKHCCtHeOOOqL6k%2B7kta3-pGWEukD=v7DsgMv@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --]
On Sun, Oct 3, 2010 at 8:30 PM, Garrett Cooper <yanegomi@gmail.com> wrote:
> As discussed offlist with some of the Yahoo! FreeBSD folks,
> mfiutil catches errors, but doesn't communicate it back up to the
> executing process. Examples follow...
> Before:
>
> $ ./mfiutil show adapter
> mfiutil: mfi_open: Permission denied
> $ echo $?
> 0
>
> (I would expect it to exit with a non-zero exit code)
> After:
>
> $ ./mfiutil show adapter
> mfiutil: mfi_open: Permission denied
> $ echo $?
> 1
>
> (Much better!)
>
> $ sudo ./mfiutil show adapter
> mfi0 Adapter:
> Product Name: MegaRAID SAS 8704ELP
> Serial Number: P391734409
> Firmware: 11.0.1-0026
> RAID Levels: JBOD, RAID0, RAID1, RAID5, RAID6, RAID10, RAID50
> Battery Backup: present
> NVRAM: 32K
> Onboard Memory: 128M
> Minimum Stripe: 8K
> Maximum Stripe: 1M
> $ echo $?
> 0
>
> (Looks good too!)
>
> After (mptutil):
>
> $ ../mptutil/mptutil show adapter
> mptutil: mpt_open: No such file or directory
> $ echo $?
> 1
>
> (Well, I don't have a mpt(4) card, so...)
>
> This trivial patch fixes this code to report valid errors in the
> handlers. I've added code to catch errors with mptutil as well as the
> logic is basically the same, and it functions as expected in the
> negative case; I don't have the hardware to test the mptutil command
> in the positive case though to ensure that functions as expected.
> Thanks!
Adding hackers@ for visibility with mptutil.
Thanks,
-Garrett
[-- Attachment #2 --]
Index: mptutil.c
===================================================================
--- mptutil.c (revision 213380)
+++ mptutil.c (working copy)
@@ -114,10 +114,12 @@
SET_FOREACH(cmd, MPT_DATASET(top)) {
if (strcmp((*cmd)->name, av[0]) == 0) {
- (*cmd)->handler(ac, av);
- return (0);
+ if ((*cmd)->handler(ac, av))
+ return (1);
+ else
+ return (0);
}
}
warnx("Unknown command %s.", av[0]);
- return (0);
+ return (1);
}
[-- Attachment #3 --]
Index: mfiutil.c
===================================================================
--- mfiutil.c (revision 211767)
+++ mfiutil.c (working copy)
@@ -125,10 +125,12 @@
SET_FOREACH(cmd, MFI_DATASET(top)) {
if (strcmp((*cmd)->name, av[0]) == 0) {
- (*cmd)->handler(ac, av);
- return (0);
+ if ((*cmd)->handler(ac, av))
+ return (1);
+ else
+ return (0);
}
}
warnx("Unknown command %s.", av[0]);
- return (0);
+ return (1);
}
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTimhH6ALXGsXkQfFQJ%2BC4LmCfKKAQz0NQVveHavF>
