Skip to content
Permalink
Browse files

10291 topo_dprintf should evaluate debug mask before forging ahead

Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Patrick Mooney <patrick.mooney@joyent.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Gergő Mihály Doma <domag02@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
  • Loading branch information
rejohnst authored and danmcd committed Sep 11, 2018
1 parent c184cb8 commit 1de1e652632a9912511ab1cd8c8c4628d5e5f1da
@@ -758,14 +758,14 @@ topo_mod_clrdebug(topo_mod_t *mod)
void
topo_mod_dprintf(topo_mod_t *mod, const char *format, ...)
{
topo_hdl_t *thp = mod->tm_hdl;
va_list alist;

if (mod->tm_debug == 0)
if (mod->tm_debug == 0 || !(thp->th_debug & TOPO_DBG_MOD))
return;

va_start(alist, format);
topo_vdprintf(mod->tm_hdl, TOPO_DBG_MOD, (const char *)mod->tm_name,
format, alist);
topo_vdprintf(mod->tm_hdl, (const char *)mod->tm_name, format, alist);
va_end(alist);
}

@@ -172,16 +172,12 @@ topo_debug_set(topo_hdl_t *thp, const char *dbmode, const char *dout)
}

void
topo_vdprintf(topo_hdl_t *thp, int mask, const char *mod, const char *format,
va_list ap)
topo_vdprintf(topo_hdl_t *thp, const char *mod, const char *format, va_list ap)
{
char *msg;
size_t len;
char c;

if (!(thp->th_debug & mask))
return;

len = vsnprintf(&c, 1, format, ap);
msg = alloca(len + 2);
(void) vsnprintf(msg, len + 1, format, ap);
@@ -212,8 +208,11 @@ topo_dprintf(topo_hdl_t *thp, int mask, const char *format, ...)
{
va_list ap;

if (!(thp->th_debug & mask))
return;

va_start(ap, format);
topo_vdprintf(thp, mask, NULL, format, ap);
topo_vdprintf(thp, NULL, format, ap);
va_end(ap);
}

@@ -21,6 +21,7 @@

/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, Joyent, Inc.
*/

#ifndef _TOPO_SUBR_H
@@ -124,7 +125,7 @@ extern int topo_version_str2num(const char *, topo_version_t);
extern int topo_version_defined(topo_version_t);

extern void topo_dprintf(topo_hdl_t *, int, const char *, ...);
extern void topo_vdprintf(topo_hdl_t *, int, const char *, const char *,
extern void topo_vdprintf(topo_hdl_t *, const char *, const char *,
va_list);

extern tnode_t *topo_hdl_root(topo_hdl_t *, const char *);

0 comments on commit 1de1e65

Please sign in to comment.
You can’t perform that action at this time.