@cryptotaxi247 / netdata-1 / commits / f51e5ecef

fix compiler warnings (#19221)

* fix compiler warnings * allow hashtable values to be non-pointers; make hashtable use 64bit values even on 32bit machines * make sure hashtable always returns the right type of value * simple_hashtable_set_slot_named() fixes * fix warning in simple hashtable * more fixes * have a custom preprocessor directive for non-pointers seems the only viable solution * uint64_t is %llX on 32bit * uint64_t is %llX on 32bit and it needs casting on 64bit * always print 16 digits * fix windows hashtable * fix more warnings * another * fixed warnings on windows * do not show pulse dbengine charts if extended mode is not enabled * fix more warnings again

Costa Tsaousis committed Dec 16, 2024 at 15:48 UTC f51e5ecefd848574519455446cfae33e9848a9d4
35 files changed +462 -429
src/aclk/mqtt_websockets/mqtt_wss_client.c
+8 -5
@@ -351,7 +351,8 @@ static int http_proxy_connect(mqtt_wss_client client)
351 char *r_buf_ptr = rbuf_get_linear_insert_range(r_buf, &r_buf_linear_insert_capacity);
352 snprintf(r_buf_ptr, r_buf_linear_insert_capacity,"%s %s:%d %s" HTTP_ENDLINE "Host: %s" HTTP_ENDLINE, PROXY_CONNECT,
353 client->target_host, client->target_port, PROXY_HTTP, client->target_host);
354 - write(client->sockfd, r_buf_ptr, strlen(r_buf_ptr));
354 +
355 + if(write(client->sockfd, r_buf_ptr, strlen(r_buf_ptr)) <= 0) { ; }
356
357 if (client->proxy_uname) {
358 size_t creds_plain_len = strlen(client->proxy_uname) + strlen(client->proxy_passwd) + 2;
@@ -383,10 +384,12 @@ static int http_proxy_connect(mqtt_wss_client client)
384
385 r_buf_ptr = rbuf_get_linear_insert_range(r_buf, &r_buf_linear_insert_capacity);
386 snprintf(r_buf_ptr, r_buf_linear_insert_capacity,"Proxy-Authorization: Basic %s" HTTP_ENDLINE, creds_base64);
386 - write(client->sockfd, r_buf_ptr, strlen(r_buf_ptr));
387 +
388 + if(write(client->sockfd, r_buf_ptr, strlen(r_buf_ptr)) <= 0) { ; }
389 +
390 freez(creds_base64);
391 }
389 - write(client->sockfd, HTTP_ENDLINE, strlen(HTTP_ENDLINE));
392 + if(write(client->sockfd, HTTP_ENDLINE, strlen(HTTP_ENDLINE)) <= 0) { ; }
393
394 // read until you find CRLF, CRLF (HTTP HDR end)
395 // or ring buffer is full
@@ -720,14 +723,14 @@ void mqtt_wss_disconnect(mqtt_wss_client client, int timeout_ms)
723
724 static void mqtt_wss_wakeup(mqtt_wss_client client)
725 {
723 - write(client->write_notif_pipe[PIPE_WRITE_END], " ", 1);
726 + if(write(client->write_notif_pipe[PIPE_WRITE_END], " ", 1) <= 0) { ; }
727 }
728
729 #define THROWAWAY_BUF_SIZE 32
730 char throwaway[THROWAWAY_BUF_SIZE];
731 static void util_clear_pipe(int fd)
732 {
730 - (void)read(fd, throwaway, THROWAWAY_BUF_SIZE);
733 + if(read(fd, throwaway, THROWAWAY_BUF_SIZE) <= 0) { ; }
734 }
735
736 static void set_socket_pollfds(mqtt_wss_client client, int ssl_ret) {
src/collectors/apps.plugin/apps_pid.c
+1 -1
@@ -8,7 +8,7 @@ static inline void link_pid_to_its_parent(struct pid_stat *p);
8 // The index of all pids
9
10 #define SIMPLE_HASHTABLE_NAME _PID
11 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct pid_stat
11 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct pid_stat *
12 #define SIMPLE_HASHTABLE_KEY_TYPE int32_t
13 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION pid_stat_to_pid_ptr
14 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION pid_ptr_eq
src/collectors/log2journal/log2journal.h
+1 -1
@@ -35,7 +35,7 @@ static inline void l2j_log(const char *format, ...) {
35 struct hashed_key;
36 static inline int compare_keys(struct hashed_key *k1, struct hashed_key *k2);
37 #define SIMPLE_HASHTABLE_SORT_FUNCTION compare_keys
38 -#define SIMPLE_HASHTABLE_VALUE_TYPE HASHED_KEY
38 +#define SIMPLE_HASHTABLE_VALUE_TYPE HASHED_KEY *
39 #define SIMPLE_HASHTABLE_NAME _KEY
40 #include "libnetdata/simple_hashtable/simple_hashtable.h"
41
src/collectors/network-viewer.plugin/network-viewer.c
+2 -1
@@ -29,7 +29,7 @@ static SPAWN_SERVER *spawn_srv = NULL;
29 #define NETWORK_CONNECTIONS_VIEWER_FUNCTION "network-connections"
30 #define NETWORK_CONNECTIONS_VIEWER_HELP "Network connections explorer"
31
32 -#define SIMPLE_HASHTABLE_VALUE_TYPE LOCAL_SOCKET
32 +#define SIMPLE_HASHTABLE_VALUE_TYPE LOCAL_SOCKET *
33 #define SIMPLE_HASHTABLE_NAME _AGGREGATED_SOCKETS
34 #include "libnetdata/simple_hashtable/simple_hashtable.h"
35
@@ -176,6 +176,7 @@ static void local_socket_to_json_array(struct sockets_stats *st, const LOCAL_SOC
176 server_endpoint = &n->remote;
177 break;
178
179 + default:
180 case SOCKET_DIRECTION_NONE:
181 server_address = NULL;
182 client_address_space = NULL;
src/collectors/proc.plugin/proc_stat.c
+1 -1
@@ -729,7 +729,7 @@ int do_proc_stat(int update_every, usec_t dt) {
729
730 if (core > 0) {
731 char cpu_core[50 + 1];
732 - snprintfz(cpu_core, 50, "cpu%lu", core - 1);
732 + snprintfz(cpu_core, 50, "cpu%zu", core - 1);
733 rrdlabels_add(cpu_chart->st->rrdlabels, "cpu", cpu_core, RRDLABEL_SRC_AUTO);
734 }
735
src/collectors/profile.plugin/plugin_profile.cc
+6 -6
@@ -39,12 +39,12 @@ private:
39
40 class Profiler {
41 public:
42 - Profiler(size_t ID, size_t NumCharts, size_t NumDimsPerChart, time_t SecondsToBackfill, int UpdateEvery) :
43 - ID(ID),
44 - NumCharts(NumCharts),
45 - NumDimsPerChart(NumDimsPerChart),
46 - SecondsToBackfill(SecondsToBackfill),
47 - UpdateEvery(UpdateEvery),
42 + Profiler(size_t ID_arg, size_t NumCharts_arg, size_t NumDimsPerChart_arg, time_t SecondsToBackfill_arg, int UpdateEvery_arg) :
43 + ID(ID_arg),
44 + NumCharts(NumCharts_arg),
45 + NumDimsPerChart(NumDimsPerChart_arg),
46 + SecondsToBackfill(SecondsToBackfill_arg),
47 + UpdateEvery(UpdateEvery_arg),
48 Gen(1024 * 1024)
49 {}
50
src/collectors/statsd.plugin/statsd.c
+1 -1
@@ -1867,7 +1867,7 @@ static inline void metric_check_obsoletion(STATSD_METRIC *m) {
1867 if(statsd.set_obsolete_after &&
1868 !rrdset_flag_check(m->st, RRDSET_FLAG_OBSOLETE) &&
1869 m->options & STATSD_METRIC_OPTION_PRIVATE_CHART_ENABLED &&
1870 - m->last_collected + statsd.set_obsolete_after < now_realtime_sec()) {
1870 + m->last_collected + (time_t)statsd.set_obsolete_after < now_realtime_sec()) {
1871 rrdset_is_obsolete___safe_from_collector_thread(m->st);
1872 m->options |= STATSD_METRIC_OPTION_OBSOLETE;
1873 }
src/collectors/windows-events.plugin/windows-events-fields-cache.c
+1 -1
@@ -14,7 +14,7 @@ typedef struct field_value {
14 } WEVT_FIELD_VALUE;
15
16 #define SIMPLE_HASHTABLE_NAME _FIELDS_CACHE
17 -#define SIMPLE_HASHTABLE_VALUE_TYPE WEVT_FIELD_VALUE
17 +#define SIMPLE_HASHTABLE_VALUE_TYPE WEVT_FIELD_VALUE *
18 #define SIMPLE_HASHTABLE_KEY_TYPE WEVT_FIELD_KEY
19 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION field_cache_value_to_key
20 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION field_cache_cache_compar
src/collectors/windows-events.plugin/windows-events-providers.c
+1 -1
@@ -59,7 +59,7 @@ typedef struct provider {
59 // A hashtable implementation for Providers
60 // using the Provider GUID as key and PROVIDER as value
61 #define SIMPLE_HASHTABLE_NAME _PROVIDER
62 -#define SIMPLE_HASHTABLE_VALUE_TYPE PROVIDER
62 +#define SIMPLE_HASHTABLE_VALUE_TYPE PROVIDER *
63 #define SIMPLE_HASHTABLE_KEY_TYPE PROVIDER_KEY
64 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION provider_value_to_key
65 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION provider_cache_compar
src/collectors/windows.plugin/perflib-hyperv.c
-1
@@ -985,7 +985,6 @@ static bool do_hyperv_switch(PERF_DATA_BLOCK *pDataBlock, int update_every, void
985
986 PERF_INSTANCE_DEFINITION *pi = NULL;
987 for (LONG i = 0; i < pObjectType->NumInstances; i++) {
988 - static bool charts_created = false;
988 pi = perflibForEachInstance(pDataBlock, pObjectType, pi);
989 if (!pi)
990 break;
src/collectors/windows.plugin/perflib-mssql.c
+1 -1
@@ -1117,7 +1117,7 @@ static void mssql_active_transactions_chart(struct mssql_db_instance *mli, const
1117 rrdset_done(mli->st_db_active_transactions);
1118 }
1119
1120 -static void mssql_data_file_size_chart(struct mssql_db_instance *mli, const char *db, int update_every) {
1120 +static inline void mssql_data_file_size_chart(struct mssql_db_instance *mli, const char *db, int update_every) {
1121 char id[RRD_ID_LENGTH_MAX + 1];
1122
1123 if (!mli->st_db_data_file_size) {
src/daemon/pulse/pulse-db-dbengine.c
+5 -4
@@ -648,21 +648,17 @@ void pulse_dbengine_do(bool extended) {
648
649 pgc_main_stats_old = pgc_main_stats;
650 pgc_main_stats = pgc_get_statistics(main_cache);
651 - dbengine2_cache_statistics_charts(&main_cache_ptrs, &pgc_main_stats, &pgc_main_stats_old, "main", 135100);
651
652 pgc_open_stats_old = pgc_open_stats;
653 pgc_open_stats = pgc_get_statistics(open_cache);
655 - dbengine2_cache_statistics_charts(&open_cache_ptrs, &pgc_open_stats, &pgc_open_stats_old, "open", 135200);
654
655 pgc_extent_stats_old = pgc_extent_stats;
656 pgc_extent_stats = pgc_get_statistics(extent_cache);
659 - dbengine2_cache_statistics_charts(&extent_cache_ptrs, &pgc_extent_stats, &pgc_extent_stats_old, "extent", 135300);
657
658 cache_efficiency_stats_old = cache_efficiency_stats;
659 cache_efficiency_stats = rrdeng_get_cache_efficiency_stats();
660
661 mrg_stats_old = mrg_stats;
665 - mrg_get_statistics(main_mrg, &mrg_stats);
662
663 struct rrdeng_buffer_sizes dbmem = rrdeng_pulse_memory_sizes();
664
@@ -686,6 +682,11 @@ void pulse_dbengine_do(bool extended) {
682 if(!main_cache || !main_mrg || !extended)
683 return;
684
685 + dbengine2_cache_statistics_charts(&main_cache_ptrs, &pgc_main_stats, &pgc_main_stats_old, "main", 135100);
686 + dbengine2_cache_statistics_charts(&open_cache_ptrs, &pgc_open_stats, &pgc_open_stats_old, "open", 135200);
687 + dbengine2_cache_statistics_charts(&extent_cache_ptrs, &pgc_extent_stats, &pgc_extent_stats_old, "extent", 135300);
688 + mrg_get_statistics(main_mrg, &mrg_stats);
689 +
690 size_t priority = 135000;
691
692 {
src/database/contexts/api_v2_contexts_alerts.c
+1 -1
@@ -52,7 +52,7 @@ bool rrdcontext_matches_alert(struct rrdcontext_to_json_v2_data *ctl, RRDCONTEXT
52 if(ctl->alerts.alert_name_pattern && !simple_pattern_matches_string(ctl->alerts.alert_name_pattern, rcl->config.name))
53 continue;
54
55 - if(ctl->alerts.alarm_id_filter && ctl->alerts.alarm_id_filter != rcl->id)
55 + if(ctl->alerts.alarm_id_filter && ctl->alerts.alarm_id_filter != (time_t)rcl->id)
56 continue;
57
58 size_t m = ctl->request->alerts.status & CONTEXTS_ALERT_STATUSES ? 0 : 1;
src/database/engine/pagecache.c
+1 -1
@@ -264,7 +264,7 @@ static size_t get_page_list_from_pgc(PGC *cache, METRIC *metric, struct rrdengin
264 break;
265 }
266
267 - if (page_start_time_s - previous_page_end_time_s > dt_s)
267 + if (page_start_time_s - previous_page_end_time_s > (time_t)dt_s)
268 (*cache_gaps)++;
269
270 Pvoid_t *PValue = PDCJudyLIns(JudyL_page_array, (Word_t) page_start_time_s, PJE0);
src/database/engine/pdc.c
+1 -1
@@ -716,7 +716,7 @@ VALIDATED_PAGE_DESCRIPTOR validate_page(
716
717 // allow to be called without update every (when loading pages from disk)
718 if(!update_every_s) {
719 - vd.update_every_s = (vd.entries > 1) ? ((vd.end_time_s - vd.start_time_s) / (time_t) (vd.entries - 1))
719 + vd.update_every_s = (vd.entries > 1) ? ((uint32_t)(vd.end_time_s - vd.start_time_s) / (vd.entries - 1))
720 : overwrite_zero_update_every_s;
721
722 update_every_s = vd.update_every_s;
src/database/sqlite/sqlite_aclk_alert.c
+11 -11
@@ -466,11 +466,11 @@ static void aclk_push_alert_event(RRDHOST *host __maybe_unused)
466 nd_log(
467 NDLS_ACCESS,
468 NDLP_DEBUG,
469 - "ACLK RES [%s (%s)]: ALERTS SENT from %ld - %ld",
469 + "ACLK RES [%s (%s)]: ALERTS SENT from %lld - %lld",
470 node_id_str,
471 rrdhost_hostname(host),
472 - first_id,
473 - last_id);
472 + (long long)first_id,
473 + (long long)last_id);
474
475 delete_alert_from_submit_queue(host, first_id, last_id);
476 // Mark to do one more check
@@ -802,11 +802,11 @@ static void schedule_alert_snapshot_if_needed(struct aclk_sync_cfg_t *wc, uint64
802 nd_log(
803 NDLS_ACCESS,
804 NDLP_NOTICE,
805 - "Scheduling alert snapshot for host \"%s\", node \"%s\" (version: cloud %zu, local %zu)",
805 + "Scheduling alert snapshot for host \"%s\", node \"%s\" (version: cloud %llu, local %llu)",
806 rrdhost_hostname(wc->host),
807 wc->node_id,
808 - cloud_version,
809 - local_version);
808 + (long long unsigned)cloud_version,
809 + (long long unsigned)local_version);
810
811 wc->send_snapshot = 1;
812 rrdhost_flag_set(wc->host, RRDHOST_FLAG_ACLK_STREAM_ALERTS);
@@ -815,11 +815,11 @@ static void schedule_alert_snapshot_if_needed(struct aclk_sync_cfg_t *wc, uint64
815 nd_log(
816 NDLS_ACCESS,
817 NDLP_DEBUG,
818 - "Alert check on \"%s\", node \"%s\" (version: cloud %zu, local %zu)",
818 + "Alert check on \"%s\", node \"%s\" (version: cloud %llu, local %llu)",
819 rrdhost_hostname(wc->host),
820 wc->node_id,
821 - cloud_version,
822 - local_version);
821 + (unsigned long long)cloud_version,
822 + (unsigned long long)local_version);
823 wc->checkpoint_count++;
824 }
825
@@ -979,12 +979,12 @@ void send_alert_snapshot_to_cloud(RRDHOST *host __maybe_unused)
979 nd_log(
980 NDLS_ACCESS,
981 NDLP_DEBUG,
982 - "ACLK REQ [%s (%s)]: Sent! %d alerts snapshot, snapshot_uuid %s (version = %zu)",
982 + "ACLK REQ [%s (%s)]: Sent! %d alerts snapshot, snapshot_uuid %s (version = %llu)",
983 wc->node_id,
984 rrdhost_hostname(host),
985 cnt,
986 snapshot_uuid,
987 - version);
987 + (long long unsigned)version);
988
989 done:
990 REPORT_BIND_FAIL(res, param);
src/libnetdata/facets/facets.c
+2 -2
@@ -106,7 +106,7 @@ static inline bool is_valid_string_hash(const char *s) {
106
107 struct facet_value;
108 // #define SIMPLE_HASHTABLE_SORT_FUNCTION compare_facet_value
109 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct facet_value
109 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct facet_value *
110 #define SIMPLE_HASHTABLE_NAME _VALUE
111 #include "../simple_hashtable/simple_hashtable.h"
112
@@ -118,7 +118,7 @@ struct facet_value;
118
119 struct facet_key;
120 // #define SIMPLE_HASHTABLE_SORT_FUNCTION compare_facet_key
121 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct facet_key
121 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct facet_key *
122 #define SIMPLE_HASHTABLE_NAME _KEY
123 #include "../simple_hashtable/simple_hashtable.h"
124
src/libnetdata/local-sockets/local-sockets.h
+9 -7
@@ -27,6 +27,8 @@
27 // hashtable for keeping the namespaces
28 // key and value is the namespace inode
29
30 +#define SIMPLE_HASHTABLE_KEY_TYPE uint64_t
31 +#define SIMPLE_HASHTABLE_VALUE_TYPE_IS_NOT_POINTER
32 #define SIMPLE_HASHTABLE_VALUE_TYPE uint64_t
33 #define SIMPLE_HASHTABLE_NAME _NET_NS
34 #include "libnetdata/simple_hashtable/simple_hashtable.h"
@@ -36,7 +38,7 @@
38 // key is the inode
39
40 struct pid_socket;
39 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct pid_socket
41 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct pid_socket *
42 #define SIMPLE_HASHTABLE_NAME _PID_SOCKET
43 #include "libnetdata/simple_hashtable/simple_hashtable.h"
44
@@ -45,7 +47,7 @@ struct pid_socket;
47 // key is the inode
48
49 struct local_socket;
48 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct local_socket
50 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct local_socket *
51 #define SIMPLE_HASHTABLE_NAME _LOCAL_SOCKET
52 #include "libnetdata/simple_hashtable/simple_hashtable.h"
53
@@ -54,7 +56,7 @@ struct local_socket;
56 // key is XXH3_64bits hash of the IP
57
58 union ipv46;
57 -#define SIMPLE_HASHTABLE_VALUE_TYPE union ipv46
59 +#define SIMPLE_HASHTABLE_VALUE_TYPE union ipv46 *
60 #define SIMPLE_HASHTABLE_NAME _LOCAL_IP
61 #include "libnetdata/simple_hashtable/simple_hashtable.h"
62
@@ -63,7 +65,7 @@ union ipv46;
65 // key is XXH3_64bits hash of the family, protocol, port number, namespace
66
67 struct local_port;
66 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct local_port
68 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct local_port *
69 #define SIMPLE_HASHTABLE_NAME _LISTENING_PORT
70 #include "libnetdata/simple_hashtable/simple_hashtable.h"
71
@@ -674,8 +676,8 @@ static inline bool local_sockets_find_all_sockets_in_proc(LS_STATE *ls, const ch
676 snprintfz(filename, sizeof(filename), "%s/%s/ns/net", proc_filename, proc_entry->d_name);
677 if(local_sockets_read_proc_inode_link(ls, filename, &net_ns_inode, "net")) {
678 XXH64_hash_t net_ns_inode_hash = XXH3_64bits(&net_ns_inode, sizeof(net_ns_inode));
677 - SIMPLE_HASHTABLE_SLOT_NET_NS *sl_ns = simple_hashtable_get_slot_NET_NS(&ls->ns_hashtable, net_ns_inode_hash, (uint64_t *)net_ns_inode, true);
678 - simple_hashtable_set_slot_NET_NS(&ls->ns_hashtable, sl_ns, net_ns_inode, (uint64_t *)net_ns_inode);
679 + SIMPLE_HASHTABLE_SLOT_NET_NS *sl_ns = simple_hashtable_get_slot_NET_NS(&ls->ns_hashtable, net_ns_inode_hash, &net_ns_inode, true);
680 + simple_hashtable_set_slot_NET_NS(&ls->ns_hashtable, sl_ns, net_ns_inode, net_ns_inode);
681 }
682 }
683
@@ -896,7 +898,7 @@ static inline bool local_sockets_libmnl_get_sockets(LS_STATE *ls, uint16_t famil
898 struct nlmsghdr *nlh = mnl_nlmsg_put_header(buf);
899 nlh->nlmsg_type = SOCK_DIAG_BY_FAMILY;
900 nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
899 - nlh->nlmsg_seq = ls->ns_state.nl_seq ? ls->ns_state.nl_seq++ : time(NULL);
901 + nlh->nlmsg_seq = ls->ns_state.nl_seq ? ls->ns_state.nl_seq++ : (uint32_t)time(NULL);
902
903 struct inet_diag_req_v2 req = {
904 .sdiag_family = family,
src/libnetdata/os/system-maps/cached-gid-groupname.c
+1 -1
@@ -7,7 +7,7 @@
7 // key is the gid, value is groupname (STRING)
8
9 #define SIMPLE_HASHTABLE_KEY_TYPE gid_t
10 -#define SIMPLE_HASHTABLE_VALUE_TYPE CACHED_GROUPNAME
10 +#define SIMPLE_HASHTABLE_VALUE_TYPE CACHED_GROUPNAME *
11 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION cached_groupname_to_gid_ptr
12 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compar_gid_ptr
13 #define SIMPLE_HASHTABLE_NAME _GROUPNAMES_CACHE
src/libnetdata/os/system-maps/cached-sid-username.c
+1 -1
@@ -24,7 +24,7 @@ typedef struct {
24 } SID_VALUE;
25
26 #define SIMPLE_HASHTABLE_NAME _SID
27 -#define SIMPLE_HASHTABLE_VALUE_TYPE SID_VALUE
27 +#define SIMPLE_HASHTABLE_VALUE_TYPE SID_VALUE *
28 #define SIMPLE_HASHTABLE_KEY_TYPE SID_KEY
29 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION sid_value_to_key
30 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION sid_cache_compar
src/libnetdata/os/system-maps/cached-uid-username.c
+1 -1
@@ -7,7 +7,7 @@
7 // key is the uid, value is username (STRING)
8
9 #define SIMPLE_HASHTABLE_KEY_TYPE uid_t
10 -#define SIMPLE_HASHTABLE_VALUE_TYPE CACHED_USERNAME
10 +#define SIMPLE_HASHTABLE_VALUE_TYPE CACHED_USERNAME *
11 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION cached_username_to_uid_ptr
12 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compar_uid_ptr
13 #define SIMPLE_HASHTABLE_NAME _USERNAMES_CACHE
src/libnetdata/os/system-maps/system-services.h
+1 -1
@@ -10,7 +10,7 @@
10 // hashtable for caching port and protocol to service name mappings
11 // key is the combination of protocol and port packed into an uint64_t, value is service name (STRING)
12
13 -#define SIMPLE_HASHTABLE_VALUE_TYPE STRING
13 +#define SIMPLE_HASHTABLE_VALUE_TYPE STRING *
14 #define SIMPLE_HASHTABLE_NAME _SERVICENAMES_CACHE
15 #include "libnetdata/simple_hashtable/simple_hashtable.h"
16
src/libnetdata/os/windows-perflib/perflib-names.c
+1 -1
@@ -22,7 +22,7 @@ static inline const char *value2key_perfLibRegistryEntry(perfLibRegistryEntry *e
22 #define SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION compare_perfLibRegistryEntry
23 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION value2key_perfLibRegistryEntry
24 #define SIMPLE_HASHTABLE_KEY_TYPE const char
25 -#define SIMPLE_HASHTABLE_VALUE_TYPE perfLibRegistryEntry
25 +#define SIMPLE_HASHTABLE_VALUE_TYPE perfLibRegistryEntry *
26 #define SIMPLE_HASHTABLE_NAME _PERFLIB
27 #include "libnetdata/simple_hashtable/simple_hashtable.h"
28
src/libnetdata/query_progress/progress.c
+1 -1
@@ -11,7 +11,7 @@
11 #include "../simple_hashtable/simple_hashtable_undef.h"
12
13 struct query;
14 -#define SIMPLE_HASHTABLE_VALUE_TYPE struct query
14 +#define SIMPLE_HASHTABLE_VALUE_TYPE struct query *
15 #define SIMPLE_HASHTABLE_KEY_TYPE nd_uuid_t
16 #define SIMPLE_HASHTABLE_NAME _QUERY
17 #define SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION query_transaction
src/libnetdata/simple_hashtable/simple_hashtable.h
+66 -36
@@ -49,7 +49,7 @@ typedef uint64_t SIMPLE_HASHTABLE_HASH;
49 #endif
50
51 #ifndef SIMPLE_HASHTABLE_VALUE_TYPE
52 -#define SIMPLE_HASHTABLE_VALUE_TYPE void
52 +#define SIMPLE_HASHTABLE_VALUE_TYPE void *
53 #endif
54
55 #ifndef SIMPLE_HASHTABLE_KEY_TYPE
@@ -60,8 +60,12 @@ typedef uint64_t SIMPLE_HASHTABLE_HASH;
60 #undef SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION
61 #endif
62
63 +// check during compilation
64 +_Static_assert(sizeof(SIMPLE_HASHTABLE_VALUE_TYPE) <= sizeof(uint64_t),
65 + "simple hashtable value cannot be bigger than 8 bytes");
66 +
67 #if defined(SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION)
64 -static inline SIMPLE_HASHTABLE_KEY_TYPE *SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION(SIMPLE_HASHTABLE_VALUE_TYPE *);
68 +static inline SIMPLE_HASHTABLE_KEY_TYPE *SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION(SIMPLE_HASHTABLE_VALUE_TYPE);
69 #endif
70
71 #if defined(SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION)
@@ -102,7 +106,10 @@ static inline bool SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION(SIMPLE_HASHTABLE_KEY_T
106
107 typedef struct simple_hashtable_slot_named {
108 SIMPLE_HASHTABLE_HASH hash;
105 - SIMPLE_HASHTABLE_VALUE_TYPE *data;
109 + union {
110 + SIMPLE_HASHTABLE_VALUE_TYPE data;
111 + uint64_t v; // make sure it is always 64bit (required to store our deleted or usernull values)
112 + };
113 } SIMPLE_HASHTABLE_SLOT_NAMED;
114
115 typedef struct simple_hashtable_named {
@@ -121,13 +128,13 @@ typedef struct simple_hashtable_named {
128 struct {
129 size_t used;
130 size_t size;
124 - SIMPLE_HASHTABLE_VALUE_TYPE **array;
131 + SIMPLE_HASHTABLE_VALUE_TYPE *array;
132 } sorted;
133 #endif
134 } SIMPLE_HASHTABLE_NAMED;
135
136 #ifdef SIMPLE_HASHTABLE_SORT_FUNCTION
130 -static inline size_t simple_hashtable_sorted_binary_search_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE *value) {
137 +static inline size_t simple_hashtable_sorted_binary_search_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE value) {
138 size_t left = 0, right = ht->sorted.used;
139
140 while (left < right) {
@@ -141,15 +148,15 @@ static inline size_t simple_hashtable_sorted_binary_search_named(SIMPLE_HASHTABL
148 return left;
149 }
150
144 -static inline void simple_hashtable_add_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE *value) {
151 +static inline void simple_hashtable_add_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE value) {
152 size_t index = simple_hashtable_sorted_binary_search_named(ht, value);
153
154 // Ensure there's enough space in the sorted array
155 if (ht->sorted.used >= ht->sorted.size) {
156 size_t size = ht->sorted.size ? ht->sorted.size * 2 : 64;
150 - SIMPLE_HASHTABLE_VALUE_TYPE **array = mallocz(size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE *));
157 + SIMPLE_HASHTABLE_VALUE_TYPE *array = mallocz(size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE));
158 if(ht->sorted.array) {
152 - memcpy(array, ht->sorted.array, ht->sorted.size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE *));
159 + memcpy(array, ht->sorted.array, ht->sorted.size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE));
160 freez(ht->sorted.array);
161 }
162 ht->sorted.array = array;
@@ -157,24 +164,24 @@ static inline void simple_hashtable_add_value_sorted_named(SIMPLE_HASHTABLE_NAME
164 }
165
166 // Use memmove to shift elements and create space for the new element
160 - memmove(&ht->sorted.array[index + 1], &ht->sorted.array[index], (ht->sorted.used - index) * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE *));
167 + memmove(&ht->sorted.array[index + 1], &ht->sorted.array[index], (ht->sorted.used - index) * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE));
168
169 ht->sorted.array[index] = value;
170 ht->sorted.used++;
171 }
172
166 -static inline void simple_hashtable_del_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE *value) {
173 +static inline void simple_hashtable_del_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE value) {
174 size_t index = simple_hashtable_sorted_binary_search_named(ht, value);
175
176 // Check if the value exists at the found index
177 assert(index < ht->sorted.used && ht->sorted.array[index] == value);
178
179 // Use memmove to shift elements and close the gap
173 - memmove(&ht->sorted.array[index], &ht->sorted.array[index + 1], (ht->sorted.used - index - 1) * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE *));
180 + memmove(&ht->sorted.array[index], &ht->sorted.array[index + 1], (ht->sorted.used - index - 1) * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE));
181 ht->sorted.used--;
182 }
183
177 -static inline void simple_hashtable_replace_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE *old_value, SIMPLE_HASHTABLE_VALUE_TYPE *new_value) {
184 +static inline void simple_hashtable_replace_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE old_value, SIMPLE_HASHTABLE_VALUE_TYPE new_value) {
185 if(new_value == old_value)
186 return;
187
@@ -200,7 +207,7 @@ static inline void simple_hashtable_replace_value_sorted_named(SIMPLE_HASHTABLE_
207 size_t shift_end = new_value_index - 1;
208 size_t shift_size = shift_end - old_value_index;
209
203 - memmove(&ht->sorted.array[old_value_index], &ht->sorted.array[shift_start], shift_size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE *));
210 + memmove(&ht->sorted.array[old_value_index], &ht->sorted.array[shift_start], shift_size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE));
211 ht->sorted.array[shift_end] = new_value;
212 }
213 else {
@@ -209,19 +216,19 @@ static inline void simple_hashtable_replace_value_sorted_named(SIMPLE_HASHTABLE_
216 size_t shift_end = old_value_index;
217 size_t shift_size = shift_end - new_value_index;
218
212 - memmove(&ht->sorted.array[new_value_index + 1], &ht->sorted.array[shift_start], shift_size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE *));
219 + memmove(&ht->sorted.array[new_value_index + 1], &ht->sorted.array[shift_start], shift_size * sizeof(SIMPLE_HASHTABLE_VALUE_TYPE));
220 ht->sorted.array[new_value_index] = new_value;
221 }
222 }
223
217 -static inline SIMPLE_HASHTABLE_VALUE_TYPE **simple_hashtable_sorted_array_first_read_only_named(SIMPLE_HASHTABLE_NAMED *ht) {
224 +static inline SIMPLE_HASHTABLE_VALUE_TYPE *simple_hashtable_sorted_array_first_read_only_named(SIMPLE_HASHTABLE_NAMED *ht) {
225 if (ht->sorted.used > 0) {
226 return &ht->sorted.array[0];
227 }
228 return NULL;
229 }
230
224 -static inline SIMPLE_HASHTABLE_VALUE_TYPE **simple_hashtable_sorted_array_next_read_only_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE **last) {
231 +static inline SIMPLE_HASHTABLE_VALUE_TYPE *simple_hashtable_sorted_array_next_read_only_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_VALUE_TYPE *last) {
232 if (!last) return NULL;
233
234 // Calculate the current position in the sorted array
@@ -244,9 +251,9 @@ static inline SIMPLE_HASHTABLE_VALUE_TYPE **simple_hashtable_sorted_array_next_r
251 #define SIMPLE_HASHTABLE_SORTED_FOREACH_READ_ONLY_VALUE(var) (*(var))
252
253 #else
247 -static inline void simple_hashtable_add_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE *value __maybe_unused) { ; }
248 -static inline void simple_hashtable_del_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE *value __maybe_unused) { ; }
249 -static inline void simple_hashtable_replace_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE *old_value __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE *new_value __maybe_unused) { ; }
254 +static inline void simple_hashtable_add_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE value __maybe_unused) { ; }
255 +static inline void simple_hashtable_del_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE value __maybe_unused) { ; }
256 +static inline void simple_hashtable_replace_value_sorted_named(SIMPLE_HASHTABLE_NAMED *ht __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE old_value __maybe_unused, SIMPLE_HASHTABLE_VALUE_TYPE new_value __maybe_unused) { ; }
257 #endif
258
259 static inline void simple_hashtable_init_named(SIMPLE_HASHTABLE_NAMED *ht, size_t size) {
@@ -266,13 +273,16 @@ static inline void simple_hashtable_destroy_named(SIMPLE_HASHTABLE_NAMED *ht) {
273
274 static inline void simple_hashtable_resize_named(SIMPLE_HASHTABLE_NAMED *ht);
275
269 -#define simple_hashtable_data_unset ((void *)NULL)
270 -#define simple_hashtable_data_deleted ((void *)UINT64_MAX)
271 -#define simple_hashtable_data_usernull ((void *)(UINT64_MAX - 1))
272 -#define simple_hashtable_is_slot_unset(sl) ((sl)->data == simple_hashtable_data_unset)
273 -#define simple_hashtable_is_slot_deleted(sl) ((sl)->data == simple_hashtable_data_deleted)
274 -#define simple_hashtable_is_slot_usernull(sl) ((sl)->data == simple_hashtable_data_usernull)
275 -#define SIMPLE_HASHTABLE_SLOT_DATA(sl) ((simple_hashtable_is_slot_unset(sl) || simple_hashtable_is_slot_deleted(sl) || simple_hashtable_is_slot_usernull(sl)) ? NULL : (sl)->data)
276 +#define simple_hashtable_data_unset ((uint64_t)0)
277 +#define simple_hashtable_data_deleted ((uint64_t)UINT64_MAX)
278 +#define simple_hashtable_data_usernull ((uint64_t)(UINT64_MAX - 1))
279 +#define simple_hashtable_is_slot_unset(sl) ((sl)->v == simple_hashtable_data_unset)
280 +#define simple_hashtable_is_slot_deleted(sl) ((sl)->v == simple_hashtable_data_deleted)
281 +#define simple_hashtable_is_slot_usernull(sl) ((sl)->v == simple_hashtable_data_usernull)
282 +#define SIMPLE_HASHTABLE_SLOT_DATA(sl) \
283 + ((simple_hashtable_is_slot_unset(sl) || simple_hashtable_is_slot_deleted(sl) || simple_hashtable_is_slot_usernull(sl)) \
284 + ? (typeof((sl)->data))0 \
285 + : (sl)->data)
286
287 static inline bool simple_hashtable_can_use_slot_named(
288 SIMPLE_HASHTABLE_SLOT_NAMED *sl, SIMPLE_HASHTABLE_HASH hash,
@@ -390,36 +400,56 @@ static inline bool simple_hashtable_del_slot_named(SIMPLE_HASHTABLE_NAMED *ht, S
400
401 simple_hashtable_del_value_sorted_named(ht, SIMPLE_HASHTABLE_SLOT_DATA(sl));
402
393 - sl->data = simple_hashtable_data_deleted;
403 + sl->v = simple_hashtable_data_deleted;
404 return true;
405 }
406
407 static inline void simple_hashtable_set_slot_named(
408 SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_SLOT_NAMED *sl,
399 - SIMPLE_HASHTABLE_HASH hash, SIMPLE_HASHTABLE_VALUE_TYPE *data) {
409 + SIMPLE_HASHTABLE_HASH hash, SIMPLE_HASHTABLE_VALUE_TYPE data) {
410
401 - if(data == NULL)
402 - data = simple_hashtable_data_usernull;
411 + uint64_t v;
412 + if(unlikely(data == (SIMPLE_HASHTABLE_VALUE_TYPE)0))
413 + v = simple_hashtable_data_usernull;
414 + else {
415 +#ifdef SIMPLE_HASHTABLE_VALUE_TYPE_IS_NOT_POINTER
416 + v = (uint64_t)data;
417 +#else
418 + v = (uint64_t)(uintptr_t)data;
419 +#endif
420 + }
421
404 - if(unlikely(data == simple_hashtable_data_unset || data == simple_hashtable_data_deleted)) {
422 + if(unlikely(v == simple_hashtable_data_unset || v == simple_hashtable_data_deleted)) {
423 + // the new value is unset or deleted,
424 + // mark the slot as deleted (updating the sorted array as necessary)
425 simple_hashtable_del_slot_named(ht, sl);
426 return;
427 }
428
429 if(likely(simple_hashtable_is_slot_unset(sl))) {
430 + // the slot is empty,
431 + // add the new value to the sorted array (when sorting is requested)
432 simple_hashtable_add_value_sorted_named(ht, data);
433 ht->used++;
434 }
435
436 else if(unlikely(simple_hashtable_is_slot_deleted(sl))) {
437 + // the slot is deleted,
438 + // add the new value to the sorted array (when sorting is requested)
439 + simple_hashtable_add_value_sorted_named(ht, data);
440 ht->deleted--;
441 }
442
418 - else
443 + else {
444 + // the slot is occupied,
445 + // replace the old value with the new value in the sorted array (when sorting is requested)
446 simple_hashtable_replace_value_sorted_named(ht, SIMPLE_HASHTABLE_SLOT_DATA(sl), data);
447 + }
448
449 + // update the slot with the new value
450 sl->hash = hash;
422 - sl->data = data;
451 + sl->v = v;
452 +
453 ht->additions++;
454 }
455
@@ -446,7 +476,7 @@ static inline void simple_hashtable_resize_named(SIMPLE_HASHTABLE_NAMED *ht) {
476 SIMPLE_HASHTABLE_KEY_TYPE *key = NULL;
477
478 #if defined(SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION) && defined(SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION)
449 - SIMPLE_HASHTABLE_VALUE_TYPE *value = SIMPLE_HASHTABLE_SLOT_DATA(slot);
479 + SIMPLE_HASHTABLE_VALUE_TYPE value = SIMPLE_HASHTABLE_SLOT_DATA(slot);
480 key = SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION(value);
481 #endif
482
@@ -517,14 +547,14 @@ static inline SIMPLE_HASHTABLE_SLOT_NAMED *simple_hashtable_next_read_only_named
547 #define simple_hashtable_get_named CONCAT(simple_hashtable_get, SIMPLE_HASHTABLE_NAME)
548 #define simple_hashtable_del_named CONCAT(simple_hashtable_del, SIMPLE_HASHTABLE_NAME)
549
520 -static inline SIMPLE_HASHTABLE_VALUE_TYPE *simple_hashtable_set_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_KEY_TYPE *key, size_t key_len, SIMPLE_HASHTABLE_VALUE_TYPE *data) {
550 +static inline SIMPLE_HASHTABLE_VALUE_TYPE simple_hashtable_set_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_KEY_TYPE *key, size_t key_len, SIMPLE_HASHTABLE_VALUE_TYPE data) {
551 XXH64_hash_t hash = XXH3_64bits((void *)key, key_len);
552 SIMPLE_HASHTABLE_SLOT_NAMED *sl = simple_hashtable_get_slot_named(ht, hash, key, true);
553 simple_hashtable_set_slot_named(ht, sl, hash, data);
554 return SIMPLE_HASHTABLE_SLOT_DATA(sl);
555 }
556
527 -static inline SIMPLE_HASHTABLE_VALUE_TYPE *simple_hashtable_get_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_KEY_TYPE *key, size_t key_len) {
557 +static inline SIMPLE_HASHTABLE_VALUE_TYPE simple_hashtable_get_named(SIMPLE_HASHTABLE_NAMED *ht, SIMPLE_HASHTABLE_KEY_TYPE *key, size_t key_len) {
558 XXH64_hash_t hash = XXH3_64bits((void *)key, key_len);
559 SIMPLE_HASHTABLE_SLOT_NAMED *sl = simple_hashtable_get_slot_named(ht, hash, key, true);
560 return SIMPLE_HASHTABLE_SLOT_DATA(sl);
src/libnetdata/simple_hashtable/simple_hashtable_undef.h
+1
@@ -28,6 +28,7 @@
28 #undef SIMPLE_HASHTABLE_SAMPLE_IMPLEMENTATION
29 #undef SIMPLE_HASHTABLE_SORT_FUNCTION
30 #undef SIMPLE_HASHTABLE_VALUE_TYPE
31 +#undef SIMPLE_HASHTABLE_VALUE_TYPE_IS_NOT_POINTER
32 #undef SIMPLE_HASHTABLE_KEY_TYPE
33 #undef SIMPLE_HASHTABLE_VALUE2KEY_FUNCTION
34 #undef SIMPLE_HASHTABLE_COMPARE_KEYS_FUNCTION
src/libnetdata/spawn_server/log-forwarder.c
+322 -322
@@ -1,322 +1,322 @@
1 -// SPDX-License-Identifier: GPL-3.0-or-later
2 -
3 -#include "../libnetdata.h"
4 -#include "log-forwarder.h"
5 -
6 -typedef struct LOG_FORWARDER_ENTRY {
7 - int fd;
8 - char *cmd;
9 - pid_t pid;
10 - BUFFER *wb;
11 - size_t pfds_idx;
12 - bool delete;
13 -
14 - struct LOG_FORWARDER_ENTRY *prev;
15 - struct LOG_FORWARDER_ENTRY *next;
16 -} LOG_FORWARDER_ENTRY;
17 -
18 -typedef struct LOG_FORWARDER {
19 - LOG_FORWARDER_ENTRY *entries;
20 - ND_THREAD *thread;
21 - SPINLOCK spinlock;
22 - int pipe_fds[2]; // Pipe for notifications
23 - bool running;
24 -} LOG_FORWARDER;
25 -
26 -static void *log_forwarder_thread_func(void *arg);
27 -
28 -// --------------------------------------------------------------------------------------------------------------------
29 -// helper functions
30 -
31 -static inline LOG_FORWARDER_ENTRY *log_forwarder_find_entry_unsafe(LOG_FORWARDER *lf, int fd) {
32 - for (LOG_FORWARDER_ENTRY *entry = lf->entries; entry; entry = entry->next) {
33 - if (entry->fd == fd)
34 - return entry;
35 - }
36 -
37 - return NULL;
38 -}
39 -
40 -static inline void log_forwarder_del_entry_unsafe(LOG_FORWARDER *lf, LOG_FORWARDER_ENTRY *entry) {
41 - DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(lf->entries, entry, prev, next);
42 - buffer_free(entry->wb);
43 - freez(entry->cmd);
44 - close(entry->fd);
45 - freez(entry);
46 -}
47 -
48 -static inline void log_forwarder_wake_up_worker(LOG_FORWARDER *lf) {
49 - char ch = 0;
50 - ssize_t bytes_written = write(lf->pipe_fds[PIPE_WRITE], &ch, 1);
51 - if (bytes_written != 1)
52 - nd_log(NDLS_COLLECTORS, NDLP_ERR, "Failed to write to notification pipe");
53 -}
54 -
55 -// --------------------------------------------------------------------------------------------------------------------
56 -// starting / stopping
57 -
58 -LOG_FORWARDER *log_forwarder_start(void) {
59 - LOG_FORWARDER *lf = callocz(1, sizeof(LOG_FORWARDER));
60 -
61 - spinlock_init(&lf->spinlock);
62 - if (pipe(lf->pipe_fds) != 0) {
63 - freez(lf);
64 - return NULL;
65 - }
66 -
67 - // make sure read() will not block on this pipe
68 - sock_setnonblock(lf->pipe_fds[PIPE_READ]);
69 -
70 - lf->running = true;
71 - lf->thread = nd_thread_create("log-fw", NETDATA_THREAD_OPTION_JOINABLE, log_forwarder_thread_func, lf);
72 -
73 - return lf;
74 -}
75 -
76 -static inline void mark_all_entries_for_deletion_unsafe(LOG_FORWARDER *lf) {
77 - for(LOG_FORWARDER_ENTRY *entry = lf->entries; entry ;entry = entry->next)
78 - entry->delete = true;
79 -}
80 -
81 -void log_forwarder_stop(LOG_FORWARDER *lf) {
82 - if(!lf || !lf->running) return;
83 -
84 - // Signal the thread to stop
85 - spinlock_lock(&lf->spinlock);
86 - lf->running = false;
87 -
88 - // mark them all for deletion
89 - mark_all_entries_for_deletion_unsafe(lf);
90 -
91 - // Send a byte to the pipe to wake up the thread
92 - char ch = 0;
93 - write(lf->pipe_fds[PIPE_WRITE], &ch, 1);
94 - spinlock_unlock(&lf->spinlock);
95 -
96 - // Wait for the thread to finish
97 - close(lf->pipe_fds[PIPE_WRITE]); // force it to quit
98 - nd_thread_join(lf->thread);
99 - close(lf->pipe_fds[PIPE_READ]);
100 -
101 - freez(lf);
102 -}
103 -
104 -// --------------------------------------------------------------------------------------------------------------------
105 -// managing entries
106 -
107 -void log_forwarder_add_fd(LOG_FORWARDER *lf, int fd) {
108 - if(!lf || !lf->running || fd < 0) return;
109 -
110 - LOG_FORWARDER_ENTRY *entry = callocz(1, sizeof(LOG_FORWARDER_ENTRY));
111 - entry->fd = fd;
112 - entry->cmd = NULL;
113 - entry->pid = 0;
114 - entry->pfds_idx = 0;
115 - entry->delete = false;
116 - entry->wb = buffer_create(0, NULL);
117 -
118 - spinlock_lock(&lf->spinlock);
119 -
120 - // Append to the entries list
121 - DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(lf->entries, entry, prev, next);
122 -
123 - // Send a byte to the pipe to wake up the thread
124 - log_forwarder_wake_up_worker(lf);
125 -
126 - spinlock_unlock(&lf->spinlock);
127 -}
128 -
129 -bool log_forwarder_del_and_close_fd(LOG_FORWARDER *lf, int fd) {
130 - if(!lf || !lf->running || fd < 0) return false;
131 -
132 - bool ret = false;
133 -
134 - spinlock_lock(&lf->spinlock);
135 -
136 - LOG_FORWARDER_ENTRY *entry = log_forwarder_find_entry_unsafe(lf, fd);
137 - if(entry) {
138 - entry->delete = true;
139 -
140 - // Send a byte to the pipe to wake up the thread
141 - log_forwarder_wake_up_worker(lf);
142 -
143 - ret = true;
144 - }
145 -
146 - spinlock_unlock(&lf->spinlock);
147 -
148 - return ret;
149 -}
150 -
151 -void log_forwarder_annotate_fd_name(LOG_FORWARDER *lf, int fd, const char *cmd) {
152 - if(!lf || !lf->running || fd < 0 || !cmd || !*cmd) return;
153 -
154 - spinlock_lock(&lf->spinlock);
155 -
156 - LOG_FORWARDER_ENTRY *entry = log_forwarder_find_entry_unsafe(lf, fd);
157 - if (entry) {
158 - freez(entry->cmd);
159 - entry->cmd = strdupz(cmd);
160 - }
161 -
162 - spinlock_unlock(&lf->spinlock);
163 -}
164 -
165 -void log_forwarder_annotate_fd_pid(LOG_FORWARDER *lf, int fd, pid_t pid) {
166 - if(!lf || !lf->running || fd < 0) return;
167 -
168 - spinlock_lock(&lf->spinlock);
169 -
170 - LOG_FORWARDER_ENTRY *entry = log_forwarder_find_entry_unsafe(lf, fd);
171 - if (entry)
172 - entry->pid = pid;
173 -
174 - spinlock_unlock(&lf->spinlock);
175 -}
176 -
177 -// --------------------------------------------------------------------------------------------------------------------
178 -// log forwarder thread
179 -
180 -static inline void log_forwarder_log(LOG_FORWARDER *lf __maybe_unused, LOG_FORWARDER_ENTRY *entry, const char *msg) {
181 - const char *s = msg;
182 - while(*s && isspace((uint8_t)*s)) s++;
183 - if(*s == '\0') return; // do not log empty lines
184 -
185 - ND_LOG_STACK lgs[] = {
186 - ND_LOG_FIELD_TXT(NDF_SYSLOG_IDENTIFIER, entry->cmd ? entry->cmd : "unknown"),
187 - ND_LOG_FIELD_I64(NDF_TID, entry->pid),
188 - ND_LOG_FIELD_END(),
189 - };
190 - ND_LOG_STACK_PUSH(lgs);
191 -
192 - nd_log(NDLS_COLLECTORS, NDLP_WARNING, "STDERR: %s", msg);
193 -}
194 -
195 -// returns the number of entries active
196 -static inline size_t log_forwarder_remove_deleted_unsafe(LOG_FORWARDER *lf) {
197 - size_t entries = 0;
198 -
199 - LOG_FORWARDER_ENTRY *entry = lf->entries;
200 - while(entry) {
201 - LOG_FORWARDER_ENTRY *next = entry->next;
202 -
203 - if(entry->delete) {
204 - if (buffer_strlen(entry->wb))
205 - // there is something not logged in it - log it
206 - log_forwarder_log(lf, entry, buffer_tostring(entry->wb));
207 -
208 - log_forwarder_del_entry_unsafe(lf, entry);
209 - }
210 - else
211 - entries++;
212 -
213 - entry = next;
214 - }
215 -
216 - return entries;
217 -}
218 -
219 -static void *log_forwarder_thread_func(void *arg) {
220 - LOG_FORWARDER *lf = (LOG_FORWARDER *)arg;
221 -
222 - while (1) {
223 - spinlock_lock(&lf->spinlock);
224 - if (!lf->running) {
225 - mark_all_entries_for_deletion_unsafe(lf);
226 - log_forwarder_remove_deleted_unsafe(lf);
227 - spinlock_unlock(&lf->spinlock);
228 - break;
229 - }
230 -
231 - // Count the number of fds
232 - size_t nfds = 1 + log_forwarder_remove_deleted_unsafe(lf);
233 -
234 - struct pollfd pfds[nfds];
235 -
236 - // First, the notification pipe
237 - pfds[0].fd = lf->pipe_fds[PIPE_READ];
238 - pfds[0].events = POLLIN;
239 -
240 - int idx = 1;
241 - for(LOG_FORWARDER_ENTRY *entry = lf->entries; entry ; entry = entry->next, idx++) {
242 - pfds[idx].fd = entry->fd;
243 - pfds[idx].events = POLLIN;
244 - entry->pfds_idx = idx;
245 - }
246 -
247 - spinlock_unlock(&lf->spinlock);
248 -
249 - int timeout = 200; // 200ms
250 - int ret = poll(pfds, nfds, timeout);
251 -
252 - if (ret > 0) {
253 - // Check the notification pipe
254 - if (pfds[0].revents & POLLIN) {
255 - // Read and discard the data
256 - char buf[256];
257 - ssize_t bytes_read = read(lf->pipe_fds[PIPE_READ], buf, sizeof(buf));
258 - // Ignore the data; proceed regardless of the result
259 - if (bytes_read == -1) {
260 - if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
261 - // Handle read error if necessary
262 - nd_log(NDLS_COLLECTORS, NDLP_ERR, "Failed to read from notification pipe");
263 - return NULL;
264 - }
265 - }
266 - }
267 -
268 - // Now check the other fds
269 - spinlock_lock(&lf->spinlock);
270 -
271 - size_t to_remove = 0;
272 -
273 - // read or mark them for deletion
274 - for(LOG_FORWARDER_ENTRY *entry = lf->entries; entry ; entry = entry->next) {
275 - if (entry->pfds_idx < 1 || entry->pfds_idx >= nfds || !(pfds[entry->pfds_idx].revents & POLLIN))
276 - continue;
277 -
278 - BUFFER *wb = entry->wb;
279 - buffer_need_bytes(wb, 1024);
280 -
281 - ssize_t bytes_read = read(entry->fd, &wb->buffer[wb->len], wb->size - wb->len - 1);
282 - if(bytes_read > 0)
283 - wb->len += bytes_read;
284 - else if(bytes_read == 0 || (bytes_read == -1 && errno != EINTR && errno != EAGAIN)) {
285 - // EOF or error
286 - entry->delete = true;
287 - to_remove++;
288 - }
289 -
290 - // log as many lines are they have been received
291 - char *start = (char *)buffer_tostring(wb);
292 - char *newline = strchr(start, '\n');
293 - while(newline) {
294 - *newline = '\0';
295 - log_forwarder_log(lf, entry, start);
296 -
297 - start = ++newline;
298 - newline = strchr(newline, '\n');
299 - }
300 -
301 - if(start != wb->buffer) {
302 - wb->len = strlen(start);
303 - if (wb->len)
304 - memmove(wb->buffer, start, wb->len);
305 - }
306 -
307 - entry->pfds_idx = 0;
308 - }
309 -
310 - spinlock_unlock(&lf->spinlock);
311 - }
312 - else if (ret == 0) {
313 - // Timeout, nothing to do
314 - continue;
315 -
316 - }
317 - else
318 - nd_log(NDLS_COLLECTORS, NDLP_ERR, "Log forwarder: poll() error");
319 - }
320 -
321 - return NULL;
322 -}
1 +// SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +#include "../libnetdata.h"
4 +#include "log-forwarder.h"
5 +
6 +typedef struct LOG_FORWARDER_ENTRY {
7 + int fd;
8 + char *cmd;
9 + pid_t pid;
10 + BUFFER *wb;
11 + size_t pfds_idx;
12 + bool delete;
13 +
14 + struct LOG_FORWARDER_ENTRY *prev;
15 + struct LOG_FORWARDER_ENTRY *next;
16 +} LOG_FORWARDER_ENTRY;
17 +
18 +typedef struct LOG_FORWARDER {
19 + LOG_FORWARDER_ENTRY *entries;
20 + ND_THREAD *thread;
21 + SPINLOCK spinlock;
22 + int pipe_fds[2]; // Pipe for notifications
23 + bool running;
24 +} LOG_FORWARDER;
25 +
26 +static void *log_forwarder_thread_func(void *arg);
27 +
28 +// --------------------------------------------------------------------------------------------------------------------
29 +// helper functions
30 +
31 +static inline LOG_FORWARDER_ENTRY *log_forwarder_find_entry_unsafe(LOG_FORWARDER *lf, int fd) {
32 + for (LOG_FORWARDER_ENTRY *entry = lf->entries; entry; entry = entry->next) {
33 + if (entry->fd == fd)
34 + return entry;
35 + }
36 +
37 + return NULL;
38 +}
39 +
40 +static inline void log_forwarder_del_entry_unsafe(LOG_FORWARDER *lf, LOG_FORWARDER_ENTRY *entry) {
41 + DOUBLE_LINKED_LIST_REMOVE_ITEM_UNSAFE(lf->entries, entry, prev, next);
42 + buffer_free(entry->wb);
43 + freez(entry->cmd);
44 + close(entry->fd);
45 + freez(entry);
46 +}
47 +
48 +static inline void log_forwarder_wake_up_worker(LOG_FORWARDER *lf) {
49 + char ch = 0;
50 + ssize_t bytes_written = write(lf->pipe_fds[PIPE_WRITE], &ch, 1);
51 + if (bytes_written != 1)
52 + nd_log(NDLS_COLLECTORS, NDLP_ERR, "Failed to write to notification pipe");
53 +}
54 +
55 +// --------------------------------------------------------------------------------------------------------------------
56 +// starting / stopping
57 +
58 +LOG_FORWARDER *log_forwarder_start(void) {
59 + LOG_FORWARDER *lf = callocz(1, sizeof(LOG_FORWARDER));
60 +
61 + spinlock_init(&lf->spinlock);
62 + if (pipe(lf->pipe_fds) != 0) {
63 + freez(lf);
64 + return NULL;
65 + }
66 +
67 + // make sure read() will not block on this pipe
68 + sock_setnonblock(lf->pipe_fds[PIPE_READ]);
69 +
70 + lf->running = true;
71 + lf->thread = nd_thread_create("log-fw", NETDATA_THREAD_OPTION_JOINABLE, log_forwarder_thread_func, lf);
72 +
73 + return lf;
74 +}
75 +
76 +static inline void mark_all_entries_for_deletion_unsafe(LOG_FORWARDER *lf) {
77 + for(LOG_FORWARDER_ENTRY *entry = lf->entries; entry ;entry = entry->next)
78 + entry->delete = true;
79 +}
80 +
81 +void log_forwarder_stop(LOG_FORWARDER *lf) {
82 + if(!lf || !lf->running) return;
83 +
84 + // Signal the thread to stop
85 + spinlock_lock(&lf->spinlock);
86 + lf->running = false;
87 +
88 + // mark them all for deletion
89 + mark_all_entries_for_deletion_unsafe(lf);
90 +
91 + // Send a byte to the pipe to wake up the thread
92 + char ch = 0;
93 + if(write(lf->pipe_fds[PIPE_WRITE], &ch, 1) <= 0) { ; }
94 + spinlock_unlock(&lf->spinlock);
95 +
96 + // Wait for the thread to finish
97 + close(lf->pipe_fds[PIPE_WRITE]); // force it to quit
98 + nd_thread_join(lf->thread);
99 + close(lf->pipe_fds[PIPE_READ]);
100 +
101 + freez(lf);
102 +}
103 +
104 +// --------------------------------------------------------------------------------------------------------------------
105 +// managing entries
106 +
107 +void log_forwarder_add_fd(LOG_FORWARDER *lf, int fd) {
108 + if(!lf || !lf->running || fd < 0) return;
109 +
110 + LOG_FORWARDER_ENTRY *entry = callocz(1, sizeof(LOG_FORWARDER_ENTRY));
111 + entry->fd = fd;
112 + entry->cmd = NULL;
113 + entry->pid = 0;
114 + entry->pfds_idx = 0;
115 + entry->delete = false;
116 + entry->wb = buffer_create(0, NULL);
117 +
118 + spinlock_lock(&lf->spinlock);
119 +
120 + // Append to the entries list
121 + DOUBLE_LINKED_LIST_PREPEND_ITEM_UNSAFE(lf->entries, entry, prev, next);
122 +
123 + // Send a byte to the pipe to wake up the thread
124 + log_forwarder_wake_up_worker(lf);
125 +
126 + spinlock_unlock(&lf->spinlock);
127 +}
128 +
129 +bool log_forwarder_del_and_close_fd(LOG_FORWARDER *lf, int fd) {
130 + if(!lf || !lf->running || fd < 0) return false;
131 +
132 + bool ret = false;
133 +
134 + spinlock_lock(&lf->spinlock);
135 +
136 + LOG_FORWARDER_ENTRY *entry = log_forwarder_find_entry_unsafe(lf, fd);
137 + if(entry) {
138 + entry->delete = true;
139 +
140 + // Send a byte to the pipe to wake up the thread
141 + log_forwarder_wake_up_worker(lf);
142 +
143 + ret = true;
144 + }
145 +
146 + spinlock_unlock(&lf->spinlock);
147 +
148 + return ret;
149 +}
150 +
151 +void log_forwarder_annotate_fd_name(LOG_FORWARDER *lf, int fd, const char *cmd) {
152 + if(!lf || !lf->running || fd < 0 || !cmd || !*cmd) return;
153 +
154 + spinlock_lock(&lf->spinlock);
155 +
156 + LOG_FORWARDER_ENTRY *entry = log_forwarder_find_entry_unsafe(lf, fd);
157 + if (entry) {
158 + freez(entry->cmd);
159 + entry->cmd = strdupz(cmd);
160 + }
161 +
162 + spinlock_unlock(&lf->spinlock);
163 +}
164 +
165 +void log_forwarder_annotate_fd_pid(LOG_FORWARDER *lf, int fd, pid_t pid) {
166 + if(!lf || !lf->running || fd < 0) return;
167 +
168 + spinlock_lock(&lf->spinlock);
169 +
170 + LOG_FORWARDER_ENTRY *entry = log_forwarder_find_entry_unsafe(lf, fd);
171 + if (entry)
172 + entry->pid = pid;
173 +
174 + spinlock_unlock(&lf->spinlock);
175 +}
176 +
177 +// --------------------------------------------------------------------------------------------------------------------
178 +// log forwarder thread
179 +
180 +static inline void log_forwarder_log(LOG_FORWARDER *lf __maybe_unused, LOG_FORWARDER_ENTRY *entry, const char *msg) {
181 + const char *s = msg;
182 + while(*s && isspace((uint8_t)*s)) s++;
183 + if(*s == '\0') return; // do not log empty lines
184 +
185 + ND_LOG_STACK lgs[] = {
186 + ND_LOG_FIELD_TXT(NDF_SYSLOG_IDENTIFIER, entry->cmd ? entry->cmd : "unknown"),
187 + ND_LOG_FIELD_I64(NDF_TID, entry->pid),
188 + ND_LOG_FIELD_END(),
189 + };
190 + ND_LOG_STACK_PUSH(lgs);
191 +
192 + nd_log(NDLS_COLLECTORS, NDLP_WARNING, "STDERR: %s", msg);
193 +}
194 +
195 +// returns the number of entries active
196 +static inline size_t log_forwarder_remove_deleted_unsafe(LOG_FORWARDER *lf) {
197 + size_t entries = 0;
198 +
199 + LOG_FORWARDER_ENTRY *entry = lf->entries;
200 + while(entry) {
201 + LOG_FORWARDER_ENTRY *next = entry->next;
202 +
203 + if(entry->delete) {
204 + if (buffer_strlen(entry->wb))
205 + // there is something not logged in it - log it
206 + log_forwarder_log(lf, entry, buffer_tostring(entry->wb));
207 +
208 + log_forwarder_del_entry_unsafe(lf, entry);
209 + }
210 + else
211 + entries++;
212 +
213 + entry = next;
214 + }
215 +
216 + return entries;
217 +}
218 +
219 +static void *log_forwarder_thread_func(void *arg) {
220 + LOG_FORWARDER *lf = (LOG_FORWARDER *)arg;
221 +
222 + while (1) {
223 + spinlock_lock(&lf->spinlock);
224 + if (!lf->running) {
225 + mark_all_entries_for_deletion_unsafe(lf);
226 + log_forwarder_remove_deleted_unsafe(lf);
227 + spinlock_unlock(&lf->spinlock);
228 + break;
229 + }
230 +
231 + // Count the number of fds
232 + size_t nfds = 1 + log_forwarder_remove_deleted_unsafe(lf);
233 +
234 + struct pollfd pfds[nfds];
235 +
236 + // First, the notification pipe
237 + pfds[0].fd = lf->pipe_fds[PIPE_READ];
238 + pfds[0].events = POLLIN;
239 +
240 + int idx = 1;
241 + for(LOG_FORWARDER_ENTRY *entry = lf->entries; entry ; entry = entry->next, idx++) {
242 + pfds[idx].fd = entry->fd;
243 + pfds[idx].events = POLLIN;
244 + entry->pfds_idx = idx;
245 + }
246 +
247 + spinlock_unlock(&lf->spinlock);
248 +
249 + int timeout = 200; // 200ms
250 + int ret = poll(pfds, nfds, timeout);
251 +
252 + if (ret > 0) {
253 + // Check the notification pipe
254 + if (pfds[0].revents & POLLIN) {
255 + // Read and discard the data
256 + char buf[256];
257 + ssize_t bytes_read = read(lf->pipe_fds[PIPE_READ], buf, sizeof(buf));
258 + // Ignore the data; proceed regardless of the result
259 + if (bytes_read == -1) {
260 + if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) {
261 + // Handle read error if necessary
262 + nd_log(NDLS_COLLECTORS, NDLP_ERR, "Failed to read from notification pipe");
263 + return NULL;
264 + }
265 + }
266 + }
267 +
268 + // Now check the other fds
269 + spinlock_lock(&lf->spinlock);
270 +
271 + size_t to_remove = 0;
272 +
273 + // read or mark them for deletion
274 + for(LOG_FORWARDER_ENTRY *entry = lf->entries; entry ; entry = entry->next) {
275 + if (entry->pfds_idx < 1 || entry->pfds_idx >= nfds || !(pfds[entry->pfds_idx].revents & POLLIN))
276 + continue;
277 +
278 + BUFFER *wb = entry->wb;
279 + buffer_need_bytes(wb, 1024);
280 +
281 + ssize_t bytes_read = read(entry->fd, &wb->buffer[wb->len], wb->size - wb->len - 1);
282 + if(bytes_read > 0)
283 + wb->len += bytes_read;
284 + else if(bytes_read == 0 || (bytes_read == -1 && errno != EINTR && errno != EAGAIN)) {
285 + // EOF or error
286 + entry->delete = true;
287 + to_remove++;
288 + }
289 +
290 + // log as many lines are they have been received
291 + char *start = (char *)buffer_tostring(wb);
292 + char *newline = strchr(start, '\n');
293 + while(newline) {
294 + *newline = '\0';
295 + log_forwarder_log(lf, entry, start);
296 +
297 + start = ++newline;
298 + newline = strchr(newline, '\n');
299 + }
300 +
301 + if(start != wb->buffer) {
302 + wb->len = strlen(start);
303 + if (wb->len)
304 + memmove(wb->buffer, start, wb->len);
305 + }
306 +
307 + entry->pfds_idx = 0;
308 + }
309 +
310 + spinlock_unlock(&lf->spinlock);
311 + }
312 + else if (ret == 0) {
313 + // Timeout, nothing to do
314 + continue;
315 +
316 + }
317 + else
318 + nd_log(NDLS_COLLECTORS, NDLP_ERR, "Log forwarder: poll() error");
319 + }
320 +
321 + return NULL;
322 +}
src/libnetdata/spawn_server/spawn_server_nofork.c
+2 -7
@@ -498,14 +498,10 @@ static bool spawn_server_send_request(ND_UUID *magic, SPAWN_REQUEST *request) {
498 bool ret = false;
499
500 size_t env_size = 0;
501 - void *encoded_env = argv_encode(request->envp, &env_size);
502 - if (!encoded_env)
503 - goto cleanup;
504 -
501 size_t argv_size = 0;
502 +
503 + void *encoded_env = argv_encode(request->envp, &env_size);
504 void *encoded_argv = argv_encode(request->argv, &argv_size);
507 - if (!encoded_argv)
508 - goto cleanup;
505
506 struct msghdr msg = {0};
507 struct cmsghdr *cmsg;
@@ -513,7 +509,6 @@ static bool spawn_server_send_request(ND_UUID *magic, SPAWN_REQUEST *request) {
509 char cmsgbuf[CMSG_SPACE(sizeof(int) * SPAWN_SERVER_TRANSFER_FDS)];
510 struct iovec iov[11];
511
516 -
512 // We send 1 request with 10 iovec in it
513 // The request will be received in 2 parts
514 // 1. the first 6 iovec which include the sizes of the memory allocations required
src/libnetdata/storage_number/storage_number.c
+2 -2
@@ -52,8 +52,8 @@ bool is_system_ieee754_double(void) {
52
53 if(*ptr != tests[i].i && (tests[i].original == tests[i].d || (isnan(tests[i].original) && isnan(tests[i].d)))) {
54 if(!logged)
55 - netdata_log_info("IEEE754: test #%zu, value " NETDATA_DOUBLE_FORMAT_G " is represented in this system as %lX, but it was expected as %lX",
56 - i+1, tests[i].original, *ptr, tests[i].i);
55 + netdata_log_info("IEEE754: test #%zu, value " NETDATA_DOUBLE_FORMAT_G " is represented in this system as %016llX, but it was expected as %016llX",
56 + i+1, tests[i].original, (long long unsigned int)*ptr, (long long unsigned int)tests[i].i);
57 errors++;
58 }
59 }
src/plugins.d/pluginsd_internals.h
+1 -1
@@ -177,7 +177,7 @@ static inline RRDDIM *pluginsd_acquire_dimension(RRDHOST *host, RRDSET *st, cons
177 if(likely(st->pluginsd.dims_with_slots)) {
178 // caching with slots
179
180 - if(unlikely(slot < 1 || slot > st->pluginsd.size)) {
180 + if(unlikely(slot < 1 || slot > (ssize_t)st->pluginsd.size)) {
181 netdata_log_error("PLUGINSD: 'host:%s/chart:%s' got a %s with slot %zd, but slots in the range [1 - %u] are expected.",
182 rrdhost_hostname(host), rrdset_id(st), cmd, slot, st->pluginsd.size);
183 return NULL;
src/streaming/rrdhost-status.h
+1 -1
@@ -84,7 +84,7 @@ ENUM_STR_DEFINE_FUNCTIONS_EXTERN(RRDHOST_DYNCFG_STATUS);
84 #include "stream-capabilities.h"
85 #include "database/rrd.h"
86
87 -typedef struct rrdhost_status {
87 +typedef struct rrdhost_status_t {
88 RRDHOST *host;
89 time_t now;
90
src/streaming/stream-compression/compression.c
+2 -2
@@ -576,8 +576,8 @@ cleanup:
576 fprintf(stderr, "Compression with %s: FAILED (%d errors)\n", name, errors);
577 else
578 fprintf(stderr, "Compression with %s: OK "
579 - "(compression %zu usec, decompression %zu usec, bytes raw %zu, compressed %zu, savings ratio %0.2f%%)\n",
580 - name, compression_ut, decompression_ut,
579 + "(compression %llu usec, decompression %llu usec, bytes raw %zu, compressed %zu, savings ratio %0.2f%%)\n",
580 + name, (long long unsigned)compression_ut, (long long unsigned)decompression_ut,
581 bytes_uncompressed, bytes_compressed,
582 100.0 - (double)bytes_compressed * 100.0 / (double)bytes_uncompressed);
583
src/streaming/stream-parents.h
+2 -2
@@ -6,7 +6,7 @@
6 #include "libnetdata/libnetdata.h"
7
8 struct rrdhost;
9 -struct rrdhost_status;
9 +struct rrdhost_status_t;
10 struct stream_parent;
11 typedef struct stream_parent STREAM_PARENT;
12
@@ -37,7 +37,7 @@ bool stream_parent_connect_to_one(
37 size_t connected_to_size,
38 STREAM_PARENT **destination);
39
40 -void rrdhost_stream_parents_to_json(BUFFER *wb, struct rrdhost_status *s);
40 +void rrdhost_stream_parents_to_json(BUFFER *wb, struct rrdhost_status_t *s);
41 STREAM_HANDSHAKE stream_parent_get_disconnect_reason(STREAM_PARENT *d);
42 void stream_parent_set_disconnect_reason(STREAM_PARENT *d, STREAM_HANDSHAKE reason, time_t since);
43 void stream_parent_set_reconnect_delay(STREAM_PARENT *d, STREAM_HANDSHAKE reason, time_t secs);
src/streaming/stream-thread.c
+2 -2
@@ -271,8 +271,8 @@ static void stream_thread_read_pipe_messages(struct stream_thread *sth) {
271
272 // --------------------------------------------------------------------------------------------------------------------
273
274 -static int set_pipe_size(int pipe_fd, int new_size) {
275 - int default_size = new_size;
274 +static int set_pipe_size(int pipe_fd __maybe_unused, int new_size) {
275 + int default_size = new_size; (void)default_size;
276 int result = new_size;
277
278 #ifdef F_GETPIPE_SZ
src/web/api/v2/api_v2_ilove/ilove.c
+2 -1
@@ -147,7 +147,8 @@ static double ibm_plex_sans_bold_word_width(const char *s, double fontSize) {
147 totalWidth += ibm_plex_sans_bold_250_em_size;
148 }
149 else {
150 - if (*s >= 0 && *s <= 126) // Check if it's a valid ASCII character (including '\0')
150 + uint8_t c = (uint8_t)*s;
151 + if (c <= 126) // Check if it's a valid ASCII character (including '\0')
152 totalWidth += ibm_plex_sans_bold_250[(unsigned char)*s][(unsigned char)s[1]];
153
154 s++;