rspamd_snprintf (path, sizeof (path), "%s%c%s.hs", cbdata->cache_dir,
G_DIR_SEPARATOR, re_class->hash);
- if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, TRUE, TRUE)) {
+ if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, TRUE, TRUE, NULL)) {
fd = open (path, O_RDONLY, 00600);
gboolean
rspamd_re_cache_is_valid_hyperscan_file (struct rspamd_re_cache *cache,
- const char *path, gboolean silent, gboolean try_load)
+ const char *path, gboolean silent, gboolean try_load, GError **err)
{
g_assert (cache != NULL);
g_assert (path != NULL);
msg_err_re_cache ("cannot open hyperscan cache file %s: too short filename",
path);
}
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "too short filename");
+
return FALSE;
}
msg_err_re_cache ("cannot open hyperscan cache file %s: not ending with .hs",
path);
}
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "not ending with .hs");
return FALSE;
}
msg_err_re_cache ("cannot open hyperscan cache file %s: %s",
path, strerror (errno));
}
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "%s",
+ strerror (errno));
return FALSE;
}
msg_err_re_cache ("cannot read magic from hyperscan "
"cache file %s: %s",
path, strerror (errno));
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "cannot read magic: %s",
+ strerror (errno));
}
else {
msg_err_re_cache ("truncated read magic from hyperscan "
"cache file %s: %z, %z wanted",
path, r, (gsize)sizeof (magicbuf));
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "truncated read magic %zd, %zd wanted",
+ r, (gsize)sizeof (magicbuf));
}
+
close (fd);
return FALSE;
}
(int) RSPAMD_HS_MAGIC_LEN, mb);
close (fd);
+ g_set_error(err, rspamd_re_cache_quark(), 0, "invalid magic");
return FALSE;
}
path, r, (gsize)sizeof (magicbuf));
}
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "cannot read platform data: %s", strerror (errno));
+
close (fd);
return FALSE;
}
msg_err_re_cache ("cannot open hyperscan cache file %s: "
"compiled for a different platform",
path);
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "compiled for a different platform");
close (fd);
return FALSE;
msg_err_re_cache ("cannot mmap hyperscan cache file %s: "
"%s",
path, strerror (errno));
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "mmap error: %s", strerror(errno));
return FALSE;
}
/* Some wrong amount of regexps */
msg_err_re_cache ("bad number of expressions in %s: %d",
path, n);
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "bad number of expressions: %d", n);
munmap (map, len);
return FALSE;
}
if (crc != valid_crc) {
msg_warn_re_cache ("outdated or invalid hs database in %s: "
"crc read %xL, crc expected %xL", path, crc, valid_crc);
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "outdated or invalid hs database, crc check failure");
munmap (map, len);
return FALSE;
if ((ret = hs_deserialize_database (p, end - p, &test_db))
!= HS_SUCCESS) {
msg_err_re_cache ("bad hs database in %s: %d", path, ret);
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "deserialize error: %d", ret);
munmap (map, len);
return FALSE;
if (!silent) {
msg_warn_re_cache ("unknown hyperscan cache file %s", path);
+ g_set_error(err, rspamd_re_cache_quark(), 0,
+ "unknown hyperscan file");
}
return FALSE;
rspamd_snprintf (path, sizeof (path), "%s%c%s.hs", cache_dir,
G_DIR_SEPARATOR, re_class->hash);
- if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, try_load, FALSE)) {
+ if (rspamd_re_cache_is_valid_hyperscan_file (cache, path, try_load, FALSE, NULL)) {
msg_debug_re_cache ("load hyperscan database from '%s'",
re_class->hash);