diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-04-20 16:32:23 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-04-20 16:32:23 +0400 |
commit | 2d8eebcf7a0951d3d1189ddface7678fea76dd4c (patch) | |
tree | 7a1748e4d3633c3b8def3de8f2a08fb370c7e61d /src/main.c | |
parent | d4b35de4315753629ac5b107968e6194eac85d24 (diff) | |
download | rspamd-2d8eebcf7a0951d3d1189ddface7678fea76dd4c.tar.gz rspamd-2d8eebcf7a0951d3d1189ddface7678fea76dd4c.zip |
* Bugfixes:
- handle '\' characters in lua strings correctly
- fix lua initialization
- avoid of using global lua state (global L)
- fix listen sockets hash to allow multiply workers of same type but on different listen sockets
- fix modules options inserting to allow multiply options of the same name
- fix parsing of lua options
- fix lua rules
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/main.c b/src/main.c index 2c02e82b1..123a69940 100644 --- a/src/main.c +++ b/src/main.c @@ -465,6 +465,37 @@ fork_delayed (struct rspamd_main *rspamd) } } +static inline uintptr_t +make_listen_key (struct in_addr *addr, int port, int family, char *path) +{ + uintptr_t res = 0; + char *key; + + if (family == AF_INET) { + /* Make fnv hash from bytes of addr and port */ + key = (char *)&addr->s_addr; + while (key - (char *)&addr->s_addr < sizeof (addr->s_addr)) { + res ^= (char)*key++; + res += (res << 1) + (res << 4) + (res << 7) + (res << 8) + (res << 24); + } + key = (char *)&port; + while (key - (char *)&port < sizeof (addr->s_addr)) { + res ^= (char)*key++; + res += (res << 1) + (res << 4) + (res << 7) + (res << 8) + (res << 24); + } + } + else { + /* Make fnv hash from bytes of path */ + key = path; + while (*key) { + res ^= (char)*key++; + res += (res << 1) + (res << 4) + (res << 7) + (res << 8) + (res << 24); + } + } + + return res; +} + static void spawn_workers (struct rspamd_main *rspamd) { @@ -479,13 +510,16 @@ spawn_workers (struct rspamd_main *rspamd) cf = cur->data; if (cf->has_socket) { - if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER (cf->type))) == NULL) { + if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER ( + make_listen_key (&cf->bind_addr, cf->bind_port, cf->bind_family, cf->bind_host)))) == NULL) { /* Create listen socket */ listen_sock = create_listen_socket (&cf->bind_addr, cf->bind_port, cf->bind_family, cf->bind_host); if (listen_sock == -1) { exit (-errno); } - g_hash_table_insert (listen_sockets, GINT_TO_POINTER (cf->type), GINT_TO_POINTER (listen_sock)); + g_hash_table_insert (listen_sockets, GINT_TO_POINTER ( + make_listen_key (&cf->bind_addr, cf->bind_port, cf->bind_family, cf->bind_host)), + GINT_TO_POINTER (listen_sock)); } else { /* We had socket for this type of worker */ |