]> source.dussan.org Git - rspamd.git/commitdiff
Fix proxy logic.
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 13 Mar 2012 13:30:06 +0000 (17:30 +0400)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Tue, 13 Mar 2012 13:30:06 +0000 (17:30 +0400)
src/main.c
src/proxy.c
src/smtp_proxy.c

index caced2b171d8f93449905418c1008ced2eff4439..a342a56ea405f69f448e7a07232fddd5fe3920bf 100644 (file)
@@ -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);
index df1ccfdae391a2f4e60bf58935313ed1e29f59c4..bd8503c714ca7700ae521ce93ed37410d46d1517 100644 (file)
@@ -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 {
index fa9da971a8061eefc8a0c5d0eefd2c57dd6bc396..75f4eaebaf90d99ecd7421817f20535579594e8c 100644 (file)
@@ -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");