Просмотр исходного кода

daemon cleanup (#4231)

* c code cleanup; eliminate all errors and warning under clion

* removed old server API

* removed obsolete "file" API command

* included common.h everywhere

* fix for github syntax highlighting

* enable CLion to build all netdata binaries

* added locks verification to cmake
Costa Tsaousis 6 лет назад
Родитель
Сommit
2b14e31bef
10 измененных файлов с 66 добавлено и 56 удалено
  1. 17 7
      CMakeLists.txt
  2. 0 4
      src/Makefile.am
  3. 2 1
      src/adaptive_resortable_list.c
  4. 2 3
      src/adaptive_resortable_list.h
  5. 1 0
      src/appconfig.c
  6. 1 0
      src/appconfig.h
  7. 31 30
      src/avl.c
  8. 10 10
      src/avl.h
  9. 1 0
      src/backend_prometheus.c
  10. 1 1
      src/backend_prometheus.h

+ 17 - 7
CMakeLists.txt

@@ -8,7 +8,7 @@ project(netdata C)
 
 find_package (Threads)
 
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat-signedness -Werror=format-security -DNETDATA_INTERNAL_CHECKS=1 -fstack-protector-all")
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat-signedness -Werror=format-security -DNETDATA_INTERNAL_CHECKS=1 -DNETDATA_VERIFY_LOCKS=1 -fstack-protector-all")
 
 set(NETDATA_FREEBSD_FILES
         src/plugin_freebsd.c
@@ -136,8 +136,6 @@ set(NETDATA_COMMON_FILES
         src/rrd.h
         src/rrd2json.c
         src/rrd2json.h
-        src/rrd2json_api_old.c
-        src/rrd2json_api_old.h
         src/rrdcalc.c
         src/rrdcalctemplate.c
         src/rrddim.c
@@ -167,8 +165,6 @@ set(NETDATA_COMMON_FILES
         src/unit_test.h
         src/url.c
         src/url.h
-        src/web_api_old.c
-        src/web_api_old.h
         src/web_api_v1.c
         src/web_api_v1.h
         src/web_buffer.c
@@ -188,6 +184,8 @@ set(APPS_PLUGIN_SOURCE_FILES
         src/apps_plugin.c
         src/avl.c
         src/avl.h
+        src/adaptive_resortable_list.c
+        src/adaptive_resortable_list.h
         src/common.c
         src/common.h
         src/clocks.c
@@ -199,6 +197,8 @@ set(APPS_PLUGIN_SOURCE_FILES
         src/log.h
         src/procfile.c
         src/procfile.h
+        src/threads.c
+        src/threads.h
         src/web_buffer.c
         src/web_buffer.h
         config.h
@@ -217,6 +217,8 @@ set(FREEIPMI_PLUGIN_SOURCE_FILES
         src/log.h
         src/procfile.c
         src/procfile.h
+        src/threads.c
+        src/threads.h
         config.h
         )
 
@@ -231,8 +233,16 @@ set(CGROUP_NETWORK_SOURCE_FILES
         src/locks.h
         src/log.c
         src/log.h
+        src/popen.c
+        src/popen.h
         src/procfile.c
         src/procfile.h
+        src/signals.c
+        src/signals.h
+        src/storage_number.c
+        src/storage_number.h
+        src/threads.c
+        src/threads.h
         src/web_buffer.c
         src/web_buffer.h
         config.h
@@ -252,10 +262,10 @@ add_executable(netdata_macos ${NETDATA_COMMON_FILES} ${NETDATA_MACOS_FILES})
 target_link_libraries (netdata_macos m z uuid ${CMAKE_THREAD_LIBS_INIT})
 
 add_executable(apps.plugin ${APPS_PLUGIN_SOURCE_FILES} src/inlined.h)
-target_link_libraries (apps.plugin m ${CMAKE_THREAD_LIBS_INIT})
+target_link_libraries (apps.plugin m cap ${CMAKE_THREAD_LIBS_INIT})
 
 add_executable(freeipmi.plugin ${FREEIPMI_PLUGIN_SOURCE_FILES})
-target_link_libraries (freeipmi.plugin ipmimonitoring)
+target_link_libraries (freeipmi.plugin ipmimonitoring ${CMAKE_THREAD_LIBS_INIT})
 
 add_executable(cgroup-network ${CGROUP_NETWORK_SOURCE_FILES})
 target_link_libraries (cgroup-network m ${CMAKE_THREAD_LIBS_INIT})

+ 0 - 4
src/Makefile.am

@@ -104,8 +104,6 @@ netdata_SOURCES = \
 	rrd.h \
 	rrd2json.c \
 	rrd2json.h \
-	rrd2json_api_old.c \
-	rrd2json_api_old.h \
 	rrdcalc.c \
 	rrdcalctemplate.c \
 	rrddim.c \
@@ -135,8 +133,6 @@ netdata_SOURCES = \
 	unit_test.h \
 	url.c \
 	url.h \
-	web_api_old.c \
-	web_api_old.h \
 	web_api_v1.c \
 	web_api_v1.h \
 	web_buffer.c \

+ 2 - 1
src/adaptive_resortable_list.c

@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-3.0+
-#include "adaptive_resortable_list.h"
+
+#include "common.h"
 
 // the default processor() of the ARL
 // can be overwritten at arl_create()

+ 2 - 3
src/adaptive_resortable_list.h

@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-3.0+
+
 #ifndef NETDATA_ADAPTIVE_RESORTABLE_LIST_H
-#define NETDATA_ADAPTIVE_RESORTABLE_LIST_H
+#define NETDATA_ADAPTIVE_RESORTABLE_LIST_H 1
 
 /*
  * ADAPTIVE RE-SORTABLE LIST
@@ -38,8 +39,6 @@
  * ONCE IN THE SOURCE DATA SET.
  */
 
-#include "common.h"
-
 #define ARL_ENTRY_FLAG_FOUND    0x01    // the entry has been found in the source data
 #define ARL_ENTRY_FLAG_EXPECTED 0x02    // the entry is expected by the program
 #define ARL_ENTRY_FLAG_DYNAMIC  0x04    // the entry was dynamically allocated, from source data

+ 1 - 0
src/appconfig.c

@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-3.0+
+
 #include "common.h"
 
 #define CONFIG_FILE_LINE_MAX ((CONFIG_MAX_NAME + CONFIG_MAX_VALUE + 1024) * 2)

+ 1 - 0
src/appconfig.h

@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-3.0+
+
 #ifndef NETDATA_CONFIG_H
 #define NETDATA_CONFIG_H 1
 

+ 31 - 30
src/avl.c

@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: LGPL-3.0+
+
 #include "common.h"
 
 /* ------------------------------------------------------------------------- */
@@ -44,7 +45,7 @@ avl *avl_insert(avl_tree *tree, avl *item) {
     avl *p, *q; /* Iterator, and parent. */
     avl *n;     /* Newly inserted node. */
     avl *w;     /* New root of rebalanced subtree. */
-    int dir;                /* Direction to descend. */
+    unsigned char dir; /* Direction to descend. */
 
     unsigned char da[AVL_MAX_HEIGHT]; /* Cached comparison results. */
     int k = 0;              /* Number of cached results. */
@@ -61,7 +62,7 @@ avl *avl_insert(avl_tree *tree, avl *item) {
 
         if (p->avl_balance != 0)
             z = q, y = p, k = 0;
-        da[k++] = dir = (cmp > 0);
+        da[k++] = dir = (unsigned char)(cmp > 0);
     }
 
     n = q->avl_link[dir] = item;
@@ -149,7 +150,7 @@ avl *avl_remove(avl_tree *tree, avl *item) {
     k = 0;
     p = (avl *) &tree->root;
     for(cmp = -1; cmp != 0; cmp = tree->compar(item, p)) {
-        int dir = (cmp > 0);
+        unsigned char dir = (unsigned char)(cmp > 0);
 
         pa[k] = p;
         da[k++] = dir;
@@ -283,7 +284,7 @@ avl *avl_remove(avl_tree *tree, avl *item) {
 // ---------------------------
 // traversing
 
-int avl_walker(avl *node, int (*callback)(void *entry, void *data), void *data) {
+int avl_walker(avl *node, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
     int total = 0, ret = 0;
 
     if(node->avl_link[0]) {
@@ -305,9 +306,9 @@ int avl_walker(avl *node, int (*callback)(void *entry, void *data), void *data)
     return total;
 }
 
-int avl_traverse(avl_tree *t, int (*callback)(void *entry, void *data), void *data) {
-    if(t->root)
-        return avl_walker(t->root, callback, data);
+int avl_traverse(avl_tree *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
+    if(tree->root)
+        return avl_walker(tree->root, callback, data);
     else
         return 0;
 }
@@ -348,16 +349,16 @@ void avl_unlock(avl_tree_lock *t) {
 // ---------------------------
 // operations with locking
 
-void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b)) {
-    avl_init(&t->avl_tree, compar);
+void avl_init_lock(avl_tree_lock *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
+    avl_init(&tree->avl_tree, compar);
 
 #ifndef AVL_WITHOUT_PTHREADS
     int lock;
 
 #ifdef AVL_LOCK_WITH_MUTEX
-    lock = netdata_mutex_init(&t->mutex, NULL);
+    lock = netdata_mutex_init(&tree->mutex, NULL);
 #else
-    lock = netdata_rwlock_init(&t->rwlock);
+    lock = netdata_rwlock_init(&tree->rwlock);
 #endif
 
     if(lock != 0)
@@ -366,38 +367,38 @@ void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b)) {
 #endif /* AVL_WITHOUT_PTHREADS */
 }
 
-avl *avl_search_lock(avl_tree_lock *t, avl *a) {
-    avl_read_lock(t);
-    avl *ret = avl_search(&t->avl_tree, a);
-    avl_unlock(t);
+avl *avl_search_lock(avl_tree_lock *tree, avl *item) {
+    avl_read_lock(tree);
+    avl *ret = avl_search(&tree->avl_tree, item);
+    avl_unlock(tree);
     return ret;
 }
 
-avl * avl_remove_lock(avl_tree_lock *t, avl *a) {
-    avl_write_lock(t);
-    avl *ret = avl_remove(&t->avl_tree, a);
-    avl_unlock(t);
+avl * avl_remove_lock(avl_tree_lock *tree, avl *item) {
+    avl_write_lock(tree);
+    avl *ret = avl_remove(&tree->avl_tree, item);
+    avl_unlock(tree);
     return ret;
 }
 
-avl *avl_insert_lock(avl_tree_lock *t, avl *a) {
-    avl_write_lock(t);
-    avl * ret = avl_insert(&t->avl_tree, a);
-    avl_unlock(t);
+avl *avl_insert_lock(avl_tree_lock *tree, avl *item) {
+    avl_write_lock(tree);
+    avl * ret = avl_insert(&tree->avl_tree, item);
+    avl_unlock(tree);
     return ret;
 }
 
-int avl_traverse_lock(avl_tree_lock *t, int (*callback)(void *entry, void *data), void *data) {
+int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void * /*entry*/, void * /*data*/), void *data) {
     int ret;
-    avl_read_lock(t);
-    ret = avl_traverse(&t->avl_tree, callback, data);
-    avl_unlock(t);
+    avl_read_lock(tree);
+    ret = avl_traverse(&tree->avl_tree, callback, data);
+    avl_unlock(tree);
     return ret;
 }
 
-void avl_init(avl_tree *t, int (*compar)(void *a, void *b)) {
-    t->root = NULL;
-    t->compar = compar;
+void avl_init(avl_tree *tree, int (*compar)(void * /*a*/, void * /*b*/)) {
+    tree->root = NULL;
+    tree->compar = compar;
 }
 
 // ------------------

+ 10 - 10
src/avl.h

@@ -57,31 +57,31 @@ typedef struct avl_tree_lock {
  * a is linked directly to the tree, so it has to
  * be properly allocated by the caller.
  */
-avl *avl_insert_lock(avl_tree_lock *t, avl *a) NEVERNULL WARNUNUSED;
-avl *avl_insert(avl_tree *t, avl *a) NEVERNULL WARNUNUSED;
+avl *avl_insert_lock(avl_tree_lock *tree, avl *item) NEVERNULL WARNUNUSED;
+avl *avl_insert(avl_tree *tree, avl *item) NEVERNULL WARNUNUSED;
 
 /* Remove an element a from the AVL tree t
  * returns a pointer to the removed element
  * or NULL if an element equal to a is not found
  * (equal as returned by t->compar())
  */
-avl *avl_remove_lock(avl_tree_lock *t, avl *a) WARNUNUSED;
-avl *avl_remove(avl_tree *t, avl *a) WARNUNUSED;
+avl *avl_remove_lock(avl_tree_lock *tree, avl *item) WARNUNUSED;
+avl *avl_remove(avl_tree *tree, avl *item) WARNUNUSED;
 
 /* Find the element into the tree that equal to a
  * (equal as returned by t->compar())
  * returns NULL is no element is equal to a
  */
-avl *avl_search_lock(avl_tree_lock *t, avl *a);
-avl *avl_search(avl_tree *t, avl *a);
+avl *avl_search_lock(avl_tree_lock *tree, avl *item);
+avl *avl_search(avl_tree *tree, avl *item);
 
 /* Initialize the avl_tree_lock
  */
-void avl_init_lock(avl_tree_lock *t, int (*compar)(void *a, void *b));
-void avl_init(avl_tree *t, int (*compar)(void *a, void *b));
+void avl_init_lock(avl_tree_lock *tree, int (*compar)(void *a, void *b));
+void avl_init(avl_tree *tree, int (*compar)(void *a, void *b));
 
 
-int avl_traverse_lock(avl_tree_lock *t, int (*callback)(void *entry, void *data), void *data);
-int avl_traverse(avl_tree *t, int (*callback)(void *entry, void *data), void *data);
+int avl_traverse_lock(avl_tree_lock *tree, int (*callback)(void *entry, void *data), void *data);
+int avl_traverse(avl_tree *tree, int (*callback)(void *entry, void *data), void *data);
 
 #endif /* avl.h */

+ 1 - 0
src/backend_prometheus.c

@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-3.0+
+
 #include "common.h"
 
 // ----------------------------------------------------------------------------

+ 1 - 1
src/backend_prometheus.h

@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-3.0+
 
 #ifndef NETDATA_BACKEND_PROMETHEUS_H
-#define NETDATA_BACKEND_PROMETHEUS_H
+#define NETDATA_BACKEND_PROMETHEUS_H 1
 
 typedef enum prometheus_output_flags {
     PROMETHEUS_OUTPUT_NONE       = 0,

Некоторые файлы не были показаны из-за большого количества измененных файлов