From: octo Date: Thu, 15 Jun 2006 20:19:12 +0000 (+0000) Subject: solaris-fixes branch: Fix the debugging output in `configfile.c'. X-Git-Tag: collectd-3.9.4~12 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=fa3e58be7ba5762f59f4f1b86cb6431cd4813a6a;p=collectd.git solaris-fixes branch: Fix the debugging output in `configfile.c'. The Solaris libc doesn't like if you pass a NULL pointer to as the string used with printf like formatting. This patch introduces a macro which escapes this. --- diff --git a/src/configfile.c b/src/configfile.c index 477d8816..39265868 100644 --- a/src/configfile.c +++ b/src/configfile.c @@ -37,6 +37,15 @@ #define ERR_NEEDS_ARG "Section `%s' needs an argument.\n" #define ERR_NEEDS_SECTION "`%s' can only be used within a section.\n" +#define ESCAPE_NULL(str) ((str) == NULL ? "(null)" : (str)) + +#define DEBUG_CALLBACK(shortvar, var, arguments, value) \ + DBG("shortvar = %s, var = %s, arguments = %s, value = %s, ...", \ + ESCAPE_NULL(shortvar), \ + ESCAPE_NULL(var), \ + ESCAPE_NULL(arguments), \ + ESCAPE_NULL(value)) + extern int operating_mode; typedef struct cf_callback @@ -102,7 +111,10 @@ static int cf_dispatch (char *type, const char *orig_key, const char *orig_value int ret; int i; - DBG ("type = %s, key = %s, value = %s", type, orig_key, orig_value); + DBG ("type = %s, key = %s, value = %s", + ESCAPE_NULL(type), + ESCAPE_NULL(orig_key), + ESCAPE_NULL(orig_value)); if ((cf_cb = cf_search (type)) == NULL) { @@ -195,7 +207,7 @@ void cf_register (char *type, } else { - DBG ("Key was truncated: `%s'", keys[i]); + DBG ("Key was truncated: `%s'", ESCAPE_NULL(keys[i])); } } } @@ -237,8 +249,7 @@ static int cf_callback_mode (const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) { - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); if (strcasecmp (value, "Client") == 0) operating_mode = MODE_CLIENT; @@ -271,8 +282,7 @@ static int cf_callback_mode_plugindir (const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) { - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); plugin_set_dir (value); @@ -285,8 +295,7 @@ static int cf_callback_mode_option (const char *shortvar, const char *var, { cf_mode_item_t *item; - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); if (extra == NULL) { @@ -335,8 +344,7 @@ static int cf_callback_mode_loadmodule (const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) { - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); if (plugin_load (value)) syslog (LOG_ERR, "plugin_load (%s): failed to load plugin", value); @@ -358,8 +366,7 @@ static int cf_callback_socket (const char *shortvar, const char *var, char *node; char *service = NET_DEFAULT_PORT; - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); buffer = strdup (value); if (buffer == NULL) @@ -401,8 +408,7 @@ static int cf_callback_plugin (const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) { - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); if (flags == LC_FLAGS_SECTIONSTART) { @@ -462,8 +468,7 @@ static int cf_callback_plugin_dispatch (const char *shortvar, const char *var, const char *arguments, const char *value, lc_flags_t flags, void *extra) { - DBG ("shortvar = %s, var = %s, arguments = %s, value = %s, ...", - shortvar, var, arguments, value); + DEBUG_CALLBACK (shortvar, var, arguments, value); if ((nesting_depth == 0) || (current_module == NULL)) {