aboutsummaryrefslogtreecommitdiffstats
path: root/src/util.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-11-12 20:38:20 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-11-12 20:38:20 +0300
commit092a40dcf813accb11a0b6bb600dccea0b35fb1d (patch)
treebc15b37adda2a21575799204dbc528874d2e82c2 /src/util.c
parent1ad9f1f651ef3f0ee26d69007dd27e60f99f1f12 (diff)
downloadrspamd-092a40dcf813accb11a0b6bb600dccea0b35fb1d.tar.gz
rspamd-092a40dcf813accb11a0b6bb600dccea0b35fb1d.zip
* Write revision and revision time to statfile
* Make some improvements to API (trying to make it more clear)
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index b431a9116..4eb0a4341 100644
--- a/src/util.c
+++ b/src/util.c
@@ -27,6 +27,7 @@
#include "util.h"
#include "cfg_file.h"
#include "main.h"
+#include "statfile.h"
/* Check log messages intensity once per minute */
#define CHECK_TIME 60
@@ -1094,7 +1095,7 @@ unlock_file (int fd, gboolean async)
return TRUE;
}
-#else
+#else /* HAVE_FLOCK */
/* Fctnl version */
gboolean
lock_file (int fd, gboolean async)
@@ -1138,7 +1139,49 @@ unlock_file (int fd, gboolean async)
return TRUE;
}
-#endif
+#endif /* HAVE_FLOCK */
+
+#ifdef RSPAMD_MAIN
+stat_file_t *
+get_statfile_by_symbol (statfile_pool_t *pool, struct classifier_config *ccf,
+ const char *symbol, struct statfile **st, gboolean try_create)
+{
+ stat_file_t *res = NULL;
+ GList *cur;
+
+ if (pool == NULL || ccf == NULL || symbol == NULL) {
+ return NULL;
+ }
+
+ cur = g_list_first (ccf->statfiles);
+ while (cur) {
+ *st = cur->data;
+ if (strcmp (symbol, (*st)->symbol) == 0) {
+ break;
+ }
+ *st = NULL;
+ cur = g_list_next (cur);
+ }
+ if (*st == NULL) {
+ return NULL;
+ }
+
+ if ((res = statfile_pool_is_open (pool, (*st)->path)) == NULL) {
+ if ((res = statfile_pool_open (pool, (*st)->path, (*st)->size, FALSE)) == NULL) {
+ msg_warn ("get_statfile_by_symbol: cannot open %s", (*st)->path);
+ if (try_create) {
+ if (statfile_pool_create (pool, (*st)->path, (*st)->size) == -1) {
+ msg_err ("get_statfile_by_symbol: cannot create statfile %s", (*st)->path);
+ return NULL;
+ }
+ res = statfile_pool_open (pool, (*st)->path, (*st)->size, FALSE);
+ }
+ }
+ }
+
+ return res;
+}
+#endif /* RSPAMD_MAIN */
/*
* vi:ts=4