Merge branch 'collectd-5.8'
authorFlorian Forster <octo@collectd.org>
Sat, 18 Nov 2017 08:56:30 +0000 (09:56 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 18 Nov 2017 08:56:30 +0000 (09:56 +0100)
1  2 
src/mcelog.c
src/processes.c
src/utils_ovs.c
src/zfs_arc.c

diff --combined src/mcelog.c
@@@ -75,12 -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);
@@@ -237,12 -237,15 +237,12 @@@ static int socket_close(socket_adapter_
    int ret = 0;
    pthread_rwlock_rdlock(&self->lock);
    if (fcntl(self->sock_fd, F_GETFL) != -1) {
 -    char errbuf[MCELOG_BUFF_SIZE];
      if (shutdown(self->sock_fd, SHUT_RDWR) != 0) {
 -      ERROR(MCELOG_PLUGIN ": Socket shutdown failed: %s",
 -            sstrerror(errno, errbuf, sizeof(errbuf)));
 +      ERROR(MCELOG_PLUGIN ": Socket shutdown failed: %s", STRERRNO);
        ret = -1;
      }
      if (close(self->sock_fd) != 0) {
 -      ERROR(MCELOG_PLUGIN ": Socket close failed: %s",
 -            sstrerror(errno, errbuf, sizeof(errbuf)));
 +      ERROR(MCELOG_PLUGIN ": Socket close failed: %s", STRERRNO);
        ret = -1;
      }
    }
@@@ -274,6 -277,7 +274,6 @@@ static void mcelog_dispatch_notificatio
  }
  
  static int socket_reinit(socket_adapter_t *self) {
 -  char errbuff[MCELOG_BUFF_SIZE];
    int ret = -1;
    cdtime_t interval = plugin_get_interval();
    struct timeval socket_timeout = CDTIME_T_TO_TIMEVAL(interval);
    self->sock_fd =
        socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
    if (self->sock_fd < 0) {
 -    ERROR(MCELOG_PLUGIN ": Could not create a socket. %s",
 -          sstrerror(errno, errbuff, sizeof(errbuff)));
 +    ERROR(MCELOG_PLUGIN ": Could not create a socket. %s", STRERRNO);
      pthread_rwlock_unlock(&self->lock);
      return ret;
    }
    pthread_rwlock_rdlock(&self->lock);
    if (connect(self->sock_fd, (struct sockaddr *)&(self->unix_sock),
                sizeof(self->unix_sock)) < 0) {
 -    ERROR(MCELOG_PLUGIN ": Failed to connect to mcelog server. %s",
 -          sstrerror(errno, errbuff, sizeof(errbuff)));
 +    ERROR(MCELOG_PLUGIN ": Failed to connect to mcelog server. %s", STRERRNO);
      self->close(self);
      ret = -1;
    } else {
@@@ -528,7 -534,9 +528,7 @@@ static int socket_receive(socket_adapte
  
    if ((res = poll(&poll_fd, 1, MCELOG_POLL_TIMEOUT)) <= 0) {
      if (res != 0 && errno != EINTR) {
 -      char errbuf[MCELOG_BUFF_SIZE];
 -      ERROR("mcelog: poll failed: %s",
 -            sstrerror(errno, errbuf, sizeof(errbuf)));
 +      ERROR("mcelog: poll failed: %s", STRERRNO);
      }
      pthread_rwlock_unlock(&self->lock);
      return res;
  }
  
  static void *poll_worker(__attribute__((unused)) void *arg) {
 -  char errbuf[MCELOG_BUFF_SIZE];
    mcelog_thread_running = 1;
    FILE **pp_file = calloc(1, sizeof(*pp_file));
    if (pp_file == NULL) {
 -    ERROR("mcelog: memory allocation failed: %s",
 -          sstrerror(errno, errbuf, sizeof(errbuf)));
 +    ERROR("mcelog: memory allocation failed: %s", STRERRNO);
      pthread_exit((void *)1);
    }
  
diff --combined src/processes.c
@@@ -502,7 -502,7 +502,7 @@@ static void ps_list_add(const char *nam
        ps_update_counter(&ps->io_diskw, &pse->io_diskw, entry->io_diskw);
      }
  
-     if ((entry->cswitch_vol != -1) && (entry->cswitch_vol != -1)) {
+     if ((entry->cswitch_vol != -1) && (entry->cswitch_invol != -1)) {
        ps_update_counter(&ps->cswitch_vol, &pse->cswitch_vol,
                          entry->cswitch_vol);
        ps_update_counter(&ps->cswitch_invol, &pse->cswitch_invol,
@@@ -904,7 -904,9 +904,7 @@@ static int ps_read_tasks_status(process
      } /* while (fgets) */
  
      if (fclose(fh)) {
 -      char errbuf[1024];
 -      WARNING("processes: fclose: %s",
 -              sstrerror(errno, errbuf, sizeof(errbuf)));
 +      WARNING("processes: fclose: %s", STRERRNO);
      }
    }
    closedir(dh);
@@@ -960,7 -962,8 +960,7 @@@ static int ps_read_status(long pid, pro
    } /* while (fgets) */
  
    if (fclose(fh)) {
 -    char errbuf[1024];
 -    WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 +    WARNING("processes: fclose: %s", STRERRNO);
    }
  
    ps->vmem_data = data * 1024;
@@@ -1020,7 -1023,8 +1020,7 @@@ static int ps_read_io(process_entry_t *
    } /* while (fgets) */
  
    if (fclose(fh)) {
 -    char errbuf[1024];
 -    WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 +    WARNING("processes: fclose: %s", STRERRNO);
    }
    return 0;
  } /* int ps_read_io (...) */
@@@ -1044,7 -1048,8 +1044,7 @@@ static int ps_count_maps(pid_t pid) 
    } /* while (fgets) */
  
    if (fclose(fh)) {
 -    char errbuf[1024];
 -    WARNING("processes: fclose: %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 +    WARNING("processes: fclose: %s", STRERRNO);
    }
    return count;
  } /* int ps_count_maps (...) */
@@@ -1255,10 -1260,12 +1255,10 @@@ static char *ps_get_cmdline(long pid, c
    errno = 0;
    fd = open(file, O_RDONLY);
    if (fd < 0) {
 -    char errbuf[4096];
      /* ENOENT means the process exited while we were handling it.
       * Don't complain about this, it only fills the logs. */
      if (errno != ENOENT)
 -      WARNING("processes plugin: Failed to open `%s': %s.", file,
 -              sstrerror(errno, errbuf, sizeof(errbuf)));
 +      WARNING("processes plugin: Failed to open `%s': %s.", file, STRERRNO);
      return NULL;
    }
  
      status = read(fd, (void *)buf_ptr, len);
  
      if (status < 0) {
 -      char errbuf[1024];
  
        if ((EAGAIN == errno) || (EINTR == errno))
          continue;
  
        WARNING("processes plugin: Failed to read from `%s': %s.", file,
 -              sstrerror(errno, errbuf, sizeof(errbuf)));
 +              STRERRNO);
        close(fd);
        return NULL;
      }
@@@ -1336,7 -1344,9 +1336,7 @@@ static int read_fork_rate(void) 
  
    proc_stat = fopen("/proc/stat", "r");
    if (proc_stat == NULL) {
 -    char errbuf[1024];
 -    ERROR("processes plugin: fopen (/proc/stat) failed: %s",
 -          sstrerror(errno, errbuf, sizeof(errbuf)));
 +    ERROR("processes plugin: fopen (/proc/stat) failed: %s", STRERRNO);
      return -1;
    }
  
@@@ -1848,7 -1858,8 +1848,7 @@@ static int ps_read(void) 
    ps_list_reset();
  
    if ((proc = opendir("/proc")) == NULL) {
 -    char errbuf[1024];
 -    ERROR("Cannot open `/proc': %s", sstrerror(errno, errbuf, sizeof(errbuf)));
 +    ERROR("Cannot open `/proc': %s", STRERRNO);
      return -1;
    }
  
diff --combined src/utils_ovs.c
@@@ -263,12 -263,11 +263,11 @@@ static void ovs_db_callback_remove(ovs_
  /* Remove all callbacks form OVS DB object */
  static void ovs_db_callback_remove_all(ovs_db_t *pdb) {
    pthread_mutex_lock(&pdb->mutex);
-   for (ovs_callback_t *del_cb = pdb->remote_cb; pdb->remote_cb;
-        del_cb = pdb->remote_cb) {
+   while (pdb->remote_cb != NULL) {
+     ovs_callback_t *del_cb = pdb->remote_cb;
      pdb->remote_cb = del_cb->next;
-     free(del_cb);
+     sfree(del_cb);
    }
-   pdb->remote_cb = NULL;
    pthread_mutex_unlock(&pdb->mutex);
  }
  
@@@ -751,14 -750,17 +750,14 @@@ static void ovs_db_reconnect(ovs_db_t *
    }
    /* try to connect to the server */
    for (struct addrinfo *rp = result; rp != NULL; rp = rp->ai_next) {
 -    char errbuff[OVS_ERROR_BUFF_SIZE];
      int sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
      if (sock < 0) {
 -      sstrerror(errno, errbuff, sizeof(errbuff));
 -      OVS_DEBUG("socket(): %s", errbuff);
 +      OVS_DEBUG("socket(): %s", STRERRNO);
        continue;
      }
      if (connect(sock, rp->ai_addr, rp->ai_addrlen) < 0) {
        close(sock);
 -      sstrerror(errno, errbuff, sizeof(errbuff));
 -      OVS_DEBUG("connect(): %s [family=%d]", errbuff, rp->ai_family);
 +      OVS_DEBUG("connect(): %s [family=%d]", STRERRNO, rp->ai_family);
      } else {
        /* send notification to event thread */
        ovs_db_event_post(pdb, OVS_DB_EVENT_CONN_ESTABLISHED);
@@@ -793,10 -795,12 +792,10 @@@ static void *ovs_poll_worker(void *arg
  
    /* poll data */
    while (ovs_db_poll_is_running(pdb)) {
 -    char errbuff[OVS_ERROR_BUFF_SIZE];
      poll_fd.fd = pdb->sock;
      int poll_ret = poll(&poll_fd, 1, /* ms */ OVS_DB_POLL_TIMEOUT * 1000);
      if (poll_ret < 0) {
 -      sstrerror(errno, errbuff, sizeof(errbuff));
 -      OVS_ERROR("poll(): %s", errbuff);
 +      OVS_ERROR("poll(): %s", STRERRNO);
        break;
      } else if (poll_ret == 0) {
        OVS_DEBUG("poll(): timeout");
        char buff[OVS_DB_POLL_READ_BLOCK_SIZE];
        ssize_t nbytes = recv(poll_fd.fd, buff, sizeof(buff), 0);
        if (nbytes < 0) {
 -        sstrerror(errno, errbuff, sizeof(errbuff));
 -        OVS_ERROR("recv(): %s", errbuff);
 +        OVS_ERROR("recv(): %s", STRERRNO);
          /* read error? Try to reconnect */
          close(poll_fd.fd);
          continue;
@@@ -896,7 -901,7 +895,7 @@@ static void *ovs_event_worker(void *arg
  
  /* Initialize EVENT thread */
  static int ovs_db_event_thread_init(ovs_db_t *pdb) {
-   pdb->event_thread.tid = (pthread_t)-1;
+   pdb->event_thread.tid = (pthread_t){0};
    /* init event thread condition variable */
    if (pthread_cond_init(&pdb->event_thread.cond, NULL)) {
      return -1;
  }
  
  /* Destroy EVENT thread */
+ /* XXX: Must hold pdb->mutex when calling! */
  static int ovs_db_event_thread_destroy(ovs_db_t *pdb) {
-   if (pdb->event_thread.tid == (pthread_t)-1)
+   if (pthread_equal(pdb->event_thread.tid, (pthread_t){0})) {
      /* already destroyed */
      return 0;
+   }
    ovs_db_event_post(pdb, OVS_DB_EVENT_TERMINATE);
    if (pthread_join(pdb->event_thread.tid, NULL) != 0)
      return -1;
    pthread_mutex_unlock(&pdb->event_thread.mutex);
    pthread_mutex_destroy(&pdb->event_thread.mutex);
    pthread_cond_destroy(&pdb->event_thread.cond);
-   pdb->event_thread.tid = (pthread_t)-1;
+   pdb->event_thread.tid = (pthread_t){0};
    return 0;
  }
  
  /* Initialize POLL thread */
  static int ovs_db_poll_thread_init(ovs_db_t *pdb) {
-   pdb->poll_thread.tid = (pthread_t)-1;
+   pdb->poll_thread.tid = (pthread_t){0};
    /* init event thread mutex */
    if (pthread_mutex_init(&pdb->poll_thread.mutex, NULL)) {
      return -1;
  }
  
  /* Destroy POLL thread */
+ /* XXX: Must hold pdb->mutex when calling! */
  static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) {
-   if (pdb->poll_thread.tid == (pthread_t)-1)
+   if (pthread_equal(pdb->poll_thread.tid, (pthread_t){0})) {
      /* already destroyed */
      return 0;
+   }
    /* change thread state */
    pthread_mutex_lock(&pdb->poll_thread.mutex);
    pdb->poll_thread.state = OVS_DB_POLL_STATE_EXITING;
    if (pthread_join(pdb->poll_thread.tid, NULL) != 0)
      return -1;
    pthread_mutex_destroy(&pdb->poll_thread.mutex);
-   pdb->poll_thread.tid = (pthread_t)-1;
+   pdb->poll_thread.tid = (pthread_t){0};
    return 0;
  }
  
@@@ -1253,15 -1262,17 +1256,17 @@@ int ovs_db_destroy(ovs_db_t *pdb) 
    /* stop poll thread */
    if (ovs_db_event_thread_destroy(pdb) < 0) {
      OVS_ERROR("destroy poll thread failed");
-     ovs_db_ret = (-1);
+     ovs_db_ret = -1;
    }
  
    /* stop event thread */
    if (ovs_db_poll_thread_destroy(pdb) < 0) {
      OVS_ERROR("stop event thread failed");
-     ovs_db_ret = (-1);
+     ovs_db_ret = -1;
    }
  
+   pthread_mutex_unlock(&pdb->mutex);
    /* unsubscribe callbacks */
    ovs_db_callback_remove_all(pdb);
  
      close(pdb->sock);
  
    /* release DB handler */
-   pthread_mutex_unlock(&pdb->mutex);
    pthread_mutex_destroy(&pdb->mutex);
    sfree(pdb);
    return ovs_db_ret;
diff --combined src/zfs_arc.c
@@@ -202,31 -202,27 +202,26 @@@ static int za_read(void) 
  
    fh = fopen(ZOL_ARCSTATS_FILE, "r");
    if (fh == NULL) {
 -    char errbuf[1024];
      ERROR("zfs_arc plugin: Opening \"%s\" failed: %s", ZOL_ARCSTATS_FILE,
 -          sstrerror(errno, errbuf, sizeof(errbuf)));
 +          STRERRNO);
      return -1;
    }
  
-   ksp = llist_create();
-   if (ksp == NULL) {
-     ERROR("zfs_arc plugin: `llist_create' failed.");
-     fclose(fh);
-     return -1;
-   }
-   // Ignore the first two lines because they contain information about
-   // the rest of the file.
-   // See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel
-   // module.
-   if (fgets(buffer, sizeof(buffer), fh) == NULL) {
-     ERROR("zfs_arc plugin: \"%s\" does not contain a single line.",
+   /* Ignore the first two lines because they contain information about the rest
+    * of the file.
+    * See kstat_seq_show_headers module/spl/spl-kstat.c of the spl kernel module.
+    */
+   if ((fgets(buffer, sizeof(buffer), fh) == NULL) ||
+       (fgets(buffer, sizeof(buffer), fh) == NULL)) {
+     ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
            ZOL_ARCSTATS_FILE);
      fclose(fh);
      return -1;
    }
-   if (fgets(buffer, sizeof(buffer), fh) == NULL) {
-     ERROR("zfs_arc plugin: \"%s\" does not contain at least two lines.",
-           ZOL_ARCSTATS_FILE);
+   ksp = llist_create();
+   if (ksp == NULL) {
+     ERROR("zfs_arc plugin: `llist_create' failed.");
      fclose(fh);
      return -1;
    }