summaryrefslogtreecommitdiffstats
path: root/database
diff options
context:
space:
mode:
authorthiagoftsm <thiagoftsm@gmail.com>2019-10-01 15:40:41 +0000
committerGitHub <noreply@github.com>2019-10-01 15:40:41 +0000
commitc48d52eeb5b2387ead1e1fa50311750f4ccd328a (patch)
treef4ff5b4018a18c42a029e7a4b622343fd7771fb9 /database
parentb063d3acae225c303f36a6dde641852ed2379124 (diff)
Fix coverity erro (CID 349552) double lock (#6970)
* dim_template_fix: Fix lock We had a double lock before, this commit fix this * dim_template_fix: Fix order This commit fix the order process * dim_template_fix: Return I am returning for the first solution, because the others are generating: * dim_template_fix: Try to lock This solution try to lock the host before to move in front * dim_template_fix: Move chart lock To avoid the chart to be deleted while we are linking the alarm I am moving bak the chart lock * dim_template_fix: Fix grammar This commit fixes the grammar of an error message * dim_template_fix: bring pattern Bring the defined pattern to the code and use netdata_rwlock_trywrlock * dim_template_fix Fix format This commit fixes a format missing
Diffstat (limited to 'database')
-rw-r--r--database/rrddim.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/database/rrddim.c b/database/rrddim.c
index 3600a7744e..8ab5a72371 100644
--- a/database/rrddim.c
+++ b/database/rrddim.c
@@ -186,6 +186,7 @@ void rrdcalc_link_to_rrddim(RRDDIM *rd, RRDSET *st, RRDHOST *host) {
}
RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collected_number multiplier, collected_number divisor, RRD_ALGORITHM algorithm, RRD_MEMORY_MODE memory_mode) {
+ RRDHOST *host = st->rrdhost;
rrdset_wrlock(st);
rrdset_flag_set(st, RRDSET_FLAG_SYNC_CLOCK);
@@ -204,7 +205,6 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
return rd;
}
- RRDHOST *host = st->rrdhost;
char filename[FILENAME_MAX + 1];
char fullfilename[FILENAME_MAX + 1];
@@ -400,13 +400,28 @@ RRDDIM *rrddim_add_custom(RRDSET *st, const char *id, const char *name, collecte
if(unlikely(rrddim_index_add(st, rd) != rd))
error("RRDDIM: INTERNAL ERROR: attempt to index duplicate dimension '%s' on chart '%s'", rd->id, st->id);
- if(host->alarms_with_foreach || host->alarms_template_with_foreach) {
- rrdhost_wrlock(host);
- rrdcalc_link_to_rrddim(rd, st, host);
+ if (host->alarms_with_foreach || host->alarms_template_with_foreach) {
+ int count = 0;
+ int hostlocked;
+ for (count = 0 ; count < 5 ; count++) {
+ hostlocked = netdata_rwlock_trywrlock(&host->rrdhost_rwlock);
+ if (!hostlocked) {
+ rrdcalc_link_to_rrddim(rd, st, host);
+ rrdhost_unlock(host);
+ break;
+ } else if (hostlocked != EBUSY) {
+ error("Cannot lock host to create an alarm for the dimension.");
+ }
+ usleep(200000);
+ }
- rrdhost_unlock(host);
+ if (count == 5) {
+ error("Failed to create an alarm for dimension %s of chart %s 5 times. Skipping alarm."
+ , rd->name, st->name);
+ }
}
rrdset_unlock(st);
+
return(rd);
}