From 5424cc32d47c5e98b9edfb2b342d9d98d97a1175 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 3 Mar 2009 14:31:51 +0300 Subject: * 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 --- src/lmtp_proto.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'src/lmtp_proto.c') 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; -- cgit v1.2.3