@cryptotaxi247 / netdata-1 / commits / 6611f94d3

Remove Warnings (ebpf) (#18484)

thiagoftsm committed Sep 5, 2024 at 15:03 UTC 6611f94d3294d86778d813bbfe192e8b08e9b2db
8 files changed +26 -36
src/collectors/ebpf.plugin/ebpf.c
+10 -9
@@ -1604,7 +1604,7 @@ static void get_ipv6_last_addr(union netdata_ip_t *out, union netdata_ip_t *in,
1604 *
1605 * @return it returns 0 on success and -1 otherwise.
1606 */
1607 -static inline int ebpf_ip2nl(uint8_t *dst, char *ip, int domain, char *source)
1607 +static inline int ebpf_ip2nl(uint8_t *dst, const char *ip, int domain, char *source)
1608 {
1609 if (inet_pton(domain, ip, dst) <= 0) {
1610 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)
1662 * @param out a pointer to store the link list
1663 * @param ip the value given as parameter
1664 */
1665 -static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
1665 +static void ebpf_parse_ip_list_unsafe(void **out, const char *ip)
1666 {
1667 ebpf_network_viewer_ip_list_t **list = (ebpf_network_viewer_ip_list_t **)out;
1668
1669 char *ipdup = strdupz(ip);
1670 union netdata_ip_t first = { };
1671 union netdata_ip_t last = { };
1672 - char *is_ipv6;
1672 + const char *is_ipv6;
1673 if (*ip == '*' && *(ip+1) == '\0') {
1674 memset(first.addr8, 0, sizeof(first.addr8));
1675 memset(last.addr8, 0xFF, sizeof(last.addr8));
@@ -1680,7 +1680,8 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
1680 goto storethisip;
1681 }
1682
1683 - char *end = ip;
1683 + char *enddup = strdupz(ip);
1684 + char *end = enddup;
1685 // Move while I cannot find a separator
1686 while (*end && *end != '/' && *end != '-') end++;
1687
@@ -1810,7 +1811,7 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
1811
1812 ebpf_network_viewer_ip_list_t *store;
1813
1813 - storethisip:
1814 +storethisip:
1815 store = callocz(1, sizeof(ebpf_network_viewer_ip_list_t));
1816 store->value = ipdup;
1817 store->hash = simple_hash(ipdup);
@@ -1821,8 +1822,9 @@ static void ebpf_parse_ip_list_unsafe(void **out, char *ip)
1822 ebpf_fill_ip_list_unsafe(list, store, "socket");
1823 return;
1824
1824 - cleanipdup:
1825 +cleanipdup:
1826 freez(ipdup);
1827 + freez(enddup);
1828 }
1829
1830 /**
@@ -2773,7 +2775,7 @@ static inline void ebpf_set_load_mode(netdata_ebpf_load_mode_t load, netdata_ebp
2775 * @param str value read from configuration file.
2776 * @param origin specify the configuration file loaded
2777 */
2776 -static inline void epbf_update_load_mode(char *str, netdata_ebpf_load_mode_t origin)
2778 +static inline void epbf_update_load_mode(const char *str, netdata_ebpf_load_mode_t origin)
2779 {
2780 netdata_ebpf_load_mode_t load = epbf_convert_string_to_load_mode(str);
2781
@@ -4074,7 +4076,6 @@ int main(int argc, char **argv)
4076 heartbeat_t hb;
4077 heartbeat_init(&hb);
4078 int update_apps_every = (int) EBPF_CFG_UPDATE_APPS_EVERY_DEFAULT;
4077 - uint32_t max_period = EBPF_CLEANUP_FACTOR;
4079 int update_apps_list = update_apps_every - 1;
4080 int process_maps_per_core = ebpf_modules[EBPF_MODULE_PROCESS_IDX].maps_per_core;
4081 //Plugin will be killed when it receives a signal
@@ -4097,7 +4098,7 @@ int main(int argc, char **argv)
4098 pthread_mutex_lock(&collect_data_mutex);
4099 ebpf_parse_proc_files();
4100 if (collect_pids & (1<<EBPF_MODULE_PROCESS_IDX)) {
4100 - collect_data_for_all_processes(process_pid_fd, process_maps_per_core, max_period);
4101 + collect_data_for_all_processes(process_pid_fd, process_maps_per_core);
4102 }
4103
4104 ebpf_create_apps_charts(apps_groups_root_target);
src/collectors/ebpf.plugin/ebpf_apps.c
+5 -6
@@ -327,7 +327,7 @@ int pids_fd[EBPF_PIDS_END_IDX];
327
328 static size_t
329 // global_iterations_counter = 1,
330 - calls_counter = 0,
330 + //calls_counter = 0,
331 // file_counter = 0,
332 // filenames_allocated_counter = 0,
333 // inodes_changed_counter = 0,
@@ -426,7 +426,7 @@ static inline void assign_target_to_pid(ebpf_pid_data_t *p)
426 static inline int read_proc_pid_cmdline(ebpf_pid_data_t *p, char *cmdline)
427 {
428 char filename[FILENAME_MAX + 1];
429 - snprintfz(filename, FILENAME_MAX, "%s/proc/%d/cmdline", netdata_configured_host_prefix, p->pid);
429 + snprintfz(filename, FILENAME_MAX, "%s/proc/%u/cmdline", netdata_configured_host_prefix, p->pid);
430
431 int ret = 0;
432
@@ -490,7 +490,7 @@ static inline int read_proc_pid_stat(ebpf_pid_data_t *p)
490 char *comm = procfile_lineword(ff, 0, 1);
491 int32_t ppid = (int32_t)str2pid_t(procfile_lineword(ff, 0, 3));
492
493 - if (p->ppid == ppid && p->target)
493 + if (p->ppid == (uint32_t)ppid && p->target)
494 goto without_cmdline_target;
495
496 p->ppid = ppid;
@@ -546,7 +546,7 @@ static inline int ebpf_collect_data_for_pid(pid_t pid)
546 read_proc_pid_stat(p);
547
548 // check its parent pid
549 - if (unlikely( p->ppid > pid_max)) {
549 + if (unlikely( p->ppid > (uint32_t)pid_max)) {
550 netdata_log_error("Pid %d (command '%s') states invalid parent pid %u. Using 0.", pid, p->comm, p->ppid);
551 p->ppid = 0;
552 }
@@ -906,9 +906,8 @@ void ebpf_process_sum_values_for_pids(ebpf_process_stat_t *process, struct ebpf_
906 *
907 * @param tbl_pid_stats_fd The mapped file descriptor for the hash table.
908 * @param maps_per_core do I have hash maps per core?
909 - * @param max_period max period to wait before remove from hash table.
909 */
911 -void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core, uint32_t max_period)
910 +void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core)
911 {
912 if (tbl_pid_stats_fd == -1)
913 return;
src/collectors/ebpf.plugin/ebpf_apps.h
+1 -1
@@ -495,7 +495,7 @@ int ebpf_read_hash_table(void *ep, int fd, uint32_t pid);
495
496 int get_pid_comm(pid_t pid, size_t n, char *dest);
497
498 -void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core, uint32_t max_period);
498 +void collect_data_for_all_processes(int tbl_pid_stats_fd, int maps_per_core);
499 void ebpf_process_apps_accumulator(ebpf_process_stat_t *out, int maps_per_core);
500
501 // The default value is at least 32 times smaller than maximum number of PIDs allowed on system,
src/collectors/ebpf.plugin/ebpf_cachestat.c
+2 -4
@@ -712,9 +712,8 @@ static inline void cachestat_save_pid_values(netdata_publish_cachestat_t *out, n
712 * Read the apps table and store data inside the structure.
713 *
714 * @param maps_per_core do I need to read all cores?
715 - * @param max_period limit of iterations without updates before remove data from hash table
715 */
717 -static void ebpf_read_cachestat_apps_table(int maps_per_core, uint32_t max_period)
716 +static void ebpf_read_cachestat_apps_table(int maps_per_core)
717 {
718 netdata_cachestat_pid_t *cv = cachestat_vector;
719 int fd = cachestat_maps[NETDATA_CACHESTAT_PID_STATS].map_fd;
@@ -845,7 +844,6 @@ void *ebpf_read_cachestat_thread(void *ptr)
844
845 int maps_per_core = em->maps_per_core;
846 int update_every = em->update_every;
848 - uint32_t max_period = EBPF_CLEANUP_FACTOR;
847
848 int counter = update_every - 1;
849
@@ -859,7 +857,7 @@ void *ebpf_read_cachestat_thread(void *ptr)
857 continue;
858
859 pthread_mutex_lock(&collect_data_mutex);
862 - ebpf_read_cachestat_apps_table(maps_per_core, max_period);
860 + ebpf_read_cachestat_apps_table(maps_per_core);
861 ebpf_resume_apps_data();
862 pthread_mutex_unlock(&collect_data_mutex);
863
src/collectors/ebpf.plugin/ebpf_dcstat.c
+2 -4
@@ -538,9 +538,8 @@ static void ebpf_dcstat_apps_accumulator(netdata_dcstat_pid_t *out, int maps_per
538 * Read the apps table and store data inside the structure.
539 *
540 * @param maps_per_core do I need to read all cores?
541 - * @param max_period limit of iterations without updates before remove data from hash table
541 */
543 -static void ebpf_read_dc_apps_table(int maps_per_core, uint32_t max_period)
542 +static void ebpf_read_dc_apps_table(int maps_per_core)
543 {
544 netdata_dcstat_pid_t *cv = dcstat_vector;
545 int fd = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd;
@@ -656,7 +655,6 @@ void *ebpf_read_dcstat_thread(void *ptr)
655 uint32_t lifetime = em->lifetime;
656 uint32_t running_time = 0;
657 usec_t period = update_every * USEC_PER_SEC;
659 - uint32_t max_period = EBPF_CLEANUP_FACTOR;
658 pids_fd[EBPF_PIDS_DCSTAT_IDX] = dcstat_maps[NETDATA_DCSTAT_PID_STATS].map_fd;
659 while (!ebpf_plugin_stop() && running_time < lifetime) {
660 (void)heartbeat_next(&hb, period);
@@ -664,7 +662,7 @@ void *ebpf_read_dcstat_thread(void *ptr)
662 continue;
663
664 pthread_mutex_lock(&collect_data_mutex);
667 - ebpf_read_dc_apps_table(maps_per_core, max_period);
665 + ebpf_read_dc_apps_table(maps_per_core);
666 ebpf_dc_resume_apps_data();
667 pthread_mutex_unlock(&collect_data_mutex);
668
src/collectors/ebpf.plugin/ebpf_fd.c
+2 -4
@@ -681,9 +681,8 @@ static void fd_apps_accumulator(netdata_fd_stat_t *out, int maps_per_core)
681 * Read the apps table and store data inside the structure.
682 *
683 * @param maps_per_core do I need to read all cores?
684 - * @param max_period limit of iterations without updates before remove data from hash table
684 */
686 -static void ebpf_read_fd_apps_table(int maps_per_core, uint32_t max_period)
685 +static void ebpf_read_fd_apps_table(int maps_per_core)
686 {
687 netdata_fd_stat_t *fv = fd_vector;
688 int fd = fd_maps[NETDATA_FD_PID_STATS].map_fd;
@@ -797,7 +796,6 @@ void *ebpf_read_fd_thread(void *ptr)
796 uint32_t lifetime = em->lifetime;
797 uint32_t running_time = 0;
798 int period = USEC_PER_SEC;
800 - uint32_t max_period = EBPF_CLEANUP_FACTOR;
799 pids_fd[EBPF_PIDS_FD_IDX] = fd_maps[NETDATA_FD_PID_STATS].map_fd;
800 while (!ebpf_plugin_stop() && running_time < lifetime) {
801 (void)heartbeat_next(&hb, period);
@@ -805,7 +803,7 @@ void *ebpf_read_fd_thread(void *ptr)
803 continue;
804
805 pthread_mutex_lock(&collect_data_mutex);
808 - ebpf_read_fd_apps_table(maps_per_core, max_period);
806 + ebpf_read_fd_apps_table(maps_per_core);
807 ebpf_fd_resume_apps_data();
808 pthread_mutex_unlock(&collect_data_mutex);
809
src/collectors/ebpf.plugin/ebpf_shm.c
+2 -4
@@ -565,9 +565,8 @@ static void ebpf_update_shm_cgroup()
565 * Read the apps table and store data inside the structure.
566 *
567 * @param maps_per_core do I need to read all cores?
568 - * @param max_period limit of iterations without updates before remove data from hash table
568 */
570 -static void ebpf_read_shm_apps_table(int maps_per_core, uint32_t max_period)
569 +static void ebpf_read_shm_apps_table(int maps_per_core)
570 {
571 netdata_ebpf_shm_t *cv = shm_vector;
572 int fd = shm_maps[NETDATA_PID_SHM_TABLE].map_fd;
@@ -1075,7 +1074,6 @@ void *ebpf_read_shm_thread(void *ptr)
1074 uint32_t lifetime = em->lifetime;
1075 uint32_t running_time = 0;
1076 usec_t period = update_every * USEC_PER_SEC;
1078 - uint32_t max_period = EBPF_CLEANUP_FACTOR;
1077 pids_fd[EBPF_PIDS_SHM_IDX] = shm_maps[NETDATA_PID_SHM_TABLE].map_fd;
1078 while (!ebpf_plugin_stop() && running_time < lifetime) {
1079 (void)heartbeat_next(&hb, period);
@@ -1083,7 +1081,7 @@ void *ebpf_read_shm_thread(void *ptr)
1081 continue;
1082
1083 pthread_mutex_lock(&collect_data_mutex);
1086 - ebpf_read_shm_apps_table(maps_per_core, max_period);
1084 + ebpf_read_shm_apps_table(maps_per_core);
1085 ebpf_shm_resume_apps_data();
1086 pthread_mutex_unlock(&collect_data_mutex);
1087
src/collectors/ebpf.plugin/ebpf_swap.c
+2 -4
@@ -539,9 +539,8 @@ void ebpf_swap_resume_apps_data() {
539 * Read the apps table and store data inside the structure.
540 *
541 * @param maps_per_core do I need to read all cores?
542 - * @param max_period limit of iterations without updates before remove data from hash table
542 */
544 -static void ebpf_read_swap_apps_table(int maps_per_core, uint32_t max_period)
543 +static void ebpf_read_swap_apps_table(int maps_per_core)
544 {
545 netdata_ebpf_swap_t *cv = swap_vector;
546 int fd = swap_maps[NETDATA_PID_SWAP_TABLE].map_fd;
@@ -609,7 +608,6 @@ void *ebpf_read_swap_thread(void *ptr)
608 uint32_t lifetime = em->lifetime;
609 uint32_t running_time = 0;
610 usec_t period = update_every * USEC_PER_SEC;
612 - uint32_t max_period = EBPF_CLEANUP_FACTOR;
611 pids_fd[EBPF_PIDS_SWAP_IDX] = swap_maps[NETDATA_PID_SWAP_TABLE].map_fd;
612
613 while (!ebpf_plugin_stop() && running_time < lifetime) {
@@ -618,7 +616,7 @@ void *ebpf_read_swap_thread(void *ptr)
616 continue;
617
618 pthread_mutex_lock(&collect_data_mutex);
621 - ebpf_read_swap_apps_table(maps_per_core, max_period);
619 + ebpf_read_swap_apps_table(maps_per_core);
620 ebpf_swap_resume_apps_data();
621 pthread_mutex_unlock(&collect_data_mutex);
622