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 /daemon | |
parent | 41f39896755e1bb1fd4c009d1bb76c32220134bf (diff) |
Code cleanup (#16448)
* Code cleanup
* More cleanup
* More cleanup
* Use FILENAME_MAX
* query fix
Diffstat (limited to 'daemon')
-rw-r--r-- | daemon/analytics.c | 46 | ||||
-rw-r--r-- | daemon/daemon.c | 4 | ||||
-rw-r--r-- | daemon/global_statistics.c | 2 | ||||
-rw-r--r-- | daemon/main.c | 2 | ||||
-rw-r--r-- | daemon/signals.c | 2 | ||||
-rw-r--r-- | daemon/unit_test.c | 14 |
6 files changed, 35 insertions, 35 deletions
diff --git a/daemon/analytics.c b/daemon/analytics.c index 4226b14655..9f19e313bb 100644 --- a/daemon/analytics.c +++ b/daemon/analytics.c @@ -149,7 +149,7 @@ void analytics_log_prometheus(void) if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.prometheus_hits < ANALYTICS_MAX_PROMETHEUS_HITS)) { analytics_data.prometheus_hits++; char b[21]; - snprintfz(b, 20, "%zu", analytics_data.prometheus_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.prometheus_hits); analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b); } } @@ -162,7 +162,7 @@ void analytics_log_shell(void) if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.shell_hits < ANALYTICS_MAX_SHELL_HITS)) { analytics_data.shell_hits++; char b[21]; - snprintfz(b, 20, "%zu", analytics_data.shell_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.shell_hits); analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b); } } @@ -175,7 +175,7 @@ void analytics_log_json(void) if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.json_hits < ANALYTICS_MAX_JSON_HITS)) { analytics_data.json_hits++; char b[21]; - snprintfz(b, 20, "%zu", analytics_data.json_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.json_hits); analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b); } } @@ -188,7 +188,7 @@ void analytics_log_dashboard(void) if (netdata_anonymous_statistics_enabled == 1 && likely(analytics_data.dashboard_hits < ANALYTICS_MAX_DASHBOARD_HITS)) { analytics_data.dashboard_hits++; char b[21]; - snprintfz(b, 20, "%zu", analytics_data.dashboard_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.dashboard_hits); analytics_set_data(&analytics_data.netdata_dashboard_used, b); } } @@ -198,7 +198,7 @@ void analytics_log_dashboard(void) */ void analytics_report_oom_score(long long int score){ char b[21]; - snprintfz(b, 20, "%lld", score); + snprintfz(b, sizeof(b) - 1, "%lld", score); analytics_set_data(&analytics_data.netdata_config_oom_score, b); } @@ -222,11 +222,11 @@ void analytics_mirrored_hosts(void) } rrd_unlock(); - snprintfz(b, 20, "%zu", count); + snprintfz(b, sizeof(b) - 1, "%zu", count); analytics_set_data(&analytics_data.netdata_mirrored_host_count, b); - snprintfz(b, 20, "%zu", reachable); + snprintfz(b, sizeof(b) - 1, "%zu", reachable); analytics_set_data(&analytics_data.netdata_mirrored_hosts_reachable, b); - snprintfz(b, 20, "%zu", unreachable); + snprintfz(b, sizeof(b) - 1, "%zu", unreachable); analytics_set_data(&analytics_data.netdata_mirrored_hosts_unreachable, b); } @@ -281,7 +281,7 @@ void analytics_collectors(void) .plugin = rrdset_plugin_name(st), .module = rrdset_module_name(st) }; - snprintfz(name, 499, "%s:%s", col.plugin, col.module); + snprintfz(name, sizeof(name) - 1, "%s:%s", col.plugin, col.module); dictionary_set(dict, name, &col, sizeof(struct collector)); } rrdset_foreach_done(st); @@ -297,7 +297,7 @@ void analytics_collectors(void) { char b[21]; - snprintfz(b, 20, "%d", ap.c); + snprintfz(b, sizeof(b) - 1, "%d", ap.c); analytics_set_data(&analytics_data.netdata_collectors_count, b); } @@ -402,7 +402,7 @@ void analytics_charts(void) analytics_data.charts_count = c; { char b[21]; - snprintfz(b, 20, "%zu", c); + snprintfz(b, sizeof(b) - 1, "%zu", c); analytics_set_data(&analytics_data.netdata_charts_count, b); } } @@ -427,7 +427,7 @@ void analytics_metrics(void) analytics_data.metrics_count = dimensions; { char b[21]; - snprintfz(b, 20, "%zu", dimensions); + snprintfz(b, sizeof(b) - 1, "%zu", dimensions); analytics_set_data(&analytics_data.netdata_metrics_count, b); } } @@ -454,11 +454,11 @@ void analytics_alarms(void) } foreach_rrdcalc_in_rrdhost_done(rc); - snprintfz(b, 20, "%zu", alarm_normal); + snprintfz(b, sizeof(b) - 1, "%zu", alarm_normal); analytics_set_data(&analytics_data.netdata_alarms_normal, b); - snprintfz(b, 20, "%zu", alarm_warn); + snprintfz(b, sizeof(b) - 1, "%zu", alarm_warn); analytics_set_data(&analytics_data.netdata_alarms_warning, b); - snprintfz(b, 20, "%zu", alarm_crit); + snprintfz(b, sizeof(b) - 1, "%zu", alarm_crit); analytics_set_data(&analytics_data.netdata_alarms_critical, b); } @@ -540,19 +540,19 @@ void analytics_gather_mutable_meta_data(void) { char b[21]; - snprintfz(b, 20, "%zu", analytics_data.prometheus_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.prometheus_hits); analytics_set_data(&analytics_data.netdata_allmetrics_prometheus_used, b); - snprintfz(b, 20, "%zu", analytics_data.shell_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.shell_hits); analytics_set_data(&analytics_data.netdata_allmetrics_shell_used, b); - snprintfz(b, 20, "%zu", analytics_data.json_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.json_hits); analytics_set_data(&analytics_data.netdata_allmetrics_json_used, b); - snprintfz(b, 20, "%zu", analytics_data.dashboard_hits); + snprintfz(b, sizeof(b) - 1, "%zu", analytics_data.dashboard_hits); analytics_set_data(&analytics_data.netdata_dashboard_used, b); - snprintfz(b, 20, "%zu", rrdhost_hosts_available()); + snprintfz(b, sizeof(b) - 1, "%zu", rrdhost_hosts_available()); analytics_set_data(&analytics_data.netdata_config_hosts_available, b); } } @@ -664,10 +664,10 @@ void set_late_global_environment(struct rrdhost_system_info *system_info) #ifdef ENABLE_DBENGINE { char b[16]; - snprintfz(b, 15, "%d", default_rrdeng_page_cache_mb); + snprintfz(b, sizeof(b) - 1, "%d", default_rrdeng_page_cache_mb); analytics_set_data(&analytics_data.netdata_config_page_cache_size, b); - snprintfz(b, 15, "%d", default_multidb_disk_quota_mb); + snprintfz(b, sizeof(b) - 1, "%d", default_multidb_disk_quota_mb); analytics_set_data(&analytics_data.netdata_config_multidb_disk_quota, b); } #endif @@ -827,7 +827,7 @@ void get_system_timezone(void) void set_global_environment() { { char b[16]; - snprintfz(b, 15, "%d", default_rrd_update_every); + snprintfz(b, sizeof(b) - 1, "%d", default_rrd_update_every); setenv("NETDATA_UPDATE_EVERY", b, 1); } diff --git a/daemon/daemon.c b/daemon/daemon.c index 296d53fc9b..df81843f71 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -213,7 +213,7 @@ static void oom_score_adj(void) { // check the environment char *s = getenv("OOMScoreAdjust"); if(!s || !*s) { - snprintfz(buf, 30, "%d", (int)wanted_score); + snprintfz(buf, sizeof(buf) - 1, "%d", (int)wanted_score); s = buf; } @@ -248,7 +248,7 @@ static void oom_score_adj(void) { int written = 0; int fd = open("/proc/self/oom_score_adj", O_WRONLY); if(fd != -1) { - snprintfz(buf, 30, "%d", (int)wanted_score); + snprintfz(buf, sizeof(buf) - 1, "%d", (int)wanted_score); ssize_t len = strlen(buf); if(len > 0 && write(fd, buf, (size_t)len) == len) written = 1; close(fd); diff --git a/daemon/global_statistics.c b/daemon/global_statistics.c index 4638b293aa..a680b9b036 100644 --- a/daemon/global_statistics.c +++ b/daemon/global_statistics.c @@ -842,7 +842,7 @@ static void global_statistics_charts(void) { for(size_t tier = 0; tier < storage_tiers ;tier++) { char buf[30 + 1]; - snprintfz(buf, 30, "tier%zu", tier); + snprintfz(buf, sizeof(buf) - 1, "tier%zu", tier); rds[tier] = rrddim_add(st_points_stored, buf, NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); } } diff --git a/daemon/main.c b/daemon/main.c index 1fd143bf90..66845abda3 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1913,7 +1913,7 @@ int main(int argc, char **argv) { { char buf[20 + 1]; - snprintfz(buf, 20, "%d", libuv_worker_threads); + snprintfz(buf, sizeof(buf) - 1, "%d", libuv_worker_threads); setenv("UV_THREADPOOL_SIZE", buf, 1); } diff --git a/daemon/signals.c b/daemon/signals.c index 02c3586018..4f22543342 100644 --- a/daemon/signals.c +++ b/daemon/signals.c @@ -42,7 +42,7 @@ static void signal_handler(int signo) { if(signals_waiting[i].action == NETDATA_SIGNAL_FATAL) { char buffer[200 + 1]; - snprintfz(buffer, 200, "\nSIGNAL HANDLER: received: %s. Oops! This is bad!\n", signals_waiting[i].name); + snprintfz(buffer, sizeof(buffer) - 1, "\nSIGNAL HANDLER: received: %s. Oops! This is bad!\n", signals_waiting[i].name); if(write(STDERR_FILENO, buffer, strlen(buffer)) == -1) { // nothing to do - we cannot write but there is no way to complain about it ; diff --git a/daemon/unit_test.c b/daemon/unit_test.c index a099ef1b6f..8f44be39bb 100644 --- a/daemon/unit_test.c +++ b/daemon/unit_test.c @@ -97,7 +97,7 @@ static int check_number_printing(void) { int i, failed = 0; for(i = 0; values[i].correct ; i++) { print_netdata_double(netdata, values[i].n); - snprintfz(system, 512, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n); + snprintfz(system, sizeof(system) - 1, "%0.12" NETDATA_DOUBLE_MODIFIER, (NETDATA_DOUBLE)values[i].n); int ok = 1; if(strcmp(netdata, values[i].correct) != 0) { @@ -319,7 +319,7 @@ void benchmark_storage_number(int loop, int multiplier) { for(i = 0; i < loop ;i++) { n *= multiplier; if(n > storage_number_positive_max) n = storage_number_positive_min; - snprintfz(buffer, 100, NETDATA_DOUBLE_FORMAT, n); + snprintfz(buffer, sizeof(buffer) - 1, NETDATA_DOUBLE_FORMAT, n); } } @@ -507,7 +507,7 @@ int unit_test_buffer() { const char *fmt = "string1: %s\nstring2: %s\nstring3: %s\nstring4: %s"; buffer_sprintf(wb, fmt, string, string, string, string); - snprintfz(final, 9000, fmt, string, string, string, string); + snprintfz(final, sizeof(final) - 1, fmt, string, string, string, string); const char *s = buffer_tostring(wb); @@ -1272,7 +1272,7 @@ int run_test(struct test *test) default_rrd_update_every = test->update_every; char name[101]; - snprintfz(name, 100, "unittest-%s", test->name); + snprintfz(name, sizeof(name) - 1, "unittest-%s", test->name); // create the chart RRDSET *st = rrdset_create_localhost("netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest", NULL, 1 @@ -1534,7 +1534,7 @@ int unit_test(long delay, long shift) repeat++; char name[101]; - snprintfz(name, 100, "unittest-%d-%ld-%ld", repeat, delay, shift); + snprintfz(name, sizeof(name) - 1, "unittest-%d-%ld-%ld", repeat, delay, shift); //debug_flags = 0xffffffff; default_rrd_memory_mode = RRD_MEMORY_MODE_ALLOC; @@ -1870,7 +1870,7 @@ static void test_dbengine_create_charts(RRDHOST *host, RRDSET *st[CHARTS], RRDDI char name[101]; for (i = 0 ; i < CHARTS ; ++i) { - snprintfz(name, 100, "dbengine-chart-%d", i); + snprintfz(name, sizeof(name) - 1, "dbengine-chart-%d", i); // create the chart st[i] = rrdset_create(host, "netdata", name, name, "netdata", NULL, "Unit Testing", "a value", "unittest", @@ -1878,7 +1878,7 @@ static void test_dbengine_create_charts(RRDHOST *host, RRDSET *st[CHARTS], RRDDI rrdset_flag_set(st[i], RRDSET_FLAG_DEBUG); rrdset_flag_set(st[i], RRDSET_FLAG_STORE_FIRST); for (j = 0 ; j < DIMS ; ++j) { - snprintfz(name, 100, "dim-%d", j); + snprintfz(name, sizeof(name) - 1, "dim-%d", j); rd[i][j] = rrddim_add(st[i], name, NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } |