summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 67a330c)
raw | patch | inline | side by side (parent: 67a330c)
author | Florian Forster <octo@collectd.org> | |
Sat, 6 Aug 2016 18:00:34 +0000 (20:00 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Sat, 6 Aug 2016 18:00:34 +0000 (20:00 +0200) |
Even with --enable-debug. This behavior is now controlled by the
"COLLECTD_TRACE" environment variable.
Fixes: #105
"COLLECTD_TRACE" environment variable.
Fixes: #105
src/libcollectdclient/client.c | patch | blob | history | |
src/libcollectdclient/collectd/client.h | patch | blob | history |
index 802e6439d8ac633d7ec6245470f614904573d4da..c90107d1d4e30c303fe4c684f60d8f1df03ffe3c 100644 (file)
#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)
index 6ae85984e95958afb6a9f1207cd38c42bcaea7e3..8e7f4b60acd5498dd4edb04da56e39f29d62b02b 100644 (file)
#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)
*/