X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Flibcollectdclient%2Fclient.c;h=bdb21f659558047e87199bb0d63bbd8d03f43a9c;hb=a3444db7419687386919fccf7d14b945f2e9da56;hp=a97dc509e4d7ff7e94b491f28244ad9e9e1d10cc;hpb=81a5fd5046c6a39f580a8fc1a3af837fd5f5aa5c;p=collectd.git diff --git a/src/libcollectdclient/client.c b/src/libcollectdclient/client.c index a97dc509..bdb21f65 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,22 @@ typedef struct lcc_response_s lcc_response_t; /* * Private functions */ +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 */ @@ -250,7 +261,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) @@ -281,7 +292,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. */ @@ -329,7 +340,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) @@ -526,9 +537,11 @@ static int lcc_open_netsocket (lcc_connection_t *c, /* {{{ */ if (status != 0) { lcc_set_errno (c, status); + freeaddrinfo (ai_res); return (-1); } + freeaddrinfo (ai_res); return (0); } /* }}} int lcc_open_netsocket */