From: Vsevolod Stakhov Date: Fri, 1 Jul 2016 15:29:43 +0000 (+0100) Subject: [Fix] Improve rrd diagnostic errors X-Git-Tag: 1.3.0~199 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cabb46ca81c60638493e7842aeaba9166d5d34a9;p=rspamd.git [Fix] Improve rrd diagnostic errors --- diff --git a/src/controller.c b/src/controller.c index 085eda5d4..8fb3cb1b1 100644 --- a/src/controller.c +++ b/src/controller.c @@ -2619,7 +2619,9 @@ start_controller_worker (struct rspamd_worker *worker) /* RRD collector */ if (ctx->cfg->rrd_file && worker->index == 0) { - ctx->rrd = rspamd_rrd_file_default (ctx->cfg->rrd_file, NULL); + GError *rrd_err = NULL; + + ctx->rrd = rspamd_rrd_file_default (ctx->cfg->rrd_file, &rrd_err); if (ctx->rrd) { ctx->rrd_event = g_slice_alloc0 (sizeof (*ctx->rrd_event)); @@ -2627,6 +2629,14 @@ start_controller_worker (struct rspamd_worker *worker) event_base_set (ctx->ev_base, ctx->rrd_event); event_add (ctx->rrd_event, &rrd_update_time); } + else if (rrd_err) { + msg_err ("cannot load rrd from %s: %e", ctx->cfg->rrd_file, + rrd_err); + g_error_free (rrd_err); + } + else { + msg_err ("cannot load rrd from %s: unknown error", ctx->cfg->rrd_file); + } } else { ctx->rrd = NULL; diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c index 470896efa..a230faf2b 100644 --- a/src/libutil/rrd.c +++ b/src/libutil/rrd.c @@ -217,20 +217,30 @@ rspamd_rrd_check_file (const gchar *filename, gboolean need_data, GError **err) return FALSE; } /* Check magic */ - if (memcmp (head.cookie, RRD_COOKIE, sizeof (head.cookie)) != 0 || - memcmp (head.version, RRD_VERSION, sizeof (head.version)) != 0 || - head.float_cookie != RRD_FLOAT_COOKIE) { + if (memcmp (head.version, RRD_VERSION, sizeof (head.version)) != 0) { g_set_error (err, - rrd_error_quark (), EINVAL, "rrd head cookies error: %s", - strerror (errno)); + rrd_error_quark (), EINVAL, "rrd head error: bad cookie"); + close (fd); + return FALSE; + } + if (memcmp (head.version, RRD_VERSION, sizeof (head.version)) != 0) { + g_set_error (err, + rrd_error_quark (), EINVAL, "rrd head error: invalid version"); + close (fd); + return FALSE; + } + if (head.float_cookie != RRD_FLOAT_COOKIE) { + g_set_error (err, + rrd_error_quark (), EINVAL, "rrd head error: another architecture " + "(file cookie %g != our cookie %g)", + head.float_cookie, RRD_FLOAT_COOKIE); close (fd); return FALSE; } /* Check for other params */ if (head.ds_cnt <= 0 || head.rra_cnt <= 0) { g_set_error (err, - rrd_error_quark (), EINVAL, "rrd head cookies error: %s", - strerror (errno)); + rrd_error_quark (), EINVAL, "rrd head cookies error: bad rra or ds count"); close (fd); return FALSE; }