From 6611f94d3294d86778d813bbfe192e8b08e9b2db Mon Sep 17 00:00:00 2001 From: thiagoftsm Date: Thu, 5 Sep 2024 15:03:34 +0000 Subject: [PATCH] Remove Warnings (ebpf) (#18484) --- src/collectors/ebpf.plugin/ebpf.c | 19 ++++++++++--------- src/collectors/ebpf.plugin/ebpf_apps.c | 11 +++++------ src/collectors/ebpf.plugin/ebpf_apps.h | 2 +- src/collectors/ebpf.plugin/ebpf_cachestat.c | 6 ++---- src/collectors/ebpf.plugin/ebpf_dcstat.c | 6 ++---- src/collectors/ebpf.plugin/ebpf_fd.c | 6 ++---- src/collectors/ebpf.plugin/ebpf_shm.c | 6 ++---- src/collectors/ebpf.plugin/ebpf_swap.c | 6 ++---- 8 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/collectors/ebpf.plugin/ebpf.c b/src/collectors/ebpf.plugin/ebpf.c index 03a51f96acdd05..c3ab357978770e 100644 --- a/src/collectors/ebpf.plugin/ebpf.c +++ b/src/collectors/ebpf.plugin/ebpf.c @@ -1604,7 +1604,7 @@ static void get_ipv6_last_addr(union netdata_ip_t *out, union netdata_ip_t *in, * * @return it returns 0 on success and -1 otherwise. */ -static inline int ebpf_ip2nl(uint8_t *dst, char *ip, int domain, char *source) +static inline int ebpf_ip2nl(uint8_t *dst, const char *ip, int domain, char *source) { if (inet_pton(domain, ip, dst) <= 0) { netdata_log_error("The address specified (%s) is invalid ", source); @@ -1662,14 +1662,14 @@ void ebpf_clean_ip_structure(ebpf_network_viewer_ip_list_t **clean) * @param out a pointer to store the link list * @param ip the value given as parameter */ -static void ebpf_parse_ip_list_unsafe(void **out, char *ip) +static void ebpf_parse_ip_list_unsafe(void **out, const char *ip) { ebpf_network_viewer_ip_list_t **list = (ebpf_network_viewer_ip_list_t **)out; char *ipdup = strdupz(ip); union netdata_ip_t first = { }; union netdata_ip_t last = { }; - char *is_ipv6; + const char *is_ipv6; if (*ip == '*' && *(ip+1) == '\0') { memset(first.addr8, 0, sizeof(first.addr8)); memset(last.addr8, 0xFF, sizeof(last.addr8)); @@ -1680,7 +1680,8 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip) goto storethisip; } - char *end = ip; + char *enddup = strdupz(ip); + char *end = enddup; // Move while I cannot find a separator while (*end && *end != '/' && *end != '-') end++; @@ -1810,7 +1811,7 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip) ebpf_network_viewer_ip_list_t *store; - storethisip: +storethisip: store = callocz(1, sizeof(ebpf_network_viewer_ip_list_t)); store->value = ipdup; store->hash = simple_hash(ipdup); @@ -1821,8 +1822,9 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip) ebpf_fill_ip_list_unsafe(list, store, "socket"); return; - cleanipdup: +cleanipdup: freez(ipdup); + freez(enddup); } /** @@ -2773,7 +2775,7 @@ static inline void ebpf_set_load_mode(netdata_ebpf_load_mode_t load, netdata_ebp * @param str value read from configuration file. * @param origin specify the configuration file loaded */ -static inline void epbf_update_load_mode(char *str, netdata_ebpf_load_mode_t origin) +static inline void epbf_update_load_mode(const char *str, netdata_ebpf_load_mode_t origin) { netdata_ebpf_load_mode_t load = epbf_convert_string_to_load_mode(str); @@ -4074,7 +4076,6 @@ int main(int argc, char **argv) heartbeat_t hb; heartbeat_init(&hb); int update_apps_every = (int) EBPF_CFG_UPDATE_APPS_EVERY_DEFAULT; - uint32_t max_period = EBPF_CLEANUP_FACTOR; int update_apps_list = update_apps_every - 1; int process_maps_per_core = ebpf_modules[EBPF_MODULE_PROCESS_IDX].maps_per_core; //Plugin will be killed when it receives a signal @@ -4097,7 +4098,7 @@ int main(int argc, char **argv) pthread_mutex_lock(&collect_data_mutex); ebpf_parse_proc_files(); if (collect_pids & (1<pid); + snprintfz(filename, FILENAME_MAX, "%s/proc/%u/cmdline", netdata_configured_host_prefix, p->pid); int ret = 0; @@ -490,7 +490,7 @@ static inline int read_proc_pid_stat(ebpf_pid_data_t *p) char *comm = procfile_lineword(ff, 0, 1); int32_t ppid = (int32_t)str2pid_t(procfile_lineword(ff, 0, 3)); - if (p->ppid == ppid && p->target) + if (p->ppid == (uint32_t)ppid && p->target) goto without_cmdline_target; p->ppid = ppid; @@ -546,7 +546,7 @@ static inline int ebpf_collect_data_for_pid(pid_t pid) read_proc_pid_stat(p); // check its parent pid - if (unlikely( p->ppid > pid_max)) { + if (unlikely( p->ppid > (uint32_t)pid_max)) { netdata_log_error("Pid %d (command '%s') states invalid parent pid %u. Using 0.", pid, p->comm, p->ppid); p->ppid = 0; } @@ -906,9 +906,8 @@ void ebpf_process_sum_values_for_pids(ebpf_process_stat_t *process, struct ebpf_ * * @param tbl_pid_stats_fd The mapped file descriptor for the hash table. * @param maps_per_core do I have hash maps per core? - * @param max_period max period to wait before remove from hash table. */ -void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core, uint32_t max_period) +void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core) { if (tbl_pid_stats_fd == -1) return; diff --git a/src/collectors/ebpf.plugin/ebpf_apps.h b/src/collectors/ebpf.plugin/ebpf_apps.h index 98c9995da9c812..5bf8953adb0636 100644 --- a/src/collectors/ebpf.plugin/ebpf_apps.h +++ b/src/collectors/ebpf.plugin/ebpf_apps.h @@ -495,7 +495,7 @@ int ebpf_read_hash_table(void *ep, int fd, uint32_t pid); int get_pid_comm(pid_t pid, size_t n, char *dest); -void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core, uint32_t max_period); +void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core); void ebpf_process_apps_accumulator(ebpf_process_stat_t *out, int maps_per_core); // The default value is at least 32 times smaller than maximum number of PIDs allowed on system, diff --git a/src/collectors/ebpf.plugin/ebpf_cachestat.c b/src/collectors/ebpf.plugin/ebpf_cachestat.c index 742e12a72ba86b..4d845b145036da 100644 --- a/src/collectors/ebpf.plugin/ebpf_cachestat.c +++ b/src/collectors/ebpf.plugin/ebpf_cachestat.c @@ -712,9 +712,8 @@ static inline void cachestat_save_pid_values(netdata_publish_cachestat_t *out, n * Read the apps table and store data inside the structure. * * @param maps_per_core do I need to read all cores? - * @param max_period limit of iterations without updates before remove data from hash table */ -static void ebpf_read_cachestat_apps_table(int maps_per_core, uint32_t max_period) +static void ebpf_read_cachestat_apps_table(int maps_per_core) { netdata_cachestat_pid_t *cv = cachestat_vector; int fd = cachestat_maps[NETDATA_CACHESTAT_PID_STATS].map_fd; @@ -845,7 +844,6 @@ void *ebpf_read_cachestat_thread(void *ptr) int maps_per_core = em->maps_per_core; int update_every = em->update_every; - uint32_t max_period = EBPF_CLEANUP_FACTOR; int counter = update_every - 1; @@ -859,7 +857,7 @@ void *ebpf_read_cachestat_thread(void *ptr) continue; pthread_mutex_lock(&collect_data_mutex); - ebpf_read_cachestat_apps_table(maps_per_core, max_period); + ebpf_read_cachestat_apps_table(maps_per_core); ebpf_resume_apps_data(); pthread_mutex_unlock(&collect_data_mutex); diff --git a/src/collectors/ebpf.plugin/ebpf_dcstat.c b/src/collectors/ebpf.plugin/ebpf_dcstat.c index 26a3e6017d4a8c..97b949ea160ecb 100644 --- a/src/collectors/ebpf.plugin/ebpf_dcstat.c +++ b/src/collectors/ebpf.plugin/ebpf_dcstat.c @@ -538,9 +538,8 @@ static void ebpf_dcstat_apps_accumulator(netdata_dcstat_pid_t *out, int maps_per * Read the apps table and store data inside the structure. * * @param maps_per_core do I need to read all cores? - * @param max_period limit of iterations without updates before remove data from hash table */ -static void ebpf_read_dc_apps_table(int maps_per_core, uint32_t max_period) +static void ebpf_read_dc_apps_table(int maps_per_core) { netdata_dcstat_pid_t *cv = dcstat_vector; int fd = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd; @@ -656,7 +655,6 @@ void *ebpf_read_dcstat_thread(void *ptr) uint32_t lifetime = em->lifetime; uint32_t running_time = 0; usec_t period = update_every * USEC_PER_SEC; - uint32_t max_period = EBPF_CLEANUP_FACTOR; pids_fd[EBPF_PIDS_DCSTAT_IDX] = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd; while (!ebpf_plugin_stop() && running_time < lifetime) { (void)heartbeat_next(&hb, period); @@ -664,7 +662,7 @@ void *ebpf_read_dcstat_thread(void *ptr) continue; pthread_mutex_lock(&collect_data_mutex); - ebpf_read_dc_apps_table(maps_per_core, max_period); + ebpf_read_dc_apps_table(maps_per_core); ebpf_dc_resume_apps_data(); pthread_mutex_unlock(&collect_data_mutex); diff --git a/src/collectors/ebpf.plugin/ebpf_fd.c b/src/collectors/ebpf.plugin/ebpf_fd.c index e5f6891365697d..45ab5a8ad9e2f7 100644 --- a/src/collectors/ebpf.plugin/ebpf_fd.c +++ b/src/collectors/ebpf.plugin/ebpf_fd.c @@ -681,9 +681,8 @@ static void fd_apps_accumulator(netdata_fd_stat_t *out, int maps_per_core) * Read the apps table and store data inside the structure. * * @param maps_per_core do I need to read all cores? - * @param max_period limit of iterations without updates before remove data from hash table */ -static void ebpf_read_fd_apps_table(int maps_per_core, uint32_t max_period) +static void ebpf_read_fd_apps_table(int maps_per_core) { netdata_fd_stat_t *fv = fd_vector; int fd = fd_maps[NETDATA_FD_PID_STATS].map_fd; @@ -797,7 +796,6 @@ void *ebpf_read_fd_thread(void *ptr) uint32_t lifetime = em->lifetime; uint32_t running_time = 0; int period = USEC_PER_SEC; - uint32_t max_period = EBPF_CLEANUP_FACTOR; pids_fd[EBPF_PIDS_FD_IDX] = fd_maps[NETDATA_FD_PID_STATS].map_fd; while (!ebpf_plugin_stop() && running_time < lifetime) { (void)heartbeat_next(&hb, period); @@ -805,7 +803,7 @@ void *ebpf_read_fd_thread(void *ptr) continue; pthread_mutex_lock(&collect_data_mutex); - ebpf_read_fd_apps_table(maps_per_core, max_period); + ebpf_read_fd_apps_table(maps_per_core); ebpf_fd_resume_apps_data(); pthread_mutex_unlock(&collect_data_mutex); diff --git a/src/collectors/ebpf.plugin/ebpf_shm.c b/src/collectors/ebpf.plugin/ebpf_shm.c index d84df704dbf4b5..fdcb5257201f9a 100644 --- a/src/collectors/ebpf.plugin/ebpf_shm.c +++ b/src/collectors/ebpf.plugin/ebpf_shm.c @@ -565,9 +565,8 @@ static void ebpf_update_shm_cgroup() * Read the apps table and store data inside the structure. * * @param maps_per_core do I need to read all cores? - * @param max_period limit of iterations without updates before remove data from hash table */ -static void ebpf_read_shm_apps_table(int maps_per_core, uint32_t max_period) +static void ebpf_read_shm_apps_table(int maps_per_core) { netdata_ebpf_shm_t *cv = shm_vector; int fd = shm_maps[NETDATA_PID_SHM_TABLE].map_fd; @@ -1075,7 +1074,6 @@ void *ebpf_read_shm_thread(void *ptr) uint32_t lifetime = em->lifetime; uint32_t running_time = 0; usec_t period = update_every * USEC_PER_SEC; - uint32_t max_period = EBPF_CLEANUP_FACTOR; pids_fd[EBPF_PIDS_SHM_IDX] = shm_maps[NETDATA_PID_SHM_TABLE].map_fd; while (!ebpf_plugin_stop() && running_time < lifetime) { (void)heartbeat_next(&hb, period); @@ -1083,7 +1081,7 @@ void *ebpf_read_shm_thread(void *ptr) continue; pthread_mutex_lock(&collect_data_mutex); - ebpf_read_shm_apps_table(maps_per_core, max_period); + ebpf_read_shm_apps_table(maps_per_core); ebpf_shm_resume_apps_data(); pthread_mutex_unlock(&collect_data_mutex); diff --git a/src/collectors/ebpf.plugin/ebpf_swap.c b/src/collectors/ebpf.plugin/ebpf_swap.c index a4eb6911681663..fe1d5671c6f5ea 100644 --- a/src/collectors/ebpf.plugin/ebpf_swap.c +++ b/src/collectors/ebpf.plugin/ebpf_swap.c @@ -539,9 +539,8 @@ void ebpf_swap_resume_apps_data() { * Read the apps table and store data inside the structure. * * @param maps_per_core do I need to read all cores? - * @param max_period limit of iterations without updates before remove data from hash table */ -static void ebpf_read_swap_apps_table(int maps_per_core, uint32_t max_period) +static void ebpf_read_swap_apps_table(int maps_per_core) { netdata_ebpf_swap_t *cv = swap_vector; int fd = swap_maps[NETDATA_PID_SWAP_TABLE].map_fd; @@ -609,7 +608,6 @@ void *ebpf_read_swap_thread(void *ptr) uint32_t lifetime = em->lifetime; uint32_t running_time = 0; usec_t period = update_every * USEC_PER_SEC; - uint32_t max_period = EBPF_CLEANUP_FACTOR; pids_fd[EBPF_PIDS_SWAP_IDX] = swap_maps[NETDATA_PID_SWAP_TABLE].map_fd; while (!ebpf_plugin_stop() && running_time < lifetime) { @@ -618,7 +616,7 @@ void *ebpf_read_swap_thread(void *ptr) continue; pthread_mutex_lock(&collect_data_mutex); - ebpf_read_swap_apps_table(maps_per_core, max_period); + ebpf_read_swap_apps_table(maps_per_core); ebpf_swap_resume_apps_data(); pthread_mutex_unlock(&collect_data_mutex);