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);
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 {
{
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;
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 {
close (session->sock);
memory_pool_delete (session->pool);
- g_free (session);
+ g_slice_free1 (sizeof (struct smtp_proxy_session), session);
}
}
{
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);
}
{
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);
}
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");