X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fclient.c;h=4dbee1e8d56d17d2fe38b862b397d61b2aa49a9b;hb=3e36ac34460b6be8388ac376ab7a4e2e990870ec;hp=1c118e3c621ac7d51efb20a12d801308d3818bdb;hpb=2761915bed8c6caea41018be3e675aa712cc0b0a;p=collectd.git diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index 1c118e3c..4dbee1e8 100644 --- a/src/libcollectdclient/client.c +++ b/src/libcollectdclient/client.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -91,12 +92,6 @@ (c)->errbuf[sizeof ((c)->errbuf) - 1] = 0; \ } while (0) -#if COLLECT_DEBUG -# define LCC_DEBUG(...) printf (__VA_ARGS__) -#else -# define LCC_DEBUG(...) /**/ -#endif - /* * Types */ @@ -118,6 +113,23 @@ typedef struct lcc_response_s lcc_response_t; /* * Private functions */ +__attribute__ ((format (printf, 1, 0))) +static int lcc_tracef(char const *format, ...) +{ + va_list ap; + int status; + + char const *trace = getenv (LCC_TRACE_ENV); + if (!trace || (strcmp ("", trace) == 0) || (strcmp ("0", trace) == 0)) + return 0; + + va_start (ap, format); + status = vprintf (format, ap); + va_end (ap); + + return status; +} + /* Even though Posix requires "strerror_r" to return an "int", * some systems (e.g. the GNU libc) return a "char *" _and_ * ignore the second argument ... -tokkee */ @@ -248,7 +260,7 @@ static int lcc_send (lcc_connection_t *c, const char *command) /* {{{ */ { int status; - LCC_DEBUG ("send: --> %s\n", command); + lcc_tracef ("send: --> %s\n", command); status = fprintf (c->fh, "%s\r\n", command); if (status < 0) @@ -277,7 +289,7 @@ static int lcc_receive (lcc_connection_t *c, /* {{{ */ return (-1); } lcc_chomp (buffer); - LCC_DEBUG ("receive: <-- %s\n", buffer); + lcc_tracef ("receive: <-- %s\n", buffer); /* Convert the leading status to an integer and make `ptr' to point to the * beginning of the message. */ @@ -325,7 +337,7 @@ static int lcc_receive (lcc_connection_t *c, /* {{{ */ break; } lcc_chomp (buffer); - LCC_DEBUG ("receive: <-- %s\n", buffer); + lcc_tracef ("receive: <-- %s\n", buffer); res.lines[i] = strdup (buffer); if (res.lines[i] == NULL)