]> source.dussan.org Git - rspamd.git/commitdiff
Some fixes to fuzzystat
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Dec 2015 17:00:26 +0000 (17:00 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 14 Dec 2015 17:00:26 +0000 (17:00 +0000)
src/fuzzy_storage.c
src/libserver/rspamd_control.c

index 50aff7141ce57c99a23645270a3728ec9953cb7c..9bb542df874fe0110069015768efb769a9ac3628 100644 (file)
@@ -41,6 +41,7 @@
 #include "ref.h"
 #include "xxhash.h"
 #include "libutil/hash.h"
+#include "unix-std.h"
 
 /* This number is used as expire time in seconds for cache items  (2 days) */
 #define DEFAULT_EXPIRE 172800L
@@ -852,6 +853,10 @@ rspamd_fuzzy_storage_stat (struct rspamd_main *rspamd_main,
                ucl_object_emit_full (obj, UCL_EMIT_JSON_COMPACT, emit_subr);
                ucl_object_emit_funcs_free (emit_subr);
                ucl_object_unref (obj);
+               /* Rewind output file */
+               close (outfd);
+               outfd = open (tmppath, O_RDONLY);
+               unlink (tmppath);
        }
 
        /* Now we can send outfd and status message */
@@ -927,6 +932,7 @@ fuzzy_parse_keypair (rspamd_mempool_t *pool,
                keystat->last_ips = rspamd_lru_hash_new_full (0, 1024,
                                (GDestroyNotify)rspamd_inet_address_destroy, fuzzy_key_stat_dtor,
                                rspamd_inet_address_hash, rspamd_inet_address_equal);
+               g_hash_table_insert (ctx->keys_stats, kp->pk, keystat);
                msg_info_pool ("loaded keypair %8xs", kp->pk);
        }
        else if (ucl_object_type (obj) == UCL_ARRAY) {
@@ -1183,6 +1189,7 @@ start_fuzzy (struct rspamd_worker *worker)
        }
 
        g_hash_table_unref (ctx->keys);
+       g_hash_table_unref (ctx->keys_stats);
 
        exit (EXIT_SUCCESS);
 }
index 90f1c27b61a9fe191bdc3fbb558345342c844054..cd6b7829b8ce10ce57797367b6dd67e029e5325f 100644 (file)
@@ -185,6 +185,12 @@ rspamd_control_write_reply (struct rspamd_control_session *session)
        workers = ucl_object_typed_new (UCL_OBJECT);
 
        DL_FOREACH (session->replies, elt) {
+               /* Skip incompatible worker for fuzzy_stat */
+               if (session->cmd.type == RSPAMD_CONTROL_FUZZY_STAT &&
+                               elt->wrk->type != g_quark_from_static_string ("fuzzy")) {
+                       continue;
+               }
+
                rspamd_snprintf (tmpbuf, sizeof (tmpbuf), "%P", elt->wrk->pid);
                cur = ucl_object_typed_new (UCL_OBJECT);
 
@@ -226,8 +232,12 @@ rspamd_control_write_reply (struct rspamd_control_session *session)
                        if (elt->attached_fd != -1) {
                                /* We have some data to parse */
                                parser = ucl_parser_new (0);
-                               ucl_object_insert_key (cur, ucl_object_fromint (
-                                               elt->reply.reply.fuzzy_stat.status), "status", 0, false);
+                               ucl_object_insert_key (cur,
+                                               ucl_object_fromint (
+                                                               elt->reply.reply.fuzzy_stat.status),
+                                               "status",
+                                               0,
+                                               false);
 
                                if (ucl_parser_add_fd (parser, elt->attached_fd)) {
                                        ucl_object_insert_key (cur, ucl_parser_get_object (parser),
@@ -235,12 +245,26 @@ rspamd_control_write_reply (struct rspamd_control_session *session)
                                        ucl_parser_free (parser);
                                }
                                else {
+
                                        ucl_object_insert_key (cur, ucl_object_fromstring (
                                                        ucl_parser_get_error (parser)), "error", 0, false);
 
                                        ucl_parser_free (parser);
                                }
                        }
+                       else {
+                               ucl_object_insert_key (cur,
+                                               ucl_object_fromstring ("missing file"),
+                                               "error",
+                                               0,
+                                               false);
+                               ucl_object_insert_key (cur,
+                                               ucl_object_fromint (
+                                                               elt->reply.reply.fuzzy_stat.status),
+                                               "status",
+                                               0,
+                                               false);
+                       }
                        break;
                default:
                        break;