aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2012-03-13 17:30:06 +0400
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2012-03-13 17:30:06 +0400
commitc2418c4890493f350198d1d990427e601fa2bf6e (patch)
tree2e20da62b3bbdd068c25fb329e68bd173f968cd4
parentdb1f276aa8d6ed66340919fe1c7fa454c52fea43 (diff)
downloadrspamd-c2418c4890493f350198d1d990427e601fa2bf6e.tar.gz
rspamd-c2418c4890493f350198d1d990427e601fa2bf6e.zip
Fix proxy logic.
-rw-r--r--src/main.c59
-rw-r--r--src/proxy.c12
-rw-r--r--src/smtp_proxy.c14
3 files changed, 48 insertions, 37 deletions
diff --git a/src/main.c b/src/main.c
index caced2b17..a342a56ea 100644
--- a/src/main.c
+++ b/src/main.c
@@ -553,38 +553,43 @@ spawn_workers (struct rspamd_main *rspamd)
while (cur) {
cf = cur->data;
- if (cf->worker->has_socket) {
- 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);
+ if (cf->worker == NULL) {
+ msg_err ("type of worker is unspecified, skip spawning");
+ }
+ else {
+ if (cf->worker->has_socket) {
+ 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 (
+ make_listen_key (&cf->bind_addr, cf->bind_port, cf->bind_family, cf->bind_host)),
+ 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 */
- listen_sock = GPOINTER_TO_INT (p);
+ else {
+ /* We had socket for this type of worker */
+ listen_sock = GPOINTER_TO_INT (p);
+ }
+ cf->listen_sock = listen_sock;
}
- cf->listen_sock = listen_sock;
- }
-
- if (cf->worker->unique) {
- if (cf->count > 1) {
- msg_err ("cannot spawn more than 1 %s worker, so spawn one", cf->worker->name);
+
+ if (cf->worker->unique) {
+ if (cf->count > 1) {
+ msg_err ("cannot spawn more than 1 %s worker, so spawn one", cf->worker->name);
+ }
+ fork_worker (rspamd, cf);
}
- fork_worker (rspamd, cf);
- }
- else if (cf->worker->threaded) {
- fork_worker (rspamd, cf);
- }
- else {
- for (i = 0; i < cf->count; i++) {
+ else if (cf->worker->threaded) {
fork_worker (rspamd, cf);
}
+ else {
+ for (i = 0; i < cf->count; i++) {
+ fork_worker (rspamd, cf);
+ }
+ }
}
cur = g_list_next (cur);
diff --git a/src/proxy.c b/src/proxy.c
index df1ccfdae..bd8503c71 100644
--- a/src/proxy.c
+++ b/src/proxy.c
@@ -87,10 +87,10 @@ rspamd_proxy_client_handler (gint fd, gshort what, gpointer data)
if (proxy->buf_offset == proxy->read_len) {
/* We wrote everything */
event_del (&proxy->client_ev);
- event_set (&proxy->client_ev, proxy->bfd, EV_READ, rspamd_proxy_client_handler, proxy);
+ event_set (&proxy->client_ev, proxy->cfd, EV_READ, rspamd_proxy_client_handler, proxy);
event_add (&proxy->client_ev, proxy->tv);
event_del (&proxy->backend_ev);
- event_set (&proxy->backend_ev, proxy->bfd, EV_READ, rspamd_proxy_client_handler, proxy);
+ event_set (&proxy->backend_ev, proxy->bfd, EV_READ, rspamd_proxy_backend_handler, proxy);
event_add (&proxy->backend_ev, proxy->tv);
}
else {
@@ -126,12 +126,12 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data)
{
rspamd_proxy_t *proxy = data;
gint r;
- GError *err;
+ GError *err = NULL;
if (what == EV_READ) {
/* Got data from backend */
event_del (&proxy->backend_ev);
- r = read (proxy->cfd, proxy->buf, proxy->bufsize);
+ r = read (proxy->bfd, proxy->buf, proxy->bufsize);
if (r > 0) {
/* Write this buffer to client */
proxy->read_len = r;
@@ -164,10 +164,10 @@ rspamd_proxy_backend_handler (gint fd, gshort what, gpointer data)
if (proxy->buf_offset == proxy->read_len) {
/* We wrote everything */
event_del (&proxy->backend_ev);
- event_set (&proxy->backend_ev, proxy->bfd, EV_READ, rspamd_proxy_client_handler, proxy);
+ event_set (&proxy->backend_ev, proxy->bfd, EV_READ, rspamd_proxy_backend_handler, proxy);
event_add (&proxy->backend_ev, proxy->tv);
event_del (&proxy->client_ev);
- event_set (&proxy->client_ev, proxy->bfd, EV_READ, rspamd_proxy_client_handler, proxy);
+ event_set (&proxy->client_ev, proxy->cfd, EV_READ, rspamd_proxy_client_handler, proxy);
event_add (&proxy->client_ev, proxy->tv);
}
else {
diff --git a/src/smtp_proxy.c b/src/smtp_proxy.c
index fa9da971a..75f4eaeba 100644
--- a/src/smtp_proxy.c
+++ b/src/smtp_proxy.c
@@ -182,7 +182,7 @@ free_smtp_proxy_session (gpointer arg)
close (session->sock);
memory_pool_delete (session->pool);
- g_free (session);
+ g_slice_free1 (sizeof (struct smtp_proxy_session), session);
}
}
@@ -191,7 +191,10 @@ smtp_proxy_err_proxy (GError * err, void *arg)
{
struct smtp_proxy_session *session = arg;
- msg_info ("abnormally closing connection, error: %s", err->message);
+ if (err) {
+ g_error_free (err);
+ msg_info ("abnormally closing connection, error: %s", err->message);
+ }
/* Free buffers */
destroy_session (session->s);
}
@@ -411,7 +414,10 @@ smtp_proxy_err_socket (GError * err, void *arg)
{
struct smtp_proxy_session *session = arg;
- msg_info ("abnormally closing connection, error: %s", err->message);
+ if (err) {
+ g_error_free (err);
+ msg_info ("abnormally closing connection, error: %s", err->message);
+ }
/* Free buffers */
destroy_session (session->s);
}
@@ -536,7 +542,7 @@ void
start_smtp_proxy (struct rspamd_worker *worker)
{
struct sigaction signals;
- struct smtp_worker_ctx *ctx = worker->ctx;
+ struct smtp_proxy_ctx *ctx = worker->ctx;
gperf_profiler_init (worker->srv->cfg, "worker");