Merge branch 'collectd-5.7' into collectd-5.8
[collectd.git] / src / xencpu.c
index e28c91e..8cba476 100644 (file)
@@ -51,7 +51,7 @@ static int xencpu_init(void) {
   xc_handle = xc_interface_open(XC_INTERFACE_INIT_ARGS);
   if (!xc_handle) {
     ERROR("xencpu: xc_interface_open() failed");
-    return (-1);
+    return -1;
   }
 
   xc_physinfo_t *physinfo;
@@ -60,14 +60,14 @@ static int xencpu_init(void) {
   if (physinfo == NULL) {
     ERROR("xencpu plugin: calloc() for physinfo failed.");
     xc_interface_close(xc_handle);
-    return (ENOMEM);
+    return ENOMEM;
   }
 
   if (xc_physinfo(xc_handle, physinfo) < 0) {
     ERROR("xencpu plugin: xc_physinfo() failed");
     xc_interface_close(xc_handle);
     free(physinfo);
-    return (-1);
+    return -1;
   }
 
   num_cpus = physinfo->nr_cpus;
@@ -79,7 +79,7 @@ static int xencpu_init(void) {
   if (cpu_info == NULL) {
     ERROR("xencpu plugin: calloc() for num_cpus failed.");
     xc_interface_close(xc_handle);
-    return (ENOMEM);
+    return ENOMEM;
   }
 
   cpu_states = calloc(num_cpus, sizeof(value_to_rate_state_t));
@@ -87,10 +87,10 @@ static int xencpu_init(void) {
     ERROR("xencpu plugin: calloc() for cpu_states failed.");
     xc_interface_close(xc_handle);
     free(cpu_info);
-    return (ENOMEM);
+    return ENOMEM;
   }
 
-  return (0);
+  return 0;
 } /* static int xencpu_init */
 
 static int xencpu_shutdown(void) {
@@ -101,22 +101,18 @@ static int xencpu_shutdown(void) {
   return 0;
 } /* static int xencpu_shutdown */
 
-static void submit_value(int cpu_num, gauge_t percent) {
-  value_t values[1];
+static void submit_value(int cpu_num, gauge_t value) {
   value_list_t vl = VALUE_LIST_INIT;
 
-  values[0].gauge = percent;
-
-  vl.values = values;
+  vl.values = &(value_t){.gauge = value};
   vl.values_len = 1;
 
-  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
   sstrncpy(vl.plugin, "xencpu", sizeof(vl.plugin));
   sstrncpy(vl.type, "percent", sizeof(vl.type));
   sstrncpy(vl.type_instance, "load", sizeof(vl.type_instance));
 
   if (cpu_num >= 0) {
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", cpu_num);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%i", cpu_num);
   }
   plugin_dispatch_values(&vl);
 } /* static void submit_value */
@@ -130,21 +126,21 @@ static int xencpu_read(void) {
   if (rc < 0) {
     ERROR("xencpu: xc_getcpuinfo() Failed: %d %s\n", rc,
           xc_strerror(xc_handle, errno));
-    return (-1);
+    return -1;
   }
 
   int status;
   for (int cpu = 0; cpu < nr_cpus; cpu++) {
     gauge_t rate = NAN;
-    value_t value = {.derive = cpu_info[cpu].idletime};
 
-    status = value_to_rate(&rate, value, DS_TYPE_DERIVE, now, &cpu_states[cpu]);
+    status = value_to_rate(&rate, (value_t){.derive = cpu_info[cpu].idletime},
+                           DS_TYPE_DERIVE, now, &cpu_states[cpu]);
     if (status == 0) {
       submit_value(cpu, 100 - rate / 10000000);
     }
   }
 
-  return (0);
+  return 0;
 } /* static int xencpu_read */
 
 void module_register(void) {