Merge pull request #2742 from elfiesmelfie/ipmi_bugfix_sensor_option
[collectd.git] / src / mcelog.c
index 22c8807..6fd4623 100644 (file)
@@ -52,9 +52,9 @@
 #define MCELOG_UNCORRECTED_ERR_TYPE_INS "uncorrected_memory_errors"
 
 typedef struct mcelog_config_s {
-  char logfile[PATH_MAX]; /* mcelog logfile */
-  pthread_t tid;          /* poll thread id */
-  llist_t *dimms_list;    /* DIMMs list */
+  char logfile[PATH_MAX];     /* mcelog logfile */
+  pthread_t tid;              /* poll thread id */
+  llist_t *dimms_list;        /* DIMMs list */
   pthread_mutex_t dimms_lock; /* lock for dimms cache */
   _Bool persist;
 } mcelog_config_t;
@@ -75,12 +75,12 @@ struct socket_adapter_s {
 typedef struct mcelog_memory_rec_s {
   int corrected_err_total; /* x total*/
   int corrected_err_timed; /* x in 24h*/
-  char corrected_err_timed_period[DATA_MAX_NAME_LEN];
+  char corrected_err_timed_period[DATA_MAX_NAME_LEN / 2];
   int uncorrected_err_total; /* x total*/
   int uncorrected_err_timed; /* x in 24h*/
-  char uncorrected_err_timed_period[DATA_MAX_NAME_LEN];
-  char location[DATA_MAX_NAME_LEN];  /* SOCKET x CHANNEL x DIMM x*/
-  char dimm_name[DATA_MAX_NAME_LEN]; /* DMI_NAME "DIMM_F1" */
+  char uncorrected_err_timed_period[DATA_MAX_NAME_LEN / 2];
+  char location[DATA_MAX_NAME_LEN / 2];  /* SOCKET x CHANNEL x DIMM x*/
+  char dimm_name[DATA_MAX_NAME_LEN / 2]; /* DMI_NAME "DIMM_F1" */
 } mcelog_memory_rec_t;
 
 static int socket_close(socket_adapter_t *self);
@@ -124,8 +124,8 @@ static llentry_t *mcelog_dimm(const mcelog_memory_rec_t *rec,
   char dimm_name[DATA_MAX_NAME_LEN];
 
   if (strlen(rec->dimm_name) > 0) {
-    ssnprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
-              rec->dimm_name);
+    snprintf(dimm_name, sizeof(dimm_name), "%s_%s", rec->location,
+             rec->dimm_name);
   } else
     sstrncpy(dimm_name, rec->location, sizeof(dimm_name));
 
@@ -257,7 +257,7 @@ static int socket_write(socket_adapter_t *self, const char *msg,
                         const size_t len) {
   int ret = 0;
   pthread_rwlock_rdlock(&self->lock);
-  if (swrite(self->sock_fd, msg, len) < 0)
+  if (swrite(self->sock_fd, msg, len) != 0)
     ret = -1;
   pthread_rwlock_unlock(&self->lock);
   return ret;
@@ -361,8 +361,8 @@ static int mcelog_dispatch_mem_notifications(const mcelog_memory_rec_t *mr) {
   sstrncpy(n.host, hostname_g, sizeof(n.host));
 
   if (mr->dimm_name[0] != '\0')
-    ssnprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
-              mr->location, mr->dimm_name);
+    snprintf(n.plugin_instance, sizeof(n.plugin_instance), "%s_%s",
+             mr->location, mr->dimm_name);
   else
     sstrncpy(n.plugin_instance, mr->location, sizeof(n.plugin_instance));
 
@@ -373,7 +373,7 @@ static int mcelog_dispatch_mem_notifications(const mcelog_memory_rec_t *mr) {
                                             mr->corrected_err_total);
     plugin_notification_meta_add_signed_int(&n, MCELOG_CORRECTED_ERR_TIMED,
                                             mr->corrected_err_timed);
-    ssnprintf(n.message, sizeof(n.message), MCELOG_CORRECTED_ERR);
+    snprintf(n.message, sizeof(n.message), MCELOG_CORRECTED_ERR);
     sstrncpy(n.type_instance, MCELOG_CORRECTED_ERR_TYPE_INS,
              sizeof(n.type_instance));
     plugin_dispatch_notification(&n);
@@ -389,7 +389,7 @@ static int mcelog_dispatch_mem_notifications(const mcelog_memory_rec_t *mr) {
                                             mr->uncorrected_err_total);
     plugin_notification_meta_add_signed_int(&n, MCELOG_UNCORRECTED_ERR_TIMED,
                                             mr->uncorrected_err_timed);
-    ssnprintf(n.message, sizeof(n.message), MCELOG_UNCORRECTED_ERR);
+    snprintf(n.message, sizeof(n.message), MCELOG_UNCORRECTED_ERR);
     sstrncpy(n.type_instance, MCELOG_UNCORRECTED_ERR_TYPE_INS,
              sizeof(n.type_instance));
     n.severity = NOTIF_FAILURE;
@@ -427,15 +427,15 @@ static int mcelog_submit(const mcelog_memory_rec_t *mr) {
   mcelog_update_dimm_stats(dimm, mr);
 
   if (mr->dimm_name[0] != '\0')
-    ssnprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
-              mr->location, mr->dimm_name);
+    snprintf(vl.plugin_instance, sizeof(vl.plugin_instance), "%s_%s",
+             mr->location, mr->dimm_name);
   else
     sstrncpy(vl.plugin_instance, mr->location, sizeof(vl.plugin_instance));
 
   plugin_dispatch_values(&vl);
 
-  ssnprintf(vl.type_instance, sizeof(vl.type_instance),
-            "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
+  snprintf(vl.type_instance, sizeof(vl.type_instance),
+           "corrected_memory_errors_in_%s", mr->corrected_err_timed_period);
   vl.values = &(value_t){.derive = (derive_t)mr->corrected_err_timed};
   plugin_dispatch_values(&vl);
 
@@ -444,9 +444,8 @@ static int mcelog_submit(const mcelog_memory_rec_t *mr) {
   vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_total};
   plugin_dispatch_values(&vl);
 
-  ssnprintf(vl.type_instance, sizeof(vl.type_instance),
-            "uncorrected_memory_errors_in_%s",
-            mr->uncorrected_err_timed_period);
+  snprintf(vl.type_instance, sizeof(vl.type_instance),
+           "uncorrected_memory_errors_in_%s", mr->uncorrected_err_timed_period);
   vl.values = &(value_t){.derive = (derive_t)mr->uncorrected_err_timed};
   plugin_dispatch_values(&vl);