dovecot-2.2: Added o_stream_nsend*() and related functions to ma...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jun 25 00:02:30 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/ca37d1577291
changeset: 14681:ca37d1577291
user: Timo Sirainen <tss at iki.fi>
date: Mon Jun 25 00:01:59 2012 +0300
description:
Added o_stream_nsend*() and related functions to make delayed error handling safer.
Once o_stream_nsend*() is called, o_stream_nfinish() must be called before
stream is destroyed to finish checking if there were any errors. If
something failed and the stream is just wanted to be closed,
o_stream_ignore_last_errors() can be called.
For streams where errors don't really make any difference (network sockets)
you can call o_stream_set_no_error_handling() immediately after creating the
stream.
diffstat:
src/anvil/anvil-connection.c | 10 +-
src/anvil/connect-limit.c | 2 +-
src/anvil/penalty.c | 2 +-
src/auth/auth-client-connection.c | 9 +-
src/auth/auth-client-connection.h | 4 +-
src/auth/auth-master-connection.c | 27 ++++----
src/auth/auth-postfix-connection.c | 3 +-
src/auth/auth-worker-client.c | 13 ++-
src/auth/auth-worker-server.c | 5 +-
src/auth/main.c | 4 +-
src/auth/mech-winbind.c | 3 +-
src/config/config-connection.c | 29 ++++----
src/config/doveconf.c | 33 +++++-----
src/dict/dict-commands.c | 12 +-
src/dict/dict-connection.c | 1 +
src/director/auth-connection.c | 3 +-
src/director/director-connection.c | 2 +-
src/director/director-test.c | 19 +++--
src/director/doveadm-connection.c | 41 ++++++------
src/director/login-connection.c | 5 +-
src/dns/dns-client.c | 9 +-
src/doveadm/client-connection.c | 19 +++--
src/doveadm/doveadm-mail-fetch.c | 1 +
src/doveadm/doveadm-print-server.c | 4 +-
src/doveadm/dsync/dsync-slave-io.c | 19 +++--
src/doveadm/server-connection.c | 9 +-
src/imap-login/imap-proxy.c | 9 +-
src/imap/cmd-append.c | 8 +-
src/imap/cmd-copy.c | 4 +-
src/imap/cmd-thread.c | 6 +-
src/imap/imap-client.c | 11 +-
src/imap/imap-fetch-body.c | 12 +--
src/imap/imap-fetch.c | 5 +-
src/imap/imap-search.c | 9 +-
src/imap/imap-sync.c | 4 +-
src/imap/mail-storage-callbacks.c | 8 +-
src/indexer/indexer-client.c | 7 +-
src/indexer/worker-connection.c | 5 +-
src/ipc/client.c | 13 ++-
src/ipc/ipc-connection.c | 5 +-
src/lib-auth/auth-master.c | 7 +-
src/lib-dict/dict-file.c | 11 +-
src/lib-fs/fs-posix.c | 4 +-
src/lib-fs/ostream-cmp.c | 2 +-
src/lib-imap-client/imapc-connection.c | 5 +-
src/lib-imap/imap-parser.c | 4 +-
src/lib-index/mail-cache-compress.c | 13 +--
src/lib-index/mail-index-strmap.c | 43 ++++++-------
src/lib-index/mail-index-write.c | 14 ++--
src/lib-lda/duplicate.c | 12 +--
src/lib-lda/lmtp-client.c | 19 +++--
src/lib-lda/mail-send.c | 6 +-
src/lib-lda/smtp-client.c | 2 +-
src/lib-master/anvil-client.c | 5 +-
src/lib-master/ipc-client.c | 3 +-
src/lib-master/ipc-server.c | 11 +-
src/lib-master/master-instance.c | 13 +--
src/lib-master/master-login-auth.c | 5 +-
src/lib-master/master-login.c | 3 +-
src/lib-storage/index/cydir/cydir-save.c | 7 +-
src/lib-storage/index/dbox-common/dbox-file-fix.c | 47 +++++++++------
src/lib-storage/index/dbox-common/dbox-file.c | 6 +-
src/lib-storage/index/dbox-common/dbox-save.c | 13 +--
src/lib-storage/index/dbox-multi/mdbox-purge.c | 11 +-
src/lib-storage/index/dbox-single/sdbox-file.c | 5 +-
src/lib-storage/index/imapc/imapc-save.c | 5 +-
src/lib-storage/index/index-attachment.c | 40 +++++-------
src/lib-storage/index/maildir/maildir-save.c | 6 +-
src/lib-storage/index/maildir/maildir-uidlist.c | 18 ++---
src/lib-storage/index/mbox/mbox-save.c | 9 +-
src/lib-storage/index/pop3c/pop3c-client.c | 15 ++--
src/lib-storage/list/subscription-file.c | 8 +-
src/lib/ostream-file.c | 2 +-
src/lib/ostream-private.h | 2 +
src/lib/ostream-rawlog.c | 2 +-
src/lib/ostream.c | 68 +++++++++++++++++++++-
src/lib/ostream.h | 20 ++++++
src/lib/test-ostream-file.c | 6 +-
src/lmtp/client.c | 3 +-
src/lmtp/lmtp-proxy.c | 4 +-
src/login-common/client-common-auth.c | 2 +-
src/login-common/client-common.c | 1 +
src/login-common/login-proxy.c | 3 +-
src/plugins/acl/acl-backend-vfile-acllist.c | 5 +-
src/plugins/acl/acl-backend-vfile.c | 6 +-
src/plugins/fts-squat/squat-trie.c | 25 +++----
src/plugins/fts-squat/squat-uidlist.c | 60 +++++++++----------
src/plugins/imap-quota/imap-quota-plugin.c | 8 +-
src/plugins/zlib/doveadm-zlib.c | 3 +-
src/plugins/zlib/ostream-bzlib.c | 2 +-
src/plugins/zlib/ostream-zlib.c | 2 +-
src/pop3-login/pop3-proxy.c | 10 +-
src/pop3/pop3-client.c | 1 +
src/pop3/pop3-commands.c | 4 +-
src/replication/aggregator/notify-connection.c | 6 +-
src/replication/aggregator/replicator-connection.c | 5 +-
src/replication/replicator/doveadm-connection.c | 5 +-
src/replication/replicator/notify-connection.c | 3 +-
src/replication/replicator/replicator-queue.c | 8 +-
src/ssl-params/main.c | 5 +-
src/stats/client-export.c | 34 +++++-----
src/stats/client.c | 1 +
src/stats/mail-server-connection.c | 3 -
src/util/rawlog.c | 8 +-
104 files changed, 593 insertions(+), 490 deletions(-)
diffs (truncated from 3801 to 300 lines):
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/anvil/anvil-connection.c
--- a/src/anvil/anvil-connection.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/anvil/anvil-connection.c Mon Jun 25 00:01:59 2012 +0300
@@ -90,15 +90,15 @@
return -1;
}
value = connect_limit_lookup(connect_limit, args[0]);
- (void)o_stream_send_str(conn->output,
- t_strdup_printf("%u\n", value));
+ o_stream_nsend_str(conn->output,
+ t_strdup_printf("%u\n", value));
} else if (strcmp(cmd, "PENALTY-GET") == 0) {
if (args[0] == NULL) {
*error_r = "PENALTY-GET: Not enough parameters";
return -1;
}
value = penalty_get(penalty, args[0], &stamp);
- (void)o_stream_send_str(conn->output,
+ o_stream_nsend_str(conn->output,
t_strdup_printf("%u %s\n", value, dec2str(stamp)));
} else if (strcmp(cmd, "PENALTY-INC") == 0) {
if (args[0] == NULL || args[1] == NULL || args[2] == NULL) {
@@ -183,8 +183,10 @@
conn = i_new(struct anvil_connection, 1);
conn->fd = fd;
conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
- if (!fifo)
+ if (!fifo) {
conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
+ o_stream_set_no_error_handling(conn->output, TRUE);
+ }
conn->io = io_add(fd, IO_READ, anvil_connection_input, conn);
conn->master = master;
conn->fifo = fifo;
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/anvil/connect-limit.c
--- a/src/anvil/connect-limit.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/anvil/connect-limit.c Mon Jun 25 00:01:59 2012 +0300
@@ -185,5 +185,5 @@
break;
}
hash_table_iterate_deinit(&iter);
- (void)o_stream_send(output, "\n", 1);
+ o_stream_nsend(output, "\n", 1);
}
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/anvil/penalty.c
--- a/src/anvil/penalty.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/anvil/penalty.c Mon Jun 25 00:01:59 2012 +0300
@@ -268,5 +268,5 @@
if (o_stream_send(output, str_data(str), str_len(str)) < 0)
break;
}
- (void)o_stream_send(output, "\n", 1);
+ o_stream_nsend(output, "\n", 1);
}
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/auth/auth-client-connection.c Mon Jun 25 00:01:59 2012 +0300
@@ -54,7 +54,7 @@
iov[0].iov_len = strlen(cmd);
iov[1].iov_base = "\n";
iov[1].iov_len = 1;
- (void)o_stream_sendv(conn->output, iov, 2);
+ o_stream_nsendv(conn->output, iov, 2);
if (o_stream_get_buffer_used_size(conn->output) >=
OUTBUF_THROTTLE_SIZE) {
@@ -292,8 +292,8 @@
auth_client_connection_unref(&conn);
}
-struct auth_client_connection *
-auth_client_connection_create(struct auth *auth, int fd, bool login_requests)
+void auth_client_connection_create(struct auth *auth, int fd,
+ bool login_requests)
{
static unsigned int connect_uid_counter = 0;
struct auth_client_connection *conn;
@@ -310,6 +310,7 @@
conn->input = i_stream_create_fd(fd, AUTH_CLIENT_MAX_LINE_LENGTH,
FALSE);
conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
+ o_stream_set_no_error_handling(conn->output, TRUE);
o_stream_set_flush_callback(conn->output, auth_client_output, conn);
conn->io = io_add(fd, IO_READ, auth_client_input, conn);
@@ -325,8 +326,6 @@
if (o_stream_send(conn->output, str_data(str), str_len(str)) < 0)
auth_client_disconnected(&conn);
-
- return conn;
}
void auth_client_connection_destroy(struct auth_client_connection **_conn)
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-client-connection.h
--- a/src/auth/auth-client-connection.h Sun Jun 24 21:43:48 2012 +0300
+++ b/src/auth/auth-client-connection.h Mon Jun 25 00:01:59 2012 +0300
@@ -22,8 +22,8 @@
unsigned int version_received:1;
};
-struct auth_client_connection *
-auth_client_connection_create(struct auth *auth, int fd, bool login_requests);
+void auth_client_connection_create(struct auth *auth, int fd,
+ bool login_requests);
void auth_client_connection_destroy(struct auth_client_connection **conn);
struct auth_client_connection *
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/auth/auth-master-connection.c Mon Jun 25 00:01:59 2012 +0300
@@ -87,7 +87,7 @@
iov[1].iov_base = "\n";
iov[1].iov_len = 1;
- (void)o_stream_sendv(conn->output, iov, 2);
+ o_stream_nsendv(conn->output, iov, 2);
}
static bool
@@ -119,19 +119,19 @@
if (client_conn == NULL) {
i_error("Master requested auth for nonexistent client %u",
client_pid);
- (void)o_stream_send_str(conn->output,
- t_strdup_printf("FAIL\t%u\n", id));
+ o_stream_nsend_str(conn->output,
+ t_strdup_printf("FAIL\t%u\n", id));
} else if (memcmp(client_conn->cookie, cookie, sizeof(cookie)) != 0) {
i_error("Master requested auth for client %u with invalid cookie",
client_pid);
- (void)o_stream_send_str(conn->output,
- t_strdup_printf("FAIL\t%u\n", id));
+ o_stream_nsend_str(conn->output,
+ t_strdup_printf("FAIL\t%u\n", id));
} else if (!auth_request_handler_master_request(
client_conn->request_handler, conn, id, client_id)) {
i_error("Master requested auth for non-login client %u",
client_pid);
- (void)o_stream_send_str(conn->output,
- t_strdup_printf("FAIL\t%u\n", id));
+ o_stream_nsend_str(conn->output,
+ t_strdup_printf("FAIL\t%u\n", id));
}
return TRUE;
}
@@ -260,7 +260,7 @@
}
str_append_c(str, '\n');
- (void)o_stream_send(conn->output, str_data(str), str_len(str));
+ o_stream_nsend(conn->output, str_data(str), str_len(str));
auth_request_unref(&auth_request);
auth_master_connection_unref(&conn);
@@ -320,7 +320,7 @@
i_debug("master out: %s", str_c(str));
str_append_c(str, '\n');
- (void)o_stream_send(conn->output, str_data(str), str_len(str));
+ o_stream_nsend(conn->output, str_data(str), str_len(str));
auth_request_unref(&auth_request);
auth_master_connection_unref(&conn);
@@ -446,7 +446,7 @@
str = t_strdup_printf("DONE\t%u\t%s\n",
ctx->auth_request->id,
ctx->failed ? "fail" : "");
- (void)o_stream_send_str(ctx->conn->output, str);
+ o_stream_nsend_str(ctx->conn->output, str);
master_input_list_finish(ctx);
return;
}
@@ -496,7 +496,7 @@
i_error("Auth client doesn't have permissions to list users: %s",
auth_restricted_reason(conn));
str = t_strdup_printf("DONE\t%u\tfail\n", id);
- (void)o_stream_send_str(conn->output, str);
+ o_stream_nsend_str(conn->output, str);
return TRUE;
}
@@ -505,7 +505,7 @@
if (userdb == NULL) {
i_error("Trying to iterate users, but userdbs don't support it");
str = t_strdup_printf("DONE\t%u\tfail\n", id);
- (void)o_stream_send_str(conn->output, str);
+ o_stream_nsend_str(conn->output, str);
return TRUE;
}
@@ -693,6 +693,7 @@
conn->auth = auth;
conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
+ o_stream_set_no_error_handling(conn->output, TRUE);
o_stream_set_flush_callback(conn->output, master_output, conn);
conn->io = io_add(fd, IO_READ, master_input, conn);
conn->userdb_only = userdb_only;
@@ -701,7 +702,7 @@
AUTH_MASTER_PROTOCOL_MAJOR_VERSION,
AUTH_MASTER_PROTOCOL_MINOR_VERSION,
my_pid);
- (void)o_stream_send_str(conn->output, line);
+ o_stream_nsend_str(conn->output, line);
DLLIST_PREPEND(&auth_master_connections, conn);
if (auth_master_connection_set_permissions(conn, socket_st) < 0) {
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-postfix-connection.c
--- a/src/auth/auth-postfix-connection.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/auth/auth-postfix-connection.c Mon Jun 25 00:01:59 2012 +0300
@@ -95,7 +95,7 @@
i_debug("postfix out: %s", str_c(str));
str_append_c(str, '\n');
- (void)o_stream_send(conn->output, str_data(str), str_len(str));
+ o_stream_nsend(conn->output, str_data(str), str_len(str));
i_assert(conn->io == NULL);
if (!conn->destroyed)
@@ -179,6 +179,7 @@
conn->auth = auth;
conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE);
conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
+ o_stream_set_no_error_handling(conn->output, TRUE);
conn->io = io_add(fd, IO_READ, postfix_input, conn);
DLLIST_PREPEND(&auth_postfix_connections, conn);
return conn;
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-worker-client.c
--- a/src/auth/auth-worker-client.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/auth/auth-worker-client.c Mon Jun 25 00:01:59 2012 +0300
@@ -102,8 +102,8 @@
string_t *str)
{
if (worker_restart_request)
- o_stream_send_str(client->output, "RESTART\n");
- o_stream_send(client->output, str_data(str), str_len(str));
+ o_stream_nsend_str(client->output, "RESTART\n");
+ o_stream_nsend(client->output, str_data(str), str_len(str));
}
static void verify_plain_callback(enum passdb_result result,
@@ -464,7 +464,7 @@
T_BEGIN {
str = t_str_new(128);
str_printfa(str, "%u\t*\t%s\n", ctx->auth_request->id, user);
- o_stream_send(ctx->client->output, str_data(str), str_len(str));
+ o_stream_nsend(ctx->client->output, str_data(str), str_len(str));
} T_END;
if (ctx->sending) {
@@ -694,6 +694,7 @@
client->input = i_stream_create_fd(fd, AUTH_WORKER_MAX_LINE_LENGTH,
FALSE);
client->output = o_stream_create_fd(fd, (size_t)-1, FALSE);
+ o_stream_set_no_error_handling(client->output, TRUE);
o_stream_set_flush_callback(client->output, auth_worker_output, client);
client->io = io_add(fd, IO_READ, auth_worker_input, client);
auth_worker_refresh_proctitle(CLIENT_STATE_HANDSHAKE);
@@ -755,7 +756,7 @@
auth_worker_client_error = TRUE;
if (auth_worker_client != NULL &&
!auth_worker_client->error_sent) {
- o_stream_send_str(auth_worker_client->output, "ERROR\n");
+ o_stream_nsend_str(auth_worker_client->output, "ERROR\n");
auth_worker_client->error_sent = TRUE;
}
auth_worker_refresh_proctitle("");
@@ -766,7 +767,7 @@
auth_worker_client_error = FALSE;
if (auth_worker_client != NULL &&
auth_worker_client->error_sent) {
- o_stream_send_str(auth_worker_client->output, "SUCCESS\n");
+ o_stream_nsend_str(auth_worker_client->output, "SUCCESS\n");
auth_worker_client->error_sent = FALSE;
}
auth_worker_refresh_proctitle(CLIENT_STATE_IDLE);
@@ -775,6 +776,6 @@
void auth_worker_client_send_shutdown(void)
{
if (auth_worker_client != NULL)
- o_stream_send_str(auth_worker_client->output, "SHUTDOWN\n");
+ o_stream_nsend_str(auth_worker_client->output, "SHUTDOWN\n");
auth_worker_refresh_proctitle(CLIENT_STATE_STOP);
}
diff -r 3ffdb4bf36d3 -r ca37d1577291 src/auth/auth-worker-server.c
--- a/src/auth/auth-worker-server.c Sun Jun 24 21:43:48 2012 +0300
+++ b/src/auth/auth-worker-server.c Mon Jun 25 00:01:59 2012 +0300
@@ -101,7 +101,7 @@
iov[2].iov_base = "\n";
iov[2].iov_len = 1;
- o_stream_sendv(conn->output, iov, 3);
+ o_stream_nsendv(conn->output, iov, 3);
i_assert(conn->request == NULL);
conn->request = request;
@@ -145,7 +145,7 @@
binary_to_hex_append(str, userdb_md5, sizeof(userdb_md5));
str_append_c(str, '\n');
More information about the dovecot-cvs
mailing list