Browse Source

cmake missing defines (#16680)

* added HAVE_ACCEPT4

* added HAVE_FINITE, HAVE_ISFINITE

* added SIZEOF_VOID_P

* added HAVE_NICE, HAVE_RECVMMSG, HAVE_GETPRIORITY

* added HAVE_C__GENERIC

* added HAVE_C_MALLOPT

* added HAVE_BACKTRACE, HAVE_CLOSE_RANGE, HAVE_SCHED_GETSCHEDULER, HAVE_SCHED_SETSCHEDULER, HAVE_SCHED_GET_PRIORITY_MIN, HAVE_SCHED_GET_PRIORITY_MAX

* added HAVE_DLSYM

* added function attributes checks

* fix SIZEOF_VOID_P

* added HAVE_PTHREAD_GETNAME_NP

* fixed compiler warnings
Costa Tsaousis 1 year ago
parent
commit
40c6c14dab

+ 126 - 6
CMakeLists.txt

@@ -65,6 +65,8 @@ set(CMAKE_CXX_STANDARD 11)
 set(CMAKE_C_STANDARD_REQUIRED On)
 set(CMAKE_CXX_STANDARD_REQUIRED On)
 
+set(SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
+
 if(NOT CMAKE_BUILD_TYPE)
         set(CMAKE_BUILD_TYPE "Release")
 endif()
@@ -184,11 +186,25 @@ check_library_exists(snappy snappy_compress "" HAVE_SNAPPY_LIB)
 #
 
 include(CheckSymbolExists)
-check_symbol_exists(major sys/sysmacros.h MAJOR_IN_SYSMACROS)
-check_symbol_exists(major sys/mkdev.h MAJOR_IN_MKDEV)
-check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
-check_symbol_exists(clock_gettime time.h HAVE_CLOCK_GETTIME)
-check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
+check_symbol_exists(major "sys/sysmacros.h" MAJOR_IN_SYSMACROS)
+check_symbol_exists(major "sys/mkdev.h" MAJOR_IN_MKDEV)
+check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME)
+check_symbol_exists(strerror_r "string.h" HAVE_STRERROR_R)
+check_symbol_exists(finite "math.h" HAVE_FINITE)
+check_symbol_exists(isfinite "math.h" HAVE_ISFINITE)
+check_symbol_exists(dlsym "dlfcn.h" HAVE_DLSYM)
+
+check_function_exists(nice HAVE_NICE)
+check_function_exists(recvmmsg HAVE_RECVMMSG)
+check_function_exists(getpriority HAVE_GETPRIORITY)
+
+check_function_exists(sched_getscheduler HAVE_SCHED_GETSCHEDULER)
+check_function_exists(sched_setscheduler HAVE_SCHED_SETSCHEDULER)
+check_function_exists(sched_get_priority_min HAVE_SCHED_GET_PRIORITY_MIN)
+check_function_exists(sched_get_priority_max HAVE_SCHED_GET_PRIORITY_MAX)
+
+check_function_exists(close_range HAVE_CLOSE_RANGE)
+check_function_exists(backtrace HAVE_BACKTRACE)
 
 #
 # check source compilation
@@ -197,6 +213,45 @@ check_symbol_exists(strerror_r string.h HAVE_STRERROR_R)
 include(CheckCSourceCompiles)
 include(CheckCXXSourceCompiles)
 
+set(CMAKE_REQUIRED_LIBRARIES pthread)
+check_c_source_compiles("
+#define _GNU_SOURCE
+#include <pthread.h>
+int main() {
+        char name[16];
+        pthread_t thread = pthread_self();
+        return pthread_getname_np(thread, name, sizeof(name));
+}
+" HAVE_PTHREAD_GETNAME_NP)
+
+check_c_source_compiles("
+#include <stdio.h>
+#define mytype(X) _Generic((X), int: 'i', float: 'f', default: 'u')
+int main() {
+        char type = mytype(0);
+        return 0;
+}
+" HAVE_C__GENERIC)
+
+check_c_source_compiles("
+#include <malloc.h>
+int main() {
+        mallopt(M_ARENA_MAX, 1);
+        mallopt(M_PERTURB, 0x5A);
+        return 0;
+}
+" HAVE_C_MALLOPT)
+
+check_c_source_compiles("
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/socket.h>
+int main() {
+        accept4(0, NULL, NULL, 0);
+        return 0;
+}
+" HAVE_ACCEPT4)
+
 check_c_source_compiles("
 #define _GNU_SOURCE
 #include <string.h>
@@ -222,11 +277,76 @@ int main() {
 }
 " HAVE_BUILTIN_ATOMICS)
 
+check_c_source_compiles("
+void my_printf(char const *s, ...) __attribute__((format(printf, 1, 2)));
+int main() { return 0; }
+" HAVE_FUNC_ATTRIBUTE_FORMAT)
+
+check_c_source_compiles("
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+void* my_alloc(size_t size) __attribute__((malloc));
+int main() {
+    void *x = my_alloc(1);
+    free(x);
+    return 0;
+}
+void* my_alloc(size_t size) {
+    void *ret = malloc(size);
+    if(!ret) exit(1);
+    return ret;
+}
+" HAVE_FUNC_ATTRIBUTE_MALLOC)
+
+check_c_source_compiles("
+void my_function() __attribute__((noinline));
+int main() { my_function(); return 0; }
+void my_function() { ; }
+" HAVE_FUNC_ATTRIBUTE_NOINLINE)
+
+check_c_source_compiles("
+void my_exit_function() __attribute__((noreturn));
+int main() {
+        my_exit_function(); // Call the noreturn function
+        return 0;
+}
+void my_exit_function() {
+        exit(1);
+}
+" HAVE_FUNC_ATTRIBUTE_NORETURN)
+
+check_c_source_compiles("
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+void* my_alloc(size_t size) __attribute__((returns_nonnull));
+int main() {
+        void* ptr = my_alloc(10);
+        free(ptr);
+        return 0;
+}
+void* my_alloc(size_t size) {
+        void *ret = malloc(size);
+        if(!ret) exit(1);
+        return ret;
+}
+" HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL)
+
+check_c_source_compiles("
+int my_function() __attribute__((warn_unused_result));
+int main() {
+        return my_function();
+}
+int my_function() {
+        return 1;
+}
+" HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT)
+
 if(FREEBSD OR MACOS)
         set(HAVE_BUILTIN_ATOMICS True)
 endif()
 
-
 # openssl/crypto
 set(ENABLE_OPENSSL True)
 if(NOT MACOS)

+ 2 - 0
aclk/aclk_stats.c

@@ -1,6 +1,8 @@
 // SPDX-License-Identifier: GPL-3.0-or-later
 
+#ifndef MQTT_WSS_CPUSTATS
 #define MQTT_WSS_CPUSTATS
+#endif
 
 #include "aclk_stats.h"
 

+ 1 - 1
collectors/cgroups.plugin/cgroup-top.c

@@ -101,7 +101,7 @@ int cgroup_function_cgroup_top(uuid_t *transaction __maybe_unused, BUFFER *wb,
                                usec_t *stop_monotonic_ut __maybe_unused, const char *function __maybe_unused,
                                void *collector_data __maybe_unused,
                                rrd_function_result_callback_t result_cb, void *result_cb_data,
-                               rrd_function_progress_cb_t progress_cb, void *progress_cb_data,
+                               rrd_function_progress_cb_t progress_cb __maybe_unused, void *progress_cb_data __maybe_unused,
                                rrd_function_is_cancelled_cb_t is_cancelled_cb, void *is_cancelled_cb_data,
                                rrd_function_register_canceller_cb_t register_canceller_cb __maybe_unused,
                                void *register_canceller_cb_data __maybe_unused,

+ 1 - 1
collectors/proc.plugin/proc_spl_kstat_zfs.c

@@ -6,7 +6,7 @@
 #define ZFS_PROC_ARCSTATS "/proc/spl/kstat/zfs/arcstats"
 #define ZFS_PROC_POOLS "/proc/spl/kstat/zfs"
 
-#define STATE_SIZE 9
+#define STATE_SIZE 20
 #define MAX_CHART_ID 256
 
 extern struct arcstats arcstats;

+ 5 - 5
collectors/systemd-journal.plugin/systemd-journal-annotations.c

@@ -712,8 +712,8 @@ void netdata_systemd_journal_transform_message_id(FACETS *facets __maybe_unused,
 
 // ----------------------------------------------------------------------------
 
-static void netdata_systemd_journal_rich_message(FACETS *facets __maybe_unused, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row __maybe_unused, void *data __maybe_unused) {
-    buffer_json_add_array_item_object(json_array);
-    buffer_json_member_add_string(json_array, "value", buffer_tostring(rkv->wb));
-    buffer_json_object_close(json_array);
-}
+//static void netdata_systemd_journal_rich_message(FACETS *facets __maybe_unused, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row __maybe_unused, void *data __maybe_unused) {
+//    buffer_json_add_array_item_object(json_array);
+//    buffer_json_member_add_string(json_array, "value", buffer_tostring(rkv->wb));
+//    buffer_json_object_close(json_array);
+//}

+ 70 - 70
collectors/systemd-journal.plugin/systemd-journal-files.c

@@ -39,74 +39,74 @@ static bool journal_sd_id128_parse(const char *in, sd_id128_t *ret) {
     return false;
 }
 
-static void journal_file_get_header_from_journalctl(const char *filename, struct journal_file *jf) {
-    // unfortunately, our capabilities are not inheritted by journalctl
-    // so, it fails to give us the information we need.
-
-    bool read_writer = false, read_head = false, read_tail = false;
-
-    char cmd[FILENAME_MAX * 2];
-    snprintfz(cmd, sizeof(cmd), "journalctl --header --file '%s'", filename);
-    CLEAN_BUFFER *wb = run_command_and_get_output_to_buffer(cmd, 1024);
-    if(wb) {
-        const char *s = buffer_tostring(wb);
-
-        const char *sequential_id_header = "Sequential Number ID:";
-        const char *sequential_id_data = strcasestr(s, sequential_id_header);
-        if(sequential_id_data) {
-            sequential_id_data += strlen(sequential_id_header);
-            if(journal_sd_id128_parse(sequential_id_data, &jf->first_writer_id))
-                read_writer = true;
-        }
-
-        const char *head_sequential_number_header = "Head sequential number:";
-        const char *head_sequential_number_data = strcasestr(s, head_sequential_number_header);
-        if(head_sequential_number_data) {
-            head_sequential_number_data += strlen(head_sequential_number_header);
-
-            while(isspace(*head_sequential_number_data))
-                head_sequential_number_data++;
-
-            if(isdigit(*head_sequential_number_data)) {
-                jf->first_seqnum = strtoul(head_sequential_number_data, NULL, 10);
-                if(jf->first_seqnum)
-                    read_head = true;
-            }
-        }
-
-        const char *tail_sequential_number_header = "Tail sequential number:";
-        const char *tail_sequential_number_data = strcasestr(s, tail_sequential_number_header);
-        if(tail_sequential_number_data) {
-            tail_sequential_number_data += strlen(tail_sequential_number_header);
-
-            while(isspace(*tail_sequential_number_data))
-                tail_sequential_number_data++;
-
-            if(isdigit(*tail_sequential_number_data)) {
-                jf->last_seqnum = strtoul(tail_sequential_number_data, NULL, 10);
-                if(jf->last_seqnum)
-                    read_tail = true;
-            }
-        }
-
-        if(read_head && read_tail && jf->last_seqnum > jf->first_seqnum)
-            jf->messages_in_file = jf->last_seqnum - jf->first_seqnum;
-    }
-
-    if(!jf->logged_journalctl_failure && (!read_head || !read_tail)) {
-
-        nd_log(NDLS_COLLECTORS, NDLP_NOTICE,
-               "Failed to read %s%s%s from journalctl's output on filename '%s', using the command: %s",
-               read_writer?"":"writer id,",
-               read_head?"":"head id,",
-               read_tail?"":"tail id,",
-               filename, cmd);
-
-        jf->logged_journalctl_failure = true;
-    }
-}
-
-usec_t journal_file_update_annotation_boot_id(sd_journal *j, struct journal_file *jf, const char *boot_id) {
+//static void journal_file_get_header_from_journalctl(const char *filename, struct journal_file *jf) {
+//    // unfortunately, our capabilities are not inheritted by journalctl
+//    // so, it fails to give us the information we need.
+//
+//    bool read_writer = false, read_head = false, read_tail = false;
+//
+//    char cmd[FILENAME_MAX * 2];
+//    snprintfz(cmd, sizeof(cmd), "journalctl --header --file '%s'", filename);
+//    CLEAN_BUFFER *wb = run_command_and_get_output_to_buffer(cmd, 1024);
+//    if(wb) {
+//        const char *s = buffer_tostring(wb);
+//
+//        const char *sequential_id_header = "Sequential Number ID:";
+//        const char *sequential_id_data = strcasestr(s, sequential_id_header);
+//        if(sequential_id_data) {
+//            sequential_id_data += strlen(sequential_id_header);
+//            if(journal_sd_id128_parse(sequential_id_data, &jf->first_writer_id))
+//                read_writer = true;
+//        }
+//
+//        const char *head_sequential_number_header = "Head sequential number:";
+//        const char *head_sequential_number_data = strcasestr(s, head_sequential_number_header);
+//        if(head_sequential_number_data) {
+//            head_sequential_number_data += strlen(head_sequential_number_header);
+//
+//            while(isspace(*head_sequential_number_data))
+//                head_sequential_number_data++;
+//
+//            if(isdigit(*head_sequential_number_data)) {
+//                jf->first_seqnum = strtoul(head_sequential_number_data, NULL, 10);
+//                if(jf->first_seqnum)
+//                    read_head = true;
+//            }
+//        }
+//
+//        const char *tail_sequential_number_header = "Tail sequential number:";
+//        const char *tail_sequential_number_data = strcasestr(s, tail_sequential_number_header);
+//        if(tail_sequential_number_data) {
+//            tail_sequential_number_data += strlen(tail_sequential_number_header);
+//
+//            while(isspace(*tail_sequential_number_data))
+//                tail_sequential_number_data++;
+//
+//            if(isdigit(*tail_sequential_number_data)) {
+//                jf->last_seqnum = strtoul(tail_sequential_number_data, NULL, 10);
+//                if(jf->last_seqnum)
+//                    read_tail = true;
+//            }
+//        }
+//
+//        if(read_head && read_tail && jf->last_seqnum > jf->first_seqnum)
+//            jf->messages_in_file = jf->last_seqnum - jf->first_seqnum;
+//    }
+//
+//    if(!jf->logged_journalctl_failure && (!read_head || !read_tail)) {
+//
+//        nd_log(NDLS_COLLECTORS, NDLP_NOTICE,
+//               "Failed to read %s%s%s from journalctl's output on filename '%s', using the command: %s",
+//               read_writer?"":"writer id,",
+//               read_head?"":"head id,",
+//               read_tail?"":"tail id,",
+//               filename, cmd);
+//
+//        jf->logged_journalctl_failure = true;
+//    }
+//}
+
+usec_t journal_file_update_annotation_boot_id(sd_journal *j, struct journal_file *jf __maybe_unused, const char *boot_id) {
     usec_t ut = UINT64_MAX;
     int r;
 
@@ -447,7 +447,7 @@ static void files_registry_insert_cb(const DICTIONARY_ITEM *item, void *value, v
            jf->filename);
 }
 
-static bool files_registry_conflict_cb(const DICTIONARY_ITEM *item, void *old_value, void *new_value, void *data __maybe_unused) {
+static bool files_registry_conflict_cb(const DICTIONARY_ITEM *item __maybe_unused, void *old_value, void *new_value, void *data __maybe_unused) {
     struct journal_file *jf = old_value;
     struct journal_file *njf = new_value;
 
@@ -801,7 +801,7 @@ int journal_file_dict_items_forward_compar(const void *a, const void *b) {
     return -journal_file_dict_items_backward_compar(a, b);
 }
 
-static bool boot_id_conflict_cb(const DICTIONARY_ITEM *item, void *old_value, void *new_value, void *data __maybe_unused) {
+static bool boot_id_conflict_cb(const DICTIONARY_ITEM *item __maybe_unused, void *old_value, void *new_value, void *data __maybe_unused) {
     usec_t *old_usec = old_value;
     usec_t *new_usec = new_value;
 

+ 3 - 5
collectors/systemd-journal.plugin/systemd-journal.c

@@ -518,12 +518,12 @@ static size_t sampling_running_file_query_estimate_remaining_lines_by_time(FUNCT
     return remaining_logs_by_time;
 }
 
-static size_t sampling_running_file_query_estimate_remaining_lines(sd_journal *j, FUNCTION_QUERY_STATUS *fqs, struct journal_file *jf, FACETS_ANCHOR_DIRECTION direction, usec_t msg_ut) {
-    size_t expected_matching_logs_by_seqnum = 0;
-    double proportion_by_seqnum = 0.0;
+static size_t sampling_running_file_query_estimate_remaining_lines(sd_journal *j __maybe_unused, FUNCTION_QUERY_STATUS *fqs, struct journal_file *jf, FACETS_ANCHOR_DIRECTION direction, usec_t msg_ut) {
     size_t remaining_logs_by_seqnum = 0;
 
 #ifdef HAVE_SD_JOURNAL_GET_SEQNUM
+    size_t expected_matching_logs_by_seqnum = 0;
+    double proportion_by_seqnum = 0.0;
     uint64_t current_msg_seqnum;
     sd_id128_t current_msg_writer;
     if(!fqs->query_file.first_msg_seqnum || sd_journal_get_seqnum(j, &current_msg_seqnum, &current_msg_writer) < 0) {
@@ -1533,7 +1533,6 @@ void function_systemd_journal(const char *transaction, char *function, usec_t *s
             .stop_monotonic_ut = stop_monotonic_ut,
     };
     FUNCTION_QUERY_STATUS *fqs = NULL;
-    const DICTIONARY_ITEM *fqs_item = NULL;
 
     FACETS *facets = facets_create(50, FACETS_OPTION_ALL_KEYS_FTS,
                                    SYSTEMD_ALWAYS_VISIBLE_KEYS,
@@ -1855,7 +1854,6 @@ void function_systemd_journal(const char *transaction, char *function, usec_t *s
     // put this request into the progress db
 
     fqs = &tmp_fqs;
-    fqs_item = NULL;
 
     // ------------------------------------------------------------------------
     // validate parameters

+ 28 - 1
config.cmake.h.in

@@ -6,6 +6,8 @@
 #define __always_unused __attribute__((unused))
 #define __maybe_unused __attribute__((unused))
 
+#cmakedefine SIZEOF_VOID_P ${SIZEOF_VOID_P}
+
 // platform
 #cmakedefine COMPILED_FOR_FREEBSD
 #cmakedefine COMPILED_FOR_LINUX
@@ -38,7 +40,19 @@
 #cmakedefine MAJOR_IN_MKDEV
 #cmakedefine HAVE_CLOCK_GETTIME
 #cmakedefine HAVE_STRERROR_R
-#cmakedefine HAVE_SETNS
+#cmakedefine HAVE_FINITE
+#cmakedefine HAVE_ISFINITE
+#cmakedefine HAVE_RECVMMSG
+#cmakedefine HAVE_NICE
+#cmakedefine HAVE_GETPRIORITY
+#cmakedefine HAVE_DLSYM
+
+#cmakedefine HAVE_BACKTRACE
+#cmakedefine HAVE_CLOSE_RANGE
+#cmakedefine HAVE_SCHED_GETSCHEDULER
+#cmakedefine HAVE_SCHED_SETSCHEDULER
+#cmakedefine HAVE_SCHED_GET_PRIORITY_MIN
+#cmakedefine HAVE_SCHED_GET_PRIORITY_MAX
 
 #cmakedefine HAVE_SYSTEMD
 #cmakedefine HAVE_SD_JOURNAL_OS_ROOT
@@ -48,7 +62,20 @@
 #cmakedefine ENABLE_SYSTEMD_DBUS
 
 // checked source compilation
+
+#cmakedefine HAVE_PTHREAD_GETNAME_NP
+#cmakedefine HAVE_ACCEPT4
 #cmakedefine STRERROR_R_CHAR_P
+#cmakedefine HAVE_C__GENERIC
+#cmakedefine HAVE_C_MALLOPT
+#cmakedefine HAVE_SETNS
+
+#cmakedefine HAVE_FUNC_ATTRIBUTE_FORMAT
+#cmakedefine HAVE_FUNC_ATTRIBUTE_MALLOC
+#cmakedefine HAVE_FUNC_ATTRIBUTE_NOINLINE
+#cmakedefine HAVE_FUNC_ATTRIBUTE_NORETURN
+#cmakedefine HAVE_FUNC_ATTRIBUTE_RETURNS_NONNULL
+#cmakedefine HAVE_FUNC_ATTRIBUTE_WARN_UNUSED_RESULT
 
 // enabled features
 

+ 3 - 2
database/engine/page.c

@@ -612,7 +612,7 @@ void pgdc_reset(PGDC *pgdc, PGD *pgd, uint32_t position)
     pgdc_seek(pgdc, position);
 }
 
-bool pgdc_get_next_point(PGDC *pgdc, uint32_t expected_position, STORAGE_POINT *sp)
+bool pgdc_get_next_point(PGDC *pgdc, uint32_t expected_position __maybe_unused, STORAGE_POINT *sp)
 {
     if (!pgdc->pgd || pgdc->pgd == PGD_EMPTY || pgdc->position >= pgdc->slots)
     {
@@ -668,7 +668,8 @@ bool pgdc_get_next_point(PGDC *pgdc, uint32_t expected_position, STORAGE_POINT *
             static bool logged = false;
             if (!logged)
             {
-                netdata_log_error("DBENGINE: unknown page type %d found. Cannot decode it. Ignoring its metrics.", pgd_type(pgdc->pgd));
+                netdata_log_error("DBENGINE: unknown page type %"PRIu32" found. Cannot decode it. Ignoring its metrics.",
+                                  pgd_type(pgdc->pgd));
                 logged = true;
             }
 

+ 1 - 1
database/rrddim.c

@@ -362,7 +362,7 @@ RRDDIM *rrddim_find_active(RRDSET *st, const char *id) {
 // ----------------------------------------------------------------------------
 // RRDDIM rename a dimension
 
-inline int rrddim_reset_name(RRDSET *st, RRDDIM *rd, const char *name) {
+inline int rrddim_reset_name(RRDSET *st __maybe_unused, RRDDIM *rd, const char *name) {
     if(unlikely(!name || !*name || !strcmp(rrddim_name(rd), name)))
         return 0;
 

Some files were not shown because too many files changed in this diff