dovecot-2.0: lib-master: Added timeout to master login attempts ...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jun 9 18:39:19 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/7385d8090890
changeset: 11506:7385d8090890
user: Timo Sirainen <tss at iki.fi>
date: Wed Jun 09 16:39:12 2010 +0100
description:
lib-master: Added timeout to master login attempts and improved error logging.
diffstat:
src/lib-master/master-auth.c | 30 ++++++++++++++++++++++--------
1 files changed, 22 insertions(+), 8 deletions(-)
diffs (95 lines):
diff -r a859ab0d760e -r 7385d8090890 src/lib-master/master-auth.c
--- a/src/lib-master/master-auth.c Wed Jun 09 16:38:33 2010 +0100
+++ b/src/lib-master/master-auth.c Wed Jun 09 16:39:12 2010 +0100
@@ -13,6 +13,7 @@
#include <sys/stat.h>
#define SOCKET_CONNECT_RETRY_MSECS 500
+#define MASTER_AUTH_REQUEST_TIMEOUT_MSECS (MASTER_LOGIN_TIMEOUT_SECS/2*1000)
struct master_auth_connection {
struct master_auth *auth;
@@ -20,6 +21,7 @@
int fd;
struct io *io;
+ struct timeout *to;
char buf[sizeof(struct master_auth_reply)];
unsigned int buf_pos;
@@ -69,11 +71,13 @@
if (conn->callback != NULL)
conn->callback(NULL, conn->context);
+ if (conn->to != NULL)
+ timeout_remove(&conn->to);
if (conn->io != NULL)
io_remove(&conn->io);
if (conn->fd != -1) {
if (close(conn->fd) < 0)
- i_fatal("close(master auth conn) failed: %m");
+ i_fatal("close(%s) failed: %m", conn->auth->path);
conn->fd = -1;
}
i_free(conn);
@@ -110,10 +114,10 @@
if (ret < 0) {
if (errno == EAGAIN)
return;
- i_error("read(master auth conn) failed: %m");
+ i_error("read(%s) failed: %m", conn->auth->path);
} else {
- i_error("read(master auth conn) failed: "
- "Remote closed connection");
+ i_error("read(%s) failed: Remote closed connection",
+ conn->auth->path);
}
master_auth_connection_deinit(&conn);
return;
@@ -128,7 +132,8 @@
conn->buf_pos = 0;
if (conn->tag != reply->tag)
- i_error("Master sent reply with unknown tag %u", reply->tag);
+ i_error("master(%s): Received reply with unknown tag %u",
+ conn->auth->path, reply->tag);
else if (conn->callback == NULL) {
/* request aborted */
} else {
@@ -138,6 +143,13 @@
master_auth_connection_deinit(&conn);
}
+static void master_auth_connection_timeout(struct master_auth_connection *conn)
+{
+ i_error("master(%s): Auth request timed out (received %u/%u bytes)",
+ conn->auth->path, conn->buf_pos, sizeof(conn->buf));
+ master_auth_connection_deinit(&conn);
+}
+
void master_auth_request(struct master_auth *auth, int fd,
const struct master_auth_request *request,
const unsigned char *data,
@@ -182,10 +194,10 @@
ret = fd_send(conn->fd, fd, buf->data, buf->used);
if (ret < 0)
- i_error("fd_send(%d) failed: %m", fd);
+ i_error("fd_send(%s, %d) failed: %m", auth->path, fd);
else if ((size_t)ret != buf->used) {
- i_error("fd_send() sent only %d of %d bytes",
- (int)ret, (int)buf->used);
+ i_error("fd_send(%s) sent only %d of %d bytes",
+ auth->path, (int)ret, (int)buf->used);
ret = -1;
}
if (ret < 0) {
@@ -194,6 +206,8 @@
}
conn->tag = req.tag;
+ conn->to = timeout_add(MASTER_AUTH_REQUEST_TIMEOUT_MSECS,
+ master_auth_connection_timeout, conn);
conn->io = io_add(conn->fd, IO_READ,
master_auth_connection_input, conn);
hash_table_insert(auth->connections, POINTER_CAST(req.tag), conn);
More information about the dovecot-cvs
mailing list