diff options
author | Stelios Fragkakis <52996999+stelfrag@users.noreply.github.com> | 2023-12-01 15:45:59 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 15:45:59 +0200 |
commit | 096d1b1b2b455375e94738220acb49df847fb269 (patch) | |
tree | 3c3f2f85729cd0b9d14311e7935202fd98458188 | |
parent | 41f39896755e1bb1fd4c009d1bb76c32220134bf (diff) |
Code cleanup (#16448)
* Code cleanup
* More cleanup
* More cleanup
* Use FILENAME_MAX
* query fix
57 files changed, 488 insertions, 483 deletions
diff --git a/collectors/diskspace.plugin/plugin_diskspace.c b/collectors/diskspace.plugin/plugin_diskspace.c index 4a69d18bd8..94257810c3 100644 --- a/collectors/diskspace.plugin/plugin_diskspace.c +++ b/collectors/diskspace.plugin/plugin_diskspace.c @@ -225,7 +225,7 @@ static void calculate_values_and_show_charts( m->st_space = rrdset_find_active_bytype_localhost("disk_space", disk); if(unlikely(!m->st_space || m->st_space->update_every != update_every)) { char title[4096 + 1]; - snprintfz(title, 4096, "Disk Space Usage"); + snprintfz(title, sizeof(title) - 1, "Disk Space Usage"); m->st_space = rrdset_create_localhost( "disk_space" , disk @@ -265,7 +265,7 @@ static void calculate_values_and_show_charts( m->st_inodes = rrdset_find_active_bytype_localhost("disk_inodes", disk); if(unlikely(!m->st_inodes) || m->st_inodes->update_every != update_every) { char title[4096 + 1]; - snprintfz(title, 4096, "Disk Files (inodes) Usage"); + snprintfz(title, sizeof(title) - 1, "Disk Files (inodes) Usage"); m->st_inodes = rrdset_create_localhost( "disk_inodes" , disk diff --git a/collectors/ebpf.plugin/ebpf.c b/collectors/ebpf.plugin/ebpf.c index 4dbff7c705..381bf5718c 100644 --- a/collectors/ebpf.plugin/ebpf.c +++ b/collectors/ebpf.plugin/ebpf.c @@ -3803,7 +3803,7 @@ static void ebpf_create_statistic_charts(int update_every) continue; em->functions.order_thread_chart = j; - snprintfz(name, 255,"%s_%s", NETDATA_EBPF_THREADS, em->info.thread_name); + snprintfz(name, sizeof(name) - 1, "%s_%s", NETDATA_EBPF_THREADS, em->info.thread_name); em->functions.fcnt_thread_chart_name = strdupz(name); ebpf_create_thread_chart(name, "Threads running.", @@ -3816,7 +3816,7 @@ static void ebpf_create_statistic_charts(int update_every) #endif em->functions.order_thread_lifetime = j; - snprintfz(name, 255,"%s_%s", NETDATA_EBPF_LIFE_TIME, em->info.thread_name); + snprintfz(name, sizeof(name) - 1, "%s_%s", NETDATA_EBPF_LIFE_TIME, em->info.thread_name); em->functions.fcnt_thread_lifetime_name = strdupz(name); ebpf_create_thread_chart(name, "Time remaining for thread.", diff --git a/collectors/ebpf.plugin/ebpf_filesystem.c b/collectors/ebpf.plugin/ebpf_filesystem.c index 789587c553..b78e655324 100644 --- a/collectors/ebpf.plugin/ebpf_filesystem.c +++ b/collectors/ebpf.plugin/ebpf_filesystem.c @@ -392,9 +392,9 @@ static void ebpf_create_fs_charts(int update_every) ebpf_filesystem_partitions_t *efp = &localfs[i]; uint32_t flags = efp->flags; if (flags & NETDATA_FILESYSTEM_FLAG_HAS_PARTITION && !(flags & test)) { - snprintfz(title, 255, "%s latency for each read request.", efp->filesystem); - snprintfz(family, 63, "%s_latency", efp->family); - snprintfz(chart_name, 63, "%s_read_latency", efp->filesystem); + snprintfz(title, sizeof(title) - 1, "%s latency for each read request.", efp->filesystem); + snprintfz(family, sizeof(family) - 1, "%s_latency", efp->family); + snprintfz(chart_name, sizeof(chart_name) - 1, "%s_read_latency", efp->filesystem); efp->hread.name = strdupz(chart_name); efp->hread.title = strdupz(title); efp->hread.ctx = NULL; @@ -410,8 +410,8 @@ static void ebpf_create_fs_charts(int update_every) update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM); order++; - snprintfz(title, 255, "%s latency for each write request.", efp->filesystem); - snprintfz(chart_name, 63, "%s_write_latency", efp->filesystem); + snprintfz(title, sizeof(title) - 1, "%s latency for each write request.", efp->filesystem); + snprintfz(chart_name, sizeof(chart_name) - 1, "%s_write_latency", efp->filesystem); efp->hwrite.name = strdupz(chart_name); efp->hwrite.title = strdupz(title); efp->hwrite.ctx = NULL; @@ -425,8 +425,8 @@ static void ebpf_create_fs_charts(int update_every) update_every, NETDATA_EBPF_MODULE_NAME_FILESYSTEM); order++; - snprintfz(title, 255, "%s latency for each open request.", efp->filesystem); - snprintfz(chart_name, 63, "%s_open_latency", efp->filesystem); + snprintfz(title, sizeof(title) - 1, "%s latency for each open request.", efp->filesystem); + snprintfz(chart_name, sizeof(chart_name) - 1, "%s_open_latency", efp->filesystem); efp->hopen.name = strdupz(chart_name); efp->hopen.title = strdupz(title); efp->hopen.ctx = NULL; @@ -441,9 +441,9 @@ static void ebpf_create_fs_charts(int update_every) order++; char *type = (efp->flags & NETDATA_FILESYSTEM_ATTR_CHARTS) ? "attribute" : "sync"; - snprintfz(title, 255, "%s latency for each %s request.", efp->filesystem, type); - snprintfz(chart_name, 63, "%s_%s_latency", efp->filesystem, type); - snprintfz(ctx, 63, "filesystem.%s_latency", type); + snprintfz(title, sizeof(title) - 1, "%s latency for each %s request.", efp->filesystem, type); + snprintfz(chart_name, sizeof(chart_name) - 1, "%s_%s_latency", efp->filesystem, type); + snprintfz(ctx, sizeof(ctx) - 1, "filesystem.%s_latency", type); efp->hadditional.name = strdupz(chart_name); efp->hadditional.title = strdupz(title); efp->hadditional.ctx = strdupz(ctx); diff --git a/collectors/ebpf.plugin/ebpf_functions.c b/collectors/ebpf.plugin/ebpf_functions.c index ebee663950..6a481ad64f 100644 --- a/collectors/ebpf.plugin/ebpf_functions.c +++ b/collectors/ebpf.plugin/ebpf_functions.c @@ -160,7 +160,7 @@ static void ebpf_function_thread_manipulation(const char *transaction, lem = ebpf_functions_select_module(thread_name); if (!lem) { - snprintfz(message, 511, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name); + snprintfz(message, sizeof(message) - 1, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name); ebpf_function_error(transaction, HTTP_RESP_NOT_FOUND, message); return; } @@ -189,7 +189,7 @@ static void ebpf_function_thread_manipulation(const char *transaction, const char *name = &keyword[sizeof(EBPF_THREADS_DISABLE_CATEGORY) - 1]; lem = ebpf_functions_select_module(name); if (!lem) { - snprintfz(message, 511, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name); + snprintfz(message, sizeof(message) - 1, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name); ebpf_function_error(transaction, HTTP_RESP_NOT_FOUND, message); return; } @@ -205,7 +205,7 @@ static void ebpf_function_thread_manipulation(const char *transaction, const char *name = &keyword[sizeof(EBPF_THREADS_SELECT_THREAD) - 1]; lem = ebpf_functions_select_module(name); if (!lem) { - snprintfz(message, 511, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name); + snprintfz(message, sizeof(message) - 1, "%s%s", EBPF_PLUGIN_THREAD_FUNCTION_ERROR_THREAD_NOT_FOUND, name); ebpf_function_error(transaction, HTTP_RESP_NOT_FOUND, message); return; } diff --git a/collectors/freebsd.plugin/freebsd_getmntinfo.c b/collectors/freebsd.plugin/freebsd_getmntinfo.c index 67840cc5f0..d55eb3d4a4 100644 --- a/collectors/freebsd.plugin/freebsd_getmntinfo.c +++ b/collectors/freebsd.plugin/freebsd_getmntinfo.c @@ -216,7 +216,7 @@ int do_getmntinfo(int update_every, usec_t dt) { (mntbuf[i].f_blocks > 2 || netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { if (unlikely(!m->st_space)) { - snprintfz(title, 4096, "Disk Space Usage for %s [%s]", + snprintfz(title, sizeof(title) - 1, "Disk Space Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname); m->st_space = rrdset_create_localhost("disk_space", mntbuf[i].f_mntonname, @@ -254,7 +254,7 @@ int do_getmntinfo(int update_every, usec_t dt) { (mntbuf[i].f_files > 1 || netdata_zero_metrics_enabled == CONFIG_BOOLEAN_YES))) { if (unlikely(!m->st_inodes)) { - snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]", + snprintfz(title, sizeof(title) - 1, "Disk Files (inodes) Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname); m->st_inodes = rrdset_create_localhost("disk_inodes", mntbuf[i].f_mntonname, diff --git a/collectors/macos.plugin/macos_fw.c b/collectors/macos.plugin/macos_fw.c index ca06f428e1..75ef386b9a 100644 --- a/collectors/macos.plugin/macos_fw.c +++ b/collectors/macos.plugin/macos_fw.c @@ -435,7 +435,7 @@ int do_macos_iokit(int update_every, usec_t dt) { if (likely(do_space)) { st = rrdset_find_active_bytype_localhost("disk_space", mntbuf[i].f_mntonname); if (unlikely(!st)) { - snprintfz(title, 4096, "Disk Space Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname); + snprintfz(title, sizeof(title) - 1, "Disk Space Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname); st = rrdset_create_localhost( "disk_space" , mntbuf[i].f_mntonname @@ -467,7 +467,7 @@ int do_macos_iokit(int update_every, usec_t dt) { if (likely(do_inodes)) { st = rrdset_find_active_bytype_localhost("disk_inodes", mntbuf[i].f_mntonname); if (unlikely(!st)) { - snprintfz(title, 4096, "Disk Files (inodes) Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname); + snprintfz(title, sizeof(title) - 1, "Disk Files (inodes) Usage for %s [%s]", mntbuf[i].f_mntonname, mntbuf[i].f_mntfromname); st = rrdset_create_localhost( "disk_inodes" , mntbuf[i].f_mntonname diff --git a/collectors/plugins.d/pluginsd_parser.c b/collectors/plugins.d/pluginsd_parser.c index 6e40850ea3..3b47c6c0fe 100644 --- a/collectors/plugins.d/pluginsd_parser.c +++ b/collectors/plugins.d/pluginsd_parser.c @@ -929,7 +929,7 @@ static void inflight_functions_insert_callback(const DICTIONARY_ITEM *item, void const char *transaction = dictionary_acquired_item_name(item); char buffer[2048 + 1]; - snprintfz(buffer, 2048, "%s %s %d \"%s\"\n", + snprintfz(buffer, sizeof(buffer) - 1, "%s %s %d \"%s\"\n", pf->payload ? "FUNCTION_PAYLOAD" : "FUNCTION", transaction, pf->timeout, @@ -1102,7 +1102,7 @@ void pluginsd_function_cancel(void *data) { internal_error(true, "PLUGINSD: sending function cancellation to plugin for transaction '%s'", transaction); char buffer[2048 + 1]; - snprintfz(buffer, 2048, "%s %s\n", + snprintfz(buffer, sizeof(buffer) - 1, "%s %s\n", PLUGINSD_KEYWORD_FUNCTION_CANCEL, transaction); diff --git a/collectors/proc.plugin/proc_diskstats.c b/collectors/proc.plugin/proc_diskstats.c index 706518cbe9..0e7ee3fa1a 100644 --- a/collectors/proc.plugin/proc_diskstats.c +++ b/collectors/proc.plugin/proc_diskstats.c @@ -500,7 +500,7 @@ static inline bool ends_with(const char *str, const char *suffix) { static inline char *get_disk_by_id(char *device) { char pathname[256 + 1]; - snprintfz(pathname, 256, "%s/by-id", path_to_dev_disk); + snprintfz(pathname, sizeof(pathname) - 1, "%s/by-id", path_to_dev_disk); struct dirent *entry; DIR *dp = opendir(pathname); @@ -546,9 +546,9 @@ static inline char *get_disk_model(char *device) { char path[256 + 1]; char buffer[256 + 1]; - snprintfz(path, 256, "%s/%s/device/model", path_to_sys_block, device); + snprintfz(path, sizeof(path) - 1, "%s/%s/device/model", path_to_sys_block, device); if(read_file(path, buffer, 256) != 0) { - snprintfz(path, 256, "%s/%s/device/name", path_to_sys_block, device); + snprintfz(path, sizeof(path) - 1, "%s/%s/device/name", path_to_sys_block, device); if(read_file(path, buffer, 256) != 0) return NULL; } @@ -564,7 +564,7 @@ static inline char *get_disk_serial(char *device) { char path[256 + 1]; char buffer[256 + 1]; - snprintfz(path, 256, "%s/%s/device/serial", path_to_sys_block, device); + snprintfz(path, sizeof(path) - 1, "%s/%s/device/serial", path_to_sys_block, device); if(read_file(path, buffer, 256) != 0) return NULL; diff --git a/collectors/proc.plugin/proc_interrupts.c b/collectors/proc.plugin/proc_interrupts.c index 9a20700a3d..37071b22f8 100644 --- a/collectors/proc.plugin/proc_interrupts.c +++ b/collectors/proc.plugin/proc_interrupts.c @@ -201,10 +201,10 @@ int do_proc_interrupts(int update_every, usec_t dt) { for(c = 0; c < cpus ;c++) { if(unlikely(!core_st[c])) { char id[50+1]; - snprintfz(id, 50, "cpu%d_interrupts", c); + snprintfz(id, sizeof(id) - 1, "cpu%d_interrupts", c); char title[100+1]; - snprintfz(title, 100, "CPU Interrupts"); + snprintfz(title, sizeof(title) - 1, "CPU Interrupts"); core_st[c] = rrdset_create_localhost( "cpu" , id @@ -221,7 +221,7 @@ int do_proc_interrupts(int update_every, usec_t dt) { ); char core[50+1]; - snprintfz(core, 50, "cpu%d", c); + snprintfz(core, sizeof(core) - 1, "cpu%d", c); rrdlabels_add(core_st[c]->rrdlabels, "cpu", core, RRDLABEL_SRC_AUTO); } diff --git a/collectors/proc.plugin/proc_mdstat.c b/collectors/proc.plugin/proc_mdstat.c index 97129d15de..3857d9ec4f 100644 --- a/collectors/proc.plugin/proc_mdstat.c +++ b/collectors/proc.plugin/proc_mdstat.c @@ -70,7 +70,7 @@ static inline void make_chart_obsolete(char *name, const char *id_modifier) RRDSET *st = NULL; if (likely(name && id_modifier)) { - snprintfz(id, 50, "mdstat.%s_%s", name, id_modifier); + snprintfz(id, sizeof(id) - 1, "mdstat.%s_%s", name, id_modifier); st = rrdset_find_active_byname_localhost(id); if (likely(st)) rrdset_is_obsolete___safe_from_collector_thread(st); @@ -438,10 +438,10 @@ int do_proc_mdstat(int update_every, usec_t dt) if (likely(raid->redundant)) { if (likely(do_disks)) { - snprintfz(id, 50, "%s_disks", raid->name); + snprintfz(id, sizeof(id) - 1, "%s_disks", raid->name); if (unlikely(!raid->st_disks && !(raid->st_disks = rrdset_find_active_byname_localhost(id)))) { - snprintfz(family, 50, "%s (%s)", raid->name, raid->level); + snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level); raid->st_disks = rrdset_create_localhost( "mdstat", @@ -473,10 +473,10 @@ int do_proc_mdstat(int update_every, usec_t dt) } if (likely(do_mismatch)) { - snprintfz(id, 50, "%s_mismatch", raid->name); + snprintfz(id, sizeof(id) - 1, "%s_mismatch", raid->name); if (unlikely(!raid->st_mismatch_cnt && !(raid->st_mismatch_cnt = rrdset_find_active_byname_localhost(id)))) { - snprintfz(family, 50, "%s (%s)", raid->name, raid->level); + snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level); raid->st_mismatch_cnt = rrdset_create_localhost( "mdstat", @@ -505,10 +505,10 @@ int do_proc_mdstat(int update_every, usec_t dt) } if (likely(do_operations)) { - snprintfz(id, 50, "%s_operation", raid->name); + snprintfz(id, sizeof(id) - 1, "%s_operation", raid->name); if (unlikely(!raid->st_operation && !(raid->st_operation = rrdset_find_active_byname_localhost(id)))) { - snprintfz(family, 50, "%s (%s)", raid->name, raid->level); + snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level); raid->st_operation = rrdset_create_localhost( "mdstat", @@ -544,9 +544,9 @@ int do_proc_mdstat(int update_every, usec_t dt) rrddim_set_by_pointer(raid->st_operation, raid->rd_reshape, raid->reshape); rrdset_done(raid->st_operation); - snprintfz(id, 50, "%s_finish", raid->name); + snprintfz(id, sizeof(id) - 1, "%s_finish", raid->name); if (unlikely(!raid->st_finish && !(raid->st_finish = rrdset_find_active_byname_localhost(id)))) { - snprintfz(family, 50, "%s (%s)", raid->name, raid->level); + snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level); raid->st_finish = rrdset_create_localhost( "mdstat", @@ -572,9 +572,9 @@ int do_proc_mdstat(int update_every, usec_t dt) rrddim_set_by_pointer(raid->st_finish, raid->rd_finish_in, raid->finish_in); rrdset_done(raid->st_finish); - snprintfz(id, 50, "%s_speed", raid->name); + snprintfz(id, sizeof(id) - 1, "%s_speed", raid->name); if (unlikely(!raid->st_speed && !(raid->st_speed = rrdset_find_active_byname_localhost(id)))) { - snprintfz(family, 50, "%s (%s)", raid->name, raid->level); + snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level); raid->st_speed = rrdset_create_localhost( "mdstat", @@ -603,10 +603,10 @@ int do_proc_mdstat(int update_every, usec_t dt) } } else { if (likely(do_nonredundant)) { - snprintfz(id, 50, "%s_availability", raid->name); + snprintfz(id, sizeof(id) - 1, "%s_availability", raid->name); if (unlikely(!raid->st_nonredundant && !(raid->st_nonredundant = rrdset_find_active_localhost(id)))) { - snprintfz(family, 50, "%s (%s)", raid->name, raid->level); + snprintfz(family, sizeof(family) - 1, "%s (%s)", raid->name, raid->level); raid->st_nonredundant = rrdset_create_localhost( "mdstat", diff --git a/collectors/proc.plugin/proc_net_softnet_stat.c b/collectors/proc.plugin/proc_net_softnet_stat.c index dfd372b2a9..2f01b88598 100644 --- a/collectors/proc.plugin/proc_net_softnet_stat.c +++ b/collectors/proc.plugin/proc_net_softnet_stat.c @@ -111,12 +111,12 @@ int do_proc_net_softnet_stat(int update_every, usec_t dt) { if(do_per_core) { for(l = 0; l < lines ;l++) { char id[50+1]; - snprintfz(id, 50, "cpu%zu_softnet_stat", l); + snprintfz(id, sizeof(id) - 1,"cpu%zu_softnet_stat", l); st = rrdset_find_active_bytype_localhost("cpu", id); if(unlikely(!st)) { char title[100+1]; - snprintfz(title, 100, "CPU softnet_stat"); + snprintfz(title, sizeof(title) - 1, "CPU softnet_stat"); st = rrdset_create_localhost( "cpu" diff --git a/collectors/proc.plugin/proc_pagetypeinfo.c b/collectors/proc.plugin/proc_pagetypeinfo.c index e5318ce8fb..fc5496c630 100644 --- a/collectors/proc.plugin/proc_pagetypeinfo.c +++ b/collectors/proc.pl |