From: collectd bot <32910397+collectd-bot@users.noreply.github.com> Date: Fri, 17 Nov 2017 15:44:07 +0000 (+0100) Subject: Auto-Merge pull request #2550 from octo/cid/179234 X-Git-Tag: collectd-5.8.0~4 X-Git-Url: https://git.octo.it/?p=collectd.git;a=commitdiff_plain;h=7a18567e6dd707f6d1d1367be5a970b3dc5fef56;hp=47cb204f324be21ae54084fbe9e338d854b87bf5 Auto-Merge pull request #2550 from octo/cid/179234 Automatically merged due to "Automerge" label --- diff --git a/src/utils_ovs.c b/src/utils_ovs.c index 20873247..ae82253b 100644 --- a/src/utils_ovs.c +++ b/src/utils_ovs.c @@ -263,12 +263,11 @@ static void ovs_db_callback_remove(ovs_db_t *pdb, ovs_callback_t *del_cb) { /* 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); } @@ -902,7 +901,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; @@ -935,10 +934,12 @@ static int ovs_db_event_thread_init(ovs_db_t *pdb) { } /* 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; @@ -949,13 +950,13 @@ static int ovs_db_event_thread_destroy(ovs_db_t *pdb) { 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; @@ -973,10 +974,12 @@ static int ovs_db_poll_thread_init(ovs_db_t *pdb) { } /* 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; @@ -985,7 +988,7 @@ static int ovs_db_poll_thread_destroy(ovs_db_t *pdb) { 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; } @@ -1259,15 +1262,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); @@ -1276,7 +1281,6 @@ int ovs_db_destroy(ovs_db_t *pdb) { close(pdb->sock); /* release DB handler */ - pthread_mutex_unlock(&pdb->mutex); pthread_mutex_destroy(&pdb->mutex); sfree(pdb); return ovs_db_ret; diff --git a/src/zfs_arc.c b/src/zfs_arc.c index e589184c..5d37f9f1 100644 --- a/src/zfs_arc.c +++ b/src/zfs_arc.c @@ -208,26 +208,21 @@ static int za_read(void) { 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; }