Having a debug print macro is nice. But if it depends on a tool specific debug switch location, it's hard to use in shared utility code.
Signed-off-by: Chris Leech <[email protected]> --- fcoemon.c | 1 + fcoemon.h | 6 ++---- fipvlan.c | 11 ++--------- include/fcoemon_utils.h | 4 +++- lib/sa_log.c | 22 ++++++++++++++++++++++ 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/fcoemon.c b/fcoemon.c index 8cb31ea..edcf32c 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -2350,6 +2350,7 @@ int main(int argc, char **argv) break; case 'd': fcoe_config.debug = 1; + enable_debug_log(1); break; case 's': fcoe_config.use_syslog = 1; diff --git a/fcoemon.h b/fcoemon.h index a36128d..474d65c 100644 --- a/fcoemon.h +++ b/fcoemon.h @@ -43,14 +43,12 @@ struct fcoe_config { #define FCM_LOG_DBG(fmt, args...) \ do { \ - if (fcoe_config.debug) \ - sa_log(fmt, ##args); \ + sa_log_debug(fmt, ##args); \ } while (0) #define FCM_LOG_DEV_DBG(fcm, fmt, args...) \ do { \ - if (fcoe_config.debug) \ - sa_log("%s, " fmt, fcm->ifname, ##args); \ + sa_log_debug("%s, " fmt, fcm->ifname, ##args); \ } while (0) #define FCM_LOG_DEV(fcm, fmt, args...) \ diff --git a/fipvlan.c b/fipvlan.c index d2269b7..3217a82 100644 --- a/fipvlan.c +++ b/fipvlan.c @@ -41,20 +41,12 @@ #include "fip.h" #include "fcoemon_utils.h" -static struct { - int debug; -} fcoe_config = { - .debug = 1, -}; - #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #define FIP_LOG(...) sa_log(__VA_ARGS__) #define FIP_LOG_ERR(error, ...) sa_log_err(error, __func__, __VA_ARGS__) #define FIP_LOG_ERRNO(...) sa_log_err(errno, __func__, __VA_ARGS__) -#define FIP_LOG_DBG(...) do { \ - if (fcoe_config.debug) sa_log(__VA_ARGS__); \ -} while (0) +#define FIP_LOG_DBG(...) sa_log_debug(__VA_ARGS__) /* global configuration */ @@ -699,6 +691,7 @@ int main(int argc, char **argv) automode = parse_cmdline(argc, argv); sa_log_prefix = exe; sa_log_flags = 0; + enable_debug_log(0); ps = packet_socket(); diff --git a/include/fcoemon_utils.h b/include/fcoemon_utils.h index 35ab19e..8680f46 100644 --- a/include/fcoemon_utils.h +++ b/include/fcoemon_utils.h @@ -40,6 +40,7 @@ #include "fc_types.h" void sa_log(const char *format, ...); +void sa_log_debug(const char *format, ...); void sa_log_err(int, const char *func, const char *format, ...); /* @@ -262,7 +263,8 @@ fc_wwn_from_mac(u_int64_t, u_int32_t scheme, u_int32_t port); extern int hex2int(char *b); -int use_syslog; +extern int use_syslog; void enable_syslog(int); +void enable_debug_log(int); #endif /* _FCOEMON_UTILS_H_ */ diff --git a/lib/sa_log.c b/lib/sa_log.c index a16b7b3..91c256f 100644 --- a/lib/sa_log.c +++ b/lib/sa_log.c @@ -22,6 +22,7 @@ #include "fc_types.h" int use_syslog; +static int debug; /* * Size of on-stack line buffers. @@ -34,6 +35,11 @@ void enable_syslog(int enable) use_syslog = enable; } +void enable_debug_log(int enable) +{ + debug = enable; +} + /* * log with a variable argument list. */ @@ -83,6 +89,22 @@ sa_log(const char *format, ...) } /* + * debug log, controlled by static debug flag + */ +void +sa_log_debug(const char *format, ...) +{ + va_list arg; + + if (!debug) + return; + + va_start(arg, format); + sa_log_va(NULL, format, arg); + va_end(arg); +} + +/* * log with error number. */ void _______________________________________________ devel mailing list [email protected] http://www.open-fcoe.org/mailman/listinfo/devel
