Merge branch 'collectd-5.7' into collectd-5.8
[collectd.git] / src / numa.c
index 8f5bf48..56ea707 100644 (file)
 #include "plugin.h"
 
 #if !KERNEL_LINUX
-# error "No applicable input method."
+#error "No applicable input method."
 #endif
 
 #ifndef NUMA_ROOT_DIR
-# define NUMA_ROOT_DIR "/sys/devices/system/node"
+#define NUMA_ROOT_DIR "/sys/devices/system/node"
 #endif
 
 static int max_node = -1;
 
-static void numa_dispatch_value (int node, /* {{{ */
-    const char *type_instance, value_t v)
-{
+static void numa_dispatch_value(int node, /* {{{ */
+                                const char *type_instance, value_t v) {
   value_list_t vl = VALUE_LIST_INIT;
 
   vl.values = &v;
   vl.values_len = 1;
 
-  sstrncpy (vl.host, hostname_g, sizeof (vl.host));
-  sstrncpy (vl.plugin, "numa", sizeof (vl.plugin));
-  ssnprintf (vl.plugin_instance, sizeof (vl.plugin_instance), "node%i", node);
-  sstrncpy (vl.type, "vmpage_action", sizeof (vl.type));
-  sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
+  sstrncpy(vl.plugin, "numa", sizeof(vl.plugin));
+  snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "node%i", node);
+  sstrncpy(vl.type, "vmpage_action", sizeof(vl.type));
+  sstrncpy(vl.type_instance, type_instance, sizeof(vl.type_instance));
 
-  plugin_dispatch_values (&vl);
+  plugin_dispatch_values(&vl);
 } /* }}} void numa_dispatch_value */
 
-static int numa_read_node (int node) /* {{{ */
+static int numa_read_node(int node) /* {{{ */
 {
   char path[PATH_MAX];
   FILE *fh;
@@ -64,105 +62,93 @@ static int numa_read_node (int node) /* {{{ */
   int status;
   int success;
 
-  ssnprintf (path, sizeof (path), NUMA_ROOT_DIR "/node%i/numastat", node);
+  snprintf(path, sizeof(path), NUMA_ROOT_DIR "/node%i/numastat", node);
 
-  fh = fopen (path, "r");
-  if (fh == NULL)
-  {
+  fh = fopen(path, "r");
+  if (fh == NULL) {
     char errbuf[1024];
-    ERROR ("numa plugin: Reading node %i failed: open(%s): %s",
-        node, path, sstrerror (errno, errbuf, sizeof (errbuf)));
-    return (-1);
+    ERROR("numa plugin: Reading node %i failed: open(%s): %s", node, path,
+          sstrerror(errno, errbuf, sizeof(errbuf)));
+    return -1;
   }
 
   success = 0;
-  while (fgets (buffer, sizeof (buffer), fh) != NULL)
-  {
+  while (fgets(buffer, sizeof(buffer), fh) != NULL) {
     char *fields[4];
     value_t v;
 
-    status = strsplit (buffer, fields, STATIC_ARRAY_SIZE (fields));
-    if (status != 2)
-    {
-      WARNING ("numa plugin: Ignoring line with unexpected "
-          "number of fields (node %i).", node);
+    status = strsplit(buffer, fields, STATIC_ARRAY_SIZE(fields));
+    if (status != 2) {
+      WARNING("numa plugin: Ignoring line with unexpected "
+              "number of fields (node %i).",
+              node);
       continue;
     }
 
     v.derive = 0;
-    status = parse_value (fields[1], &v, DS_TYPE_DERIVE);
+    status = parse_value(fields[1], &v, DS_TYPE_DERIVE);
     if (status != 0)
       continue;
 
-    numa_dispatch_value (node, fields[0], v);
+    numa_dispatch_value(node, fields[0], v);
     success++;
   }
 
-  fclose (fh);
-  return (success ? 0 : -1);
+  fclose(fh);
+  return success ? 0 : -1;
 } /* }}} int numa_read_node */
 
-static int numa_read (void) /* {{{ */
+static int numa_read(void) /* {{{ */
 {
   int i;
   int status;
   int success;
 
-  if (max_node < 0)
-  {
-    WARNING ("numa plugin: No NUMA nodes were detected.");
-    return (-1);
+  if (max_node < 0) {
+    WARNING("numa plugin: No NUMA nodes were detected.");
+    return -1;
   }
 
   success = 0;
-  for (i = 0; i <= max_node; i++)
-  {
-    status = numa_read_node (i);
+  for (i = 0; i <= max_node; i++) {
+    status = numa_read_node(i);
     if (status == 0)
       success++;
   }
 
-  return (success ? 0 : -1);
+  return success ? 0 : -1;
 } /* }}} int numa_read */
 
-static int numa_init (void) /* {{{ */
+static int numa_init(void) /* {{{ */
 {
   /* Determine the number of nodes on this machine. */
-  while (42)
-  {
+  while (42) {
     char path[PATH_MAX];
-    struct stat statbuf = { 0 };
+    struct stat statbuf = {0};
     int status;
 
-    ssnprintf (path, sizeof (path), NUMA_ROOT_DIR "/node%i", max_node + 1);
+    snprintf(path, sizeof(path), NUMA_ROOT_DIR "/node%i", max_node + 1);
 
-    status = stat (path, &statbuf);
-    if (status == 0)
-    {
+    status = stat(path, &statbuf);
+    if (status == 0) {
       max_node++;
       continue;
-    }
-    else if (errno == ENOENT)
-    {
+    } else if (errno == ENOENT) {
       break;
-    }
-    else /* ((status != 0) && (errno != ENOENT)) */
+    } else /* ((status != 0) && (errno != ENOENT)) */
     {
       char errbuf[1024];
-      ERROR ("numa plugin: stat(%s) failed: %s", path,
-          sstrerror (errno, errbuf, sizeof (errbuf)));
-      return (-1);
+      ERROR("numa plugin: stat(%s) failed: %s", path,
+            sstrerror(errno, errbuf, sizeof(errbuf)));
+      return -1;
     }
   }
 
-  DEBUG ("numa plugin: Found %i nodes.", max_node + 1);
-  return (0);
+  DEBUG("numa plugin: Found %i nodes.", max_node + 1);
+  return 0;
 } /* }}} int numa_init */
 
-void module_register (void)
-{
-  plugin_register_init ("numa", numa_init);
-  plugin_register_read ("numa", numa_read);
+void module_register(void) {
+  plugin_register_init("numa", numa_init);
+  plugin_register_read("numa", numa_read);
 } /* void module_register */
-
-/* vim: set sw=2 sts=2 et : */