vcmn_err: incorrect panic message
Pawel Jakub Dawidek
pjd at FreeBSD.org
Sun Dec 18 12:50:05 UTC 2011
On Sat, Dec 17, 2011 at 03:44:41PM +0200, Andriy Gapon wrote:
> Guys,
>
> what do you think about the following change or a variation of it?
> With the current code, in the unfortunate event of panic-ing via vcmn_err() a
> panic message would actually be a format string (placeholders are not substituted).
The patch looks good.
> commit f6cd1dc812b4cfdb3a123052ce0cb49a5afa941d
> Author: Andriy Gapon <avg at icyb.net.ua>
> Date: Thu Dec 15 00:04:31 2011 +0200
>
> opensolaris compat: fix vcmn_err so that panic produces a proper message
>
> ... instead of just a verbatim format string
>
> diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_cmn_err.c
> b/sys/cddl/compat/opensolaris/kern/opensolaris_cmn_err.c
> index 12e1854..abde30d 100644
> --- a/sys/cddl/compat/opensolaris/kern/opensolaris_cmn_err.c
> +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_cmn_err.c
> @@ -28,29 +28,35 @@ void
> vcmn_err(int ce, const char *fmt, va_list adx)
> {
> char buf[256];
> + const char *prefix;
>
> + prefix = NULL; /* silence unwitty compilers */
> switch (ce) {
> case CE_CONT:
> - snprintf(buf, sizeof(buf), "Solaris(cont): %s\n", fmt);
> + prefix = "Solaris(cont): ";
> break;
> case CE_NOTE:
> - snprintf(buf, sizeof(buf), "Solaris: NOTICE: %s\n", fmt);
> + prefix = "Solaris: NOTICE: ";
> break;
> case CE_WARN:
> - snprintf(buf, sizeof(buf), "Solaris: WARNING: %s\n", fmt);
> + prefix = "Solaris: WARNING: ";
> break;
> case CE_PANIC:
> - snprintf(buf, sizeof(buf), "Solaris(panic): %s\n", fmt);
> + prefix = "Solaris(panic): ";
> break;
> case CE_IGNORE:
> break;
> default:
> panic("Solaris: unknown severity level");
> }
> - if (ce == CE_PANIC)
> - panic("%s", buf);
> - if (ce != CE_IGNORE)
> - vprintf(buf, adx);
> + if (ce == CE_PANIC) {
> + vsnprintf(buf, sizeof(buf), fmt, adx);
> + panic("%s%s", prefix, buf);
> + }
> + if (ce != CE_IGNORE) {
> + printf("%s", prefix);
> + vprintf(fmt, adx);
> + }
> }
>
> void
--
Pawel Jakub Dawidek http://www.wheelsystems.com
FreeBSD committer http://www.FreeBSD.org
Am I Evil? Yes, I Am! http://yomoli.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/zfs-devel/attachments/20111218/81e81d82/attachment.pgp
More information about the zfs-devel
mailing list