Merge pull request #2702 from elfiesmelfie/feat_snmp_agent
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Fri, 8 Jun 2018 16:24:19 +0000 (18:24 +0200)
committerGitHub <noreply@github.com>
Fri, 8 Jun 2018 16:24:19 +0000 (18:24 +0200)
snmp_agent: new features

12 files changed:
Makefile.am
src/daemon/cmd.c [new file with mode: 0644]
src/daemon/cmd.h [new file with mode: 0644]
src/daemon/collectd.c
src/daemon/collectd.h
src/intel_rdt.c
src/lua.c
src/perl.c
src/processes.c
src/utils_lua.c
src/utils_lua.h
src/virt.c

index 232ddd6..83b76a0 100644 (file)
@@ -195,6 +195,8 @@ endif
 
 
 collectd_SOURCES = \
+       src/daemon/cmd.c \
+       src/daemon/cmd.h \
        src/daemon/collectd.c \
        src/daemon/collectd.h \
        src/daemon/configfile.c \
diff --git a/src/daemon/cmd.c b/src/daemon/cmd.c
new file mode 100644 (file)
index 0000000..7b77995
--- /dev/null
@@ -0,0 +1,271 @@
+/**
+ * collectd - src/daemon/cmd.c
+ * Copyright (C) 2005-2007  Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ **/
+
+#include "cmd.h"
+#include "collectd.h"
+
+#include "common.h"
+#include <sys/un.h>
+
+static void *do_flush(void __attribute__((unused)) * arg) {
+  INFO("Flushing all data.");
+  plugin_flush(/* plugin = */ NULL,
+               /* timeout = */ 0,
+               /* ident = */ NULL);
+  INFO("Finished flushing all data.");
+  pthread_exit(NULL);
+  return NULL;
+}
+
+static void sig_int_handler(int __attribute__((unused)) signal) {
+  stop_collectd();
+}
+
+static void sig_term_handler(int __attribute__((unused)) signal) {
+  stop_collectd();
+}
+
+static void sig_usr1_handler(int __attribute__((unused)) signal) {
+  pthread_t thread;
+  pthread_attr_t attr;
+
+  /* flushing the data might take a while,
+   * so it should be done asynchronously */
+  pthread_attr_init(&attr);
+  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+  pthread_create(&thread, &attr, do_flush, NULL);
+  pthread_attr_destroy(&attr);
+}
+
+#if COLLECT_DAEMON
+static int pidfile_create(void) {
+  FILE *fh;
+  const char *file = global_option_get("PIDFile");
+
+  if ((fh = fopen(file, "w")) == NULL) {
+    ERROR("fopen (%s): %s", file, STRERRNO);
+    return 1;
+  }
+
+  fprintf(fh, "%i\n", (int)getpid());
+  fclose(fh);
+
+  return 0;
+} /* static int pidfile_create (const char *file) */
+
+static int pidfile_remove(void) {
+  const char *file = global_option_get("PIDFile");
+  if (file == NULL)
+    return 0;
+
+  return unlink(file);
+} /* static int pidfile_remove (const char *file) */
+#endif /* COLLECT_DAEMON */
+
+#ifdef KERNEL_LINUX
+static int notify_upstart(void) {
+  char const *upstart_job = getenv("UPSTART_JOB");
+
+  if (upstart_job == NULL)
+    return 0;
+
+  if (strcmp(upstart_job, "collectd") != 0) {
+    WARNING("Environment specifies unexpected UPSTART_JOB=\"%s\", expected "
+            "\"collectd\". Ignoring the variable.",
+            upstart_job);
+    return 0;
+  }
+
+  NOTICE("Upstart detected, stopping now to signal readiness.");
+  raise(SIGSTOP);
+  unsetenv("UPSTART_JOB");
+
+  return 1;
+}
+
+static int notify_systemd(void) {
+  size_t su_size;
+  const char *notifysocket = getenv("NOTIFY_SOCKET");
+  if (notifysocket == NULL)
+    return 0;
+
+  if ((strlen(notifysocket) < 2) ||
+      ((notifysocket[0] != '@') && (notifysocket[0] != '/'))) {
+    ERROR("invalid notification socket NOTIFY_SOCKET=\"%s\": path must be "
+          "absolute",
+          notifysocket);
+    return 0;
+  }
+  NOTICE("Systemd detected, trying to signal readiness.");
+
+  unsetenv("NOTIFY_SOCKET");
+
+  int fd;
+#if defined(SOCK_CLOEXEC)
+  fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, /* protocol = */ 0);
+#else
+  fd = socket(AF_UNIX, SOCK_DGRAM, /* protocol = */ 0);
+#endif
+  if (fd < 0) {
+    ERROR("creating UNIX socket failed: %s", STRERRNO);
+    return 0;
+  }
+
+  struct sockaddr_un su = {0};
+  su.sun_family = AF_UNIX;
+  if (notifysocket[0] != '@') {
+    /* regular UNIX socket */
+    sstrncpy(su.sun_path, notifysocket, sizeof(su.sun_path));
+    su_size = sizeof(su);
+  } else {
+    /* Linux abstract namespace socket: specify address as "\0foo", i.e.
+     * start with a null byte. Since null bytes have no special meaning in
+     * that case, we have to set su_size correctly to cover only the bytes
+     * that are part of the address. */
+    sstrncpy(su.sun_path, notifysocket, sizeof(su.sun_path));
+    su.sun_path[0] = 0;
+    su_size = sizeof(sa_family_t) + strlen(notifysocket);
+    if (su_size > sizeof(su))
+      su_size = sizeof(su);
+  }
+
+  const char buffer[] = "READY=1\n";
+  if (sendto(fd, buffer, strlen(buffer), MSG_NOSIGNAL, (void *)&su,
+             (socklen_t)su_size) < 0) {
+    ERROR("sendto(\"%s\") failed: %s", notifysocket, STRERRNO);
+    close(fd);
+    return 0;
+  }
+
+  unsetenv("NOTIFY_SOCKET");
+  close(fd);
+  return 1;
+}
+#endif /* KERNEL_LINUX */
+
+int main(int argc, char **argv) {
+  struct cmdline_config config = init_config(argc, argv);
+
+#if COLLECT_DAEMON
+  /*
+   * fork off child
+   */
+  struct sigaction sig_chld_action = {.sa_handler = SIG_IGN};
+
+  sigaction(SIGCHLD, &sig_chld_action, NULL);
+
+  /*
+   * Only daemonize if we're not being supervised
+   * by upstart or systemd (when using Linux).
+   */
+  if (config.daemonize
+#ifdef KERNEL_LINUX
+      && notify_upstart() == 0 && notify_systemd() == 0
+#endif
+      ) {
+    pid_t pid;
+    if ((pid = fork()) == -1) {
+      /* error */
+      fprintf(stderr, "fork: %s", STRERRNO);
+      return 1;
+    } else if (pid != 0) {
+      /* parent */
+      /* printf ("Running (PID %i)\n", pid); */
+      return 0;
+    }
+
+    /* Detach from session */
+    setsid();
+
+    /* Write pidfile */
+    if (pidfile_create())
+      exit(2);
+
+    /* close standard descriptors */
+    close(2);
+    close(1);
+    close(0);
+
+    int status = open("/dev/null", O_RDWR);
+    if (status != 0) {
+      ERROR("Error: Could not connect `STDIN' to `/dev/null' (status %d)",
+            status);
+      return 1;
+    }
+
+    status = dup(0);
+    if (status != 1) {
+      ERROR("Error: Could not connect `STDOUT' to `/dev/null' (status %d)",
+            status);
+      return 1;
+    }
+
+    status = dup(0);
+    if (status != 2) {
+      ERROR("Error: Could not connect `STDERR' to `/dev/null', (status %d)",
+            status);
+      return 1;
+    }
+  }    /* if (config.daemonize) */
+#endif /* COLLECT_DAEMON */
+
+  struct sigaction sig_pipe_action = {.sa_handler = SIG_IGN};
+
+  sigaction(SIGPIPE, &sig_pipe_action, NULL);
+
+  /*
+   * install signal handlers
+   */
+  struct sigaction sig_int_action = {.sa_handler = sig_int_handler};
+
+  if (sigaction(SIGINT, &sig_int_action, NULL) != 0) {
+    ERROR("Error: Failed to install a signal handler for signal INT: %s",
+          STRERRNO);
+    return 1;
+  }
+
+  struct sigaction sig_term_action = {.sa_handler = sig_term_handler};
+
+  if (sigaction(SIGTERM, &sig_term_action, NULL) != 0) {
+    ERROR("Error: Failed to install a signal handler for signal TERM: %s",
+          STRERRNO);
+    return 1;
+  }
+
+  struct sigaction sig_usr1_action = {.sa_handler = sig_usr1_handler};
+
+  if (sigaction(SIGUSR1, &sig_usr1_action, NULL) != 0) {
+    ERROR("Error: Failed to install a signal handler for signal USR1: %s",
+          STRERRNO);
+    return 1;
+  }
+
+  int exit_status = run_loop(config.test_readall);
+
+#if COLLECT_DAEMON
+  if (config.daemonize)
+    pidfile_remove();
+#endif /* COLLECT_DAEMON */
+
+  return exit_status;
+} /* int main */
diff --git a/src/daemon/cmd.h b/src/daemon/cmd.h
new file mode 100644 (file)
index 0000000..152ee63
--- /dev/null
@@ -0,0 +1,41 @@
+/**
+ * collectd - src/daemon/cmd.h
+ * Copyright (C) 2018  Florian octo Forster
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ **/
+
+#ifndef CMD_H
+#define CMD_H
+
+#include <stdbool.h>
+
+struct cmdline_config {
+  bool test_config;
+  bool test_readall;
+  bool create_basedir;
+  const char *configfile;
+  bool daemonize;
+};
+
+void stop_collectd(void);
+struct cmdline_config init_config(int argc, char **argv);
+int run_loop(bool test_readall);
+
+#endif /* CMD_H */
index 7e85975..b4668e0 100644 (file)
@@ -25,6 +25,7 @@
  *   Alvaro Barcellos <alvaro.barcellos at gmail.com>
  **/
 
+#include "cmd.h"
 #include "collectd.h"
 
 #include "common.h"
@@ -33,7 +34,6 @@
 
 #include <netdb.h>
 #include <sys/types.h>
-#include <sys/un.h>
 
 #if HAVE_LOCALE_H
 #include <locale.h>
 
 static int loop;
 
-static void *do_flush(void __attribute__((unused)) * arg) {
-  INFO("Flushing all data.");
-  plugin_flush(/* plugin = */ NULL,
-               /* timeout = */ 0,
-               /* ident = */ NULL);
-  INFO("Finished flushing all data.");
-  pthread_exit(NULL);
-  return NULL;
-}
-
-static void sig_int_handler(int __attribute__((unused)) signal) { loop++; }
-
-static void sig_term_handler(int __attribute__((unused)) signal) { loop++; }
-
-static void sig_usr1_handler(int __attribute__((unused)) signal) {
-  pthread_t thread;
-  pthread_attr_t attr;
-
-  /* flushing the data might take a while,
-   * so it should be done asynchronously */
-  pthread_attr_init(&attr);
-  pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-  pthread_create(&thread, &attr, do_flush, NULL);
-  pthread_attr_destroy(&attr);
-}
-
 static int init_hostname(void) {
   const char *str = global_option_get("Hostname");
   if (str && str[0] != '\0') {
@@ -318,120 +292,6 @@ static int do_shutdown(void) {
   return plugin_shutdown_all();
 } /* int do_shutdown */
 
-#if COLLECT_DAEMON
-static int pidfile_create(void) {
-  FILE *fh;
-  const char *file = global_option_get("PIDFile");
-
-  if ((fh = fopen(file, "w")) == NULL) {
-    ERROR("fopen (%s): %s", file, STRERRNO);
-    return 1;
-  }
-
-  fprintf(fh, "%i\n", (int)getpid());
-  fclose(fh);
-
-  return 0;
-} /* static int pidfile_create (const char *file) */
-
-static int pidfile_remove(void) {
-  const char *file = global_option_get("PIDFile");
-  if (file == NULL)
-    return 0;
-
-  return unlink(file);
-} /* static int pidfile_remove (const char *file) */
-#endif /* COLLECT_DAEMON */
-
-#ifdef KERNEL_LINUX
-static int notify_upstart(void) {
-  char const *upstart_job = getenv("UPSTART_JOB");
-
-  if (upstart_job == NULL)
-    return 0;
-
-  if (strcmp(upstart_job, "collectd") != 0) {
-    WARNING("Environment specifies unexpected UPSTART_JOB=\"%s\", expected "
-            "\"collectd\". Ignoring the variable.",
-            upstart_job);
-    return 0;
-  }
-
-  NOTICE("Upstart detected, stopping now to signal readiness.");
-  raise(SIGSTOP);
-  unsetenv("UPSTART_JOB");
-
-  return 1;
-}
-
-static int notify_systemd(void) {
-  size_t su_size;
-  const char *notifysocket = getenv("NOTIFY_SOCKET");
-  if (notifysocket == NULL)
-    return 0;
-
-  if ((strlen(notifysocket) < 2) ||
-      ((notifysocket[0] != '@') && (notifysocket[0] != '/'))) {
-    ERROR("invalid notification socket NOTIFY_SOCKET=\"%s\": path must be "
-          "absolute",
-          notifysocket);
-    return 0;
-  }
-  NOTICE("Systemd detected, trying to signal readiness.");
-
-  unsetenv("NOTIFY_SOCKET");
-
-  int fd;
-#if defined(SOCK_CLOEXEC)
-  fd = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, /* protocol = */ 0);
-#else
-  fd = socket(AF_UNIX, SOCK_DGRAM, /* protocol = */ 0);
-#endif
-  if (fd < 0) {
-    ERROR("creating UNIX socket failed: %s", STRERRNO);
-    return 0;
-  }
-
-  struct sockaddr_un su = {0};
-  su.sun_family = AF_UNIX;
-  if (notifysocket[0] != '@') {
-    /* regular UNIX socket */
-    sstrncpy(su.sun_path, notifysocket, sizeof(su.sun_path));
-    su_size = sizeof(su);
-  } else {
-    /* Linux abstract namespace socket: specify address as "\0foo", i.e.
-     * start with a null byte. Since null bytes have no special meaning in
-     * that case, we have to set su_size correctly to cover only the bytes
-     * that are part of the address. */
-    sstrncpy(su.sun_path, notifysocket, sizeof(su.sun_path));
-    su.sun_path[0] = 0;
-    su_size = sizeof(sa_family_t) + strlen(notifysocket);
-    if (su_size > sizeof(su))
-      su_size = sizeof(su);
-  }
-
-  const char buffer[] = "READY=1\n";
-  if (sendto(fd, buffer, strlen(buffer), MSG_NOSIGNAL, (void *)&su,
-             (socklen_t)su_size) < 0) {
-    ERROR("sendto(\"%s\") failed: %s", notifysocket, STRERRNO);
-    close(fd);
-    return 0;
-  }
-
-  unsetenv("NOTIFY_SOCKET");
-  close(fd);
-  return 1;
-}
-#endif /* KERNEL_LINUX */
-
-struct cmdline_config {
-  bool test_config;
-  bool test_readall;
-  bool create_basedir;
-  const char *configfile;
-  bool daemonize;
-};
-
 static void read_cmdline(int argc, char **argv, struct cmdline_config *config) {
   /* read options */
   while (1) {
@@ -516,9 +376,9 @@ static int configure_collectd(struct cmdline_config *config) {
   return 0;
 }
 
-int main(int argc, char **argv) {
-  int exit_status = 0;
+void stop_collectd(void) { loop++; }
 
+struct cmdline_config init_config(int argc, char **argv) {
   struct cmdline_config config = {
       .daemonize = true, .create_basedir = true, .configfile = CONFIGFILE,
   };
@@ -526,7 +386,7 @@ int main(int argc, char **argv) {
   read_cmdline(argc, argv, &config);
 
   if (config.test_config)
-    return 0;
+    exit(EXIT_SUCCESS);
 
   if (optind < argc)
     exit_usage(1);
@@ -536,109 +396,18 @@ int main(int argc, char **argv) {
   if (configure_collectd(&config) != 0)
     exit(EXIT_FAILURE);
 
-#if COLLECT_DAEMON
-  /*
-   * fork off child
-   */
-  struct sigaction sig_chld_action = {.sa_handler = SIG_IGN};
-
-  sigaction(SIGCHLD, &sig_chld_action, NULL);
-
-  /*
-   * Only daemonize if we're not being supervised
-   * by upstart or systemd (when using Linux).
-   */
-  if (config.daemonize
-#ifdef KERNEL_LINUX
-      && notify_upstart() == 0 && notify_systemd() == 0
-#endif
-      ) {
-    pid_t pid;
-    if ((pid = fork()) == -1) {
-      /* error */
-      fprintf(stderr, "fork: %s", STRERRNO);
-      return 1;
-    } else if (pid != 0) {
-      /* parent */
-      /* printf ("Running (PID %i)\n", pid); */
-      return 0;
-    }
-
-    /* Detach from session */
-    setsid();
-
-    /* Write pidfile */
-    if (pidfile_create())
-      exit(2);
-
-    /* close standard descriptors */
-    close(2);
-    close(1);
-    close(0);
-
-    int status = open("/dev/null", O_RDWR);
-    if (status != 0) {
-      ERROR("Error: Could not connect `STDIN' to `/dev/null' (status %d)",
-            status);
-      return 1;
-    }
-
-    status = dup(0);
-    if (status != 1) {
-      ERROR("Error: Could not connect `STDOUT' to `/dev/null' (status %d)",
-            status);
-      return 1;
-    }
-
-    status = dup(0);
-    if (status != 2) {
-      ERROR("Error: Could not connect `STDERR' to `/dev/null', (status %d)",
-            status);
-      return 1;
-    }
-  }    /* if (config.daemonize) */
-#endif /* COLLECT_DAEMON */
-
-  struct sigaction sig_pipe_action = {.sa_handler = SIG_IGN};
-
-  sigaction(SIGPIPE, &sig_pipe_action, NULL);
-
-  /*
-   * install signal handlers
-   */
-  struct sigaction sig_int_action = {.sa_handler = sig_int_handler};
-
-  if (sigaction(SIGINT, &sig_int_action, NULL) != 0) {
-    ERROR("Error: Failed to install a signal handler for signal INT: %s",
-          STRERRNO);
-    return 1;
-  }
-
-  struct sigaction sig_term_action = {.sa_handler = sig_term_handler};
-
-  if (sigaction(SIGTERM, &sig_term_action, NULL) != 0) {
-    ERROR("Error: Failed to install a signal handler for signal TERM: %s",
-          STRERRNO);
-    return 1;
-  }
-
-  struct sigaction sig_usr1_action = {.sa_handler = sig_usr1_handler};
+  return config;
+}
 
-  if (sigaction(SIGUSR1, &sig_usr1_action, NULL) != 0) {
-    ERROR("Error: Failed to install a signal handler for signal USR1: %s",
-          STRERRNO);
-    return 1;
-  }
+int run_loop(bool test_readall) {
+  int exit_status = 0;
 
-  /*
-   * run the actual loops
-   */
   if (do_init() != 0) {
     ERROR("Error: one or more plugin init callbacks failed.");
     exit_status = 1;
   }
 
-  if (config.test_readall) {
+  if (test_readall) {
     if (plugin_read_all_once() != 0) {
       ERROR("Error: one or more plugin read callbacks failed.");
       exit_status = 1;
@@ -656,10 +425,5 @@ int main(int argc, char **argv) {
     exit_status = 1;
   }
 
-#if COLLECT_DAEMON
-  if (config.daemonize)
-    pidfile_remove();
-#endif /* COLLECT_DAEMON */
-
   return exit_status;
-} /* int main */
+} /* int run_loop */
index 87f05a2..459da4d 100644 (file)
 #define __attribute__(x) /**/
 #endif
 
-#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
-#undef strcpy
-#undef strcat
-#undef strtok
-#pragma GCC poison strcpy strcat strtok
-#endif
-
-/*
- * Special hack for the perl plugin: Because the later included perl.h defines
- * a macro which is never used, but contains `sprintf', we cannot poison that
- * identifies just yet. The parl plugin will do that itself once perl.h is
- * included.
- */
-#ifndef DONT_POISON_SPRINTF_YET
-#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
-#undef sprintf
-#pragma GCC poison sprintf
-#endif
-#endif
-
 #ifndef GAUGE_FORMAT
 #define GAUGE_FORMAT "%.15g"
 #endif
index 667033c..62ce9b8 100644 (file)
@@ -25,9 +25,9 @@
  *   Serhiy Pshyk <serhiyx.pshyk@intel.com>
  **/
 
+#include "collectd.h"
 #include "common.h"
 #include "utils_config_cores.h"
-#include "collectd.h"
 
 #include <pqos.h>
 
@@ -336,8 +336,8 @@ static int rdt_config(oconfig_item_t *ci) {
   return 0;
 }
 
-static void rdt_submit_derive(char *cgroup, char *type, char *type_instance,
-                              derive_t value) {
+static void rdt_submit_derive(const char *cgroup, const char *type,
+                              const char *type_instance, derive_t value) {
   value_list_t vl = VALUE_LIST_INIT;
 
   vl.values = &(value_t){.derive = value};
@@ -352,8 +352,8 @@ static void rdt_submit_derive(char *cgroup, char *type, char *type_instance,
   plugin_dispatch_values(&vl);
 }
 
-static void rdt_submit_gauge(char *cgroup, char *type, char *type_instance,
-                             gauge_t value) {
+static void rdt_submit_gauge(const char *cgroup, const char *type,
+                             const char *type_instance, gauge_t value) {
   value_list_t vl = VALUE_LIST_INIT;
 
   vl.values = &(value_t){.gauge = value};
index 8cfb704..f66d852 100644 (file)
--- a/src/lua.c
+++ b/src/lua.c
  *   Ruben Kerkhof <ruben at rubenkerkhof.com>
  **/
 
-/* <lua5.1/luaconf.h> defines a macro using "sprintf". Although not used here,
- * GCC will complain about the macro definition. */
-#define DONT_POISON_SPRINTF_YET
-
+#include "collectd.h"
 #include "common.h"
 #include "plugin.h"
-#include "collectd.h"
+#include "utils_lua.h"
 
 /* Include the Lua API header files. */
 #include <lauxlib.h>
 #include <lua.h>
 #include <lualib.h>
-#include "utils_lua.h"
 
 #include <pthread.h>
 
-#if COLLECT_DEBUG && __GNUC__
-#undef sprintf
-#pragma GCC poison sprintf
-#endif
-
 typedef struct lua_script_s {
   char *script_path;
   lua_State *lua_state;
index 306d413..31c68ad 100644 (file)
 /* do not automatically get the thread specific Perl interpreter */
 #define PERL_NO_GET_CONTEXT
 
-#define DONT_POISON_SPRINTF_YET 1
-#include "collectd.h"
-
-#undef DONT_POISON_SPRINTF_YET
-
 #include <stdbool.h>
 
 #include <EXTERN.h>
 #include <perl.h>
 
-#if defined(COLLECT_DEBUG) && COLLECT_DEBUG && defined(__GNUC__) && __GNUC__
-#undef sprintf
-#pragma GCC poison sprintf
-#endif
-
 #include <XSUB.h>
 
 /* Some versions of Perl define their own version of DEBUG... :-/ */
index ffe6c5a..86e99c3 100644 (file)
@@ -909,7 +909,7 @@ static void ps_submit_proc_list(procstat_t *ps) {
   gauge_t const delay_factor = 1000000000.0;
 
   struct {
-    char *type_instance;
+    const char *type_instance;
     gauge_t rate_ns;
   } delay_metrics[] = {
       {"delay-cpu", ps->delay_cpu},
index 1f060f8..11ac001 100644 (file)
  *   Florian Forster <octo at collectd.org>
  **/
 
-/* <lua5.1/luaconf.h> defines a macro using "sprintf". Although not used here,
- * GCC will complain about the macro definition. */
-#define DONT_POISON_SPRINTF_YET
-
 #include "common.h"
 #include "utils_lua.h"
 
index 61d9070..e5a3d74 100644 (file)
 #ifndef UTILS_LUA_H
 #define UTILS_LUA_H 1
 
-#include "plugin.h"
 #include "collectd.h"
+#include "plugin.h"
 
-#ifndef DONT_POISON_SPRINTF_YET
-#error "Files including utils_lua.h need to define DONT_POISON_SPRINTF_YET."
-#endif
 #include <lua.h>
 
 /*
index 1ce376c..87ab8fd 100644 (file)
@@ -1024,7 +1024,8 @@ static void domain_state_submit_notif(virDomainPtr dom, int state, int reason) {
   char msg[DATA_MAX_NAME_LEN];
   const char *state_str = domain_states[state];
 #ifdef HAVE_DOM_REASON
-  if ((reason < 0) || ((size_t)reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) {
+  if ((reason < 0) ||
+      ((size_t)reason >= STATIC_ARRAY_SIZE(domain_reasons[0]))) {
     ERROR(PLUGIN_NAME ": Array index out of bounds: reason=%d", reason);
     return;
   }
@@ -1584,7 +1585,7 @@ static int get_block_stats(struct block_device *block_dev) {
 
 #define NM_ADD_STR_ITEMS(_items, _size)                                        \
   do {                                                                         \
-    for (size_t _i = 0; _i < _size; ++_i) {                                       \
+    for (size_t _i = 0; _i < _size; ++_i) {                                    \
       DEBUG(PLUGIN_NAME                                                        \
             " plugin: Adding notification metadata name=%s value=%s",          \
             _items[_i].name, _items[_i].value);                                \
@@ -1824,7 +1825,7 @@ static int get_if_dev_stats(struct interface_device *if_dev) {
   return 0;
 }
 
-static int domain_lifecycle_event_cb(__attribute__((unused)) virConnectPtr conn,
+static int domain_lifecycle_event_cb(__attribute__((unused)) virConnectPtr con_,
                                      virDomainPtr dom, int event, int detail,
                                      __attribute__((unused)) void *opaque) {
   int domain_state = map_domain_event_to_state(event);