#include <unistd.h> /* for unlink */
#include <optional>
#include "unix-std.h"
+#include "rspamd_control.h"
#define msg_info_hyperscan(...) rspamd_default_log_function (G_LOG_LEVEL_INFO, \
"hyperscan", "", \
virtual ~hs_known_files_cache() {
// Cleanup cache dir
- if (rspamd_current_worker != nullptr && rspamd_worker_is_primary_controller(rspamd_current_worker)) {
+ /* We clean dir merely if we are running from the main process */
+ if (rspamd_current_worker == nullptr) {
auto cleanup_dir = [&](std::string_view dir) -> void {
for (const auto &ext : cache_extensions) {
glob_t globbuf;
rspamd_hyperscan_notice_known(const char *fname)
{
rspamd::util::hs_known_files_cache::get().add_cached_file(fname);
+
+ if (rspamd_current_worker != nullptr) {
+ /* Also notify main process */
+ struct rspamd_srv_command notice_cmd;
+
+ if (strlen(fname) >= sizeof(notice_cmd.cmd.hyperscan_cache_file.path)) {
+ msg_err("internal error: length of the filename %d ('%s') is larger than control buffer path: %d",
+ (int)strlen(fname), fname, (int)sizeof(notice_cmd.cmd.hyperscan_cache_file.path));
+ }
+ else {
+ notice_cmd.type = RSPAMD_NOTICE_HYPERSCAN_CACHE;
+ rspamd_srv_send_command(rspamd_current_worker,
+ rspamd_current_worker->srv->event_loop, ¬ice_cmd, -1,
+ nullptr,
+ nullptr);
+ }
+ }
}
#endif // WITH_HYPERSCAN
\ No newline at end of file
#include <sys/resource.h>
#endif
+#ifdef WITH_HYPERSCAN
+#include "hyperscan_tools.h"
+#endif
+
static ev_tstamp io_timeout = 30.0;
static ev_tstamp worker_io_timeout = 0.5;
case RSPAMD_SRV_HEALTH:
rspamd_fill_health_reply (srv, &rdata->rep);
break;
+ case RSPAMD_NOTICE_HYPERSCAN_CACHE:
+#ifdef WITH_HYPERSCAN
+ rspamd_hyperscan_notice_known(cmd.cmd.hyperscan_cache_file.path);
+#endif
+ rdata->rep.reply.hyperscan_cache_file.unused = 0;
+ break;
default:
msg_err ("unknown command type: %d", cmd.type);
break;
RSPAMD_SRV_ON_FORK,
RSPAMD_SRV_HEARTBEAT,
RSPAMD_SRV_HEALTH,
+ RSPAMD_NOTICE_HYPERSCAN_CACHE,
};
enum rspamd_log_pipe_type {
RSPAMD_LOG_PIPE_SYMBOLS = 0,
};
-#define CONTROL_PATHLEN MIN(PATH_MAX, PIPE_BUF - sizeof(int) * 2)
+#define CONTROL_PATHLEN MIN(PATH_MAX, PIPE_BUF - sizeof(int) * 2 - sizeof(gint64))
struct rspamd_control_command {
enum rspamd_control_type type;
union {
struct {
guint status;
} health;
+ /* Used when a worker loads a valid hyperscan file */
+ struct {
+ char path[CONTROL_PATHLEN];
+ } hyperscan_cache_file;
} cmd;
};
guint scanners_count;
guint workers_hb_lost;
} health;
+ struct {
+ int unused;
+ } hyperscan_cache_file;
} reply;
};