diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-03 14:31:51 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-03-03 14:31:51 +0300 |
commit | 5424cc32d47c5e98b9edfb2b342d9d98d97a1175 (patch) | |
tree | bd4a0d4418b71d0024f5d66d07de2cc24aded7ec /src/lmtp_proto.c | |
parent | 3ff032cf72164dc9aa8575c0a631f7c7b0079f46 (diff) | |
download | rspamd-5424cc32d47c5e98b9edfb2b342d9d98d97a1175.tar.gz rspamd-5424cc32d47c5e98b9edfb2b342d9d98d97a1175.zip |
* Unify socket creation and accepting by using utility functions
* Check SO_ERROR on socket immideately after connect/bind to avoid resourses allocation for
unsuccessful connections
* Avoid descriptors leakage when we create sockets and have errors on them
* Set on all socket descriptors FD_CLOEXEC flag to avoid problems with executing LDA
Diffstat (limited to 'src/lmtp_proto.c')
-rw-r--r-- | src/lmtp_proto.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/lmtp_proto.c b/src/lmtp_proto.c index 42bf3560a..ab20e41a8 100644 --- a/src/lmtp_proto.c +++ b/src/lmtp_proto.c @@ -416,31 +416,20 @@ mta_err_socket (GError *err, void *arg) static int lmtp_deliver_mta (struct worker_task *task) { - int sock, on = 1; - struct linger linger; + int sock; struct sockaddr_un *un; struct mta_callback_data *cd; if (task->cfg->deliver_family == AF_UNIX) { un = alloca (sizeof (struct sockaddr_un)); - sock = make_unix_socket (task->cfg->deliver_host, un); - if (event_make_socket_nonblocking (sock) < 0) { - return -1; - } + sock = make_unix_socket (task->cfg->deliver_host, un, FALSE); } else { - sock = make_socket (&task->cfg->deliver_addr, task->cfg->deliver_port); + sock = make_tcp_socket (&task->cfg->deliver_addr, task->cfg->deliver_port, FALSE); } if (sock == -1) { msg_warn ("lmtp_deliver_mta: cannot create socket for %s, %s", task->cfg->deliver_host, strerror (errno)); } - - /* Socket options */ - setsockopt (sock, SOL_SOCKET, SO_KEEPALIVE, (void *)&on, sizeof(on)); - setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); - linger.l_onoff = 1; - linger.l_linger = 2; - setsockopt (sock, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger)); cd = memory_pool_alloc (task->task_pool, sizeof (struct mta_callback_data)); cd->task = task; |