Skip to content

Commit

Permalink
Coverity fixes (netdata#18896)
Browse files Browse the repository at this point in the history
* Ignore return code, we are exiting (suppress coverity)

* cloud base url is now url

* Suppress coverity warning

* Fix coverity time_t
  • Loading branch information
stelfrag authored Oct 30, 2024
1 parent d544c22 commit b4dfc78
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/aclk/aclk.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ static int load_private_key()
*/
static int wait_till_agent_claimed(void)
{
//TODO prevent malloc and freez
ND_UUID uuid = claim_id_get_uuid();
while (likely(UUIDiszero(uuid))) {
sleep_usec(USEC_PER_SEC * 1);
Expand Down Expand Up @@ -202,15 +201,15 @@ static int wait_till_agent_claim_ready()
// We trap the impossible NULL here to keep the linter happy without using a fatal() in the code.
const char *cloud_base_url = cloud_config_url_get();
if (cloud_base_url == NULL) {
netdata_log_error("Do not move the cloud base url out of post_conf_load!!");
netdata_log_error("Do not move the \"url\" out of post_conf_load!!");
return 1;
}

// We just check configuration is valid here
// TODO make it without malloc/free
memset(&url, 0, sizeof(url_t));
if (url_parse(cloud_base_url, &url)) {
netdata_log_error("Agent is claimed but the URL in configuration key \"cloud base url\" is invalid, please fix");
netdata_log_error("Agent is claimed but the URL in configuration key \"url\" is invalid, please fix");
url_t_destroy(&url);
sleep(5);
continue;
Expand Down Expand Up @@ -560,7 +559,7 @@ static int aclk_attempt_to_connect(mqtt_wss_client client)
while (service_running(SERVICE_ACLK)) {
aclk_cloud_base_url = cloud_config_url_get();
if (aclk_cloud_base_url == NULL) {
error_report("Do not move the cloud base url out of post_conf_load!!");
error_report("Do not move the \"url\" out of post_conf_load!!");
aclk_status = ACLK_STATUS_NO_CLOUD_URL;
return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1201,7 +1201,7 @@ static void get_netdata_configured_variables()
// get the hostname

netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
verify_netdata_host_prefix(true);
(void) verify_netdata_host_prefix(true);

char buf[HOSTNAME_MAX + 1];
if (get_hostname(buf, HOSTNAME_MAX))
Expand Down
2 changes: 1 addition & 1 deletion src/database/engine/rrdengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,6 @@ void dbengine_event_loop(void* arg) {
}

nd_log(NDLS_DAEMON, NDLP_DEBUG, "Shutting down dbengine thread");
uv_loop_close(&main->loop);
(void) uv_loop_close(&main->loop);
worker_unregister();
}
5 changes: 5 additions & 0 deletions src/database/rrd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1637,6 +1637,11 @@ static inline double rrddim_get_last_stored_value(RRDDIM *rd_dim, double *max_va
return value;
}

static inline uint32_t get_uint32_id()
{
return now_realtime_sec() & UINT32_MAX;
}

//
// RRD DB engine declarations

Expand Down
6 changes: 4 additions & 2 deletions src/database/sqlite/sqlite_health.c
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,10 @@ void sql_health_alarm_log_load(RRDHOST *host)
dictionary_destroy(all_rrdcalcs);
all_rrdcalcs = NULL;

if(!host->health_max_unique_id) host->health_max_unique_id = (uint32_t)now_realtime_sec();
if(!host->health_max_alarm_id) host->health_max_alarm_id = (uint32_t)now_realtime_sec();
if (!host->health_max_unique_id)
host->health_max_unique_id = get_uint32_id();
if (!host->health_max_alarm_id)
host->health_max_alarm_id = get_uint32_id();

host->health_log.next_log_id = host->health_max_unique_id + 1;
if (unlikely(!host->health_log.next_alarm_id || host->health_log.next_alarm_id <= host->health_max_alarm_id))
Expand Down
2 changes: 1 addition & 1 deletion src/health/health_event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static void health_initialize_rrdhost(RRDHOST *host) {
host->health.health_default_recipient = string_dup(health_globals.config.default_recipient);
host->health.use_summary_for_notifications = health_globals.config.use_summary_for_notifications;

host->health_log.next_log_id = (uint32_t)now_realtime_sec();
host->health_log.next_log_id = get_uint32_id();
host->health_log.next_alarm_id = 0;

rw_spinlock_init(&host->health_log.spinlock);
Expand Down
2 changes: 1 addition & 1 deletion src/health/rrdcalc.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ uint32_t rrdcalc_get_unique_id(RRDHOST *host, STRING *chart, STRING *name, uint3
alarm_id = sql_get_alarm_id(host, chart, name, next_event_id);
if (!alarm_id) {
if (unlikely(!host->health_log.next_alarm_id))
host->health_log.next_alarm_id = (uint32_t)now_realtime_sec();
host->health_log.next_alarm_id = get_uint32_id();
alarm_id = host->health_log.next_alarm_id++;
}
}
Expand Down

0 comments on commit b4dfc78

Please sign in to comment.