#include <stdlib.h>
#include <stdio.h>
+#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
(c)->errbuf[sizeof ((c)->errbuf) - 1] = 0; \
} while (0)
-#if COLLECT_DEBUG
-# define LCC_DEBUG(...) printf (__VA_ARGS__)
-#else
-# define LCC_DEBUG(...) /**/
-#endif
-
/*
* Types
*/
/*
* 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 */
{
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)
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. */
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)
#include "lcc_features.h"
+/* COLLECTD_TRACE is the environment variable used to control trace output. When
+ * set to something non-zero, all lines sent to / received from the daemon are
+ * printed to STDOUT. */
+#ifndef LCC_TRACE_ENV
+# define LCC_TRACE_ENV "COLLECTD_TRACE"
+#endif
+
/*
* Includes (for data types)
*/