dovecot-2.2: stats: Don't log write()=EPIPE failures. Retry open...
dovecot at dovecot.org
dovecot at dovecot.org
Sun May 20 03:26:26 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/315f0d8cc2b2
changeset: 14297:315f0d8cc2b2
user: Timo Sirainen <tss at iki.fi>
date: Mon Mar 05 19:33:51 2012 +0200
description:
stats: Don't log write()=EPIPE failures. Retry opening the pipe once.
diffstat:
src/plugins/stats/stats-connection.c | 36 +++++++++++++++++++++++++++---------
1 files changed, 27 insertions(+), 9 deletions(-)
diffs (70 lines):
diff -r 721e127e107f -r 315f0d8cc2b2 src/plugins/stats/stats-connection.c
--- a/src/plugins/stats/stats-connection.c Mon Mar 05 18:44:01 2012 +0200
+++ b/src/plugins/stats/stats-connection.c Mon Mar 05 19:33:51 2012 +0200
@@ -14,8 +14,24 @@
int fd;
char *path;
+
+ bool open_failed;
};
+static bool stats_connection_open(struct stats_connection *conn)
+{
+ if (conn->open_failed)
+ return FALSE;
+
+ conn->fd = open(conn->path, O_WRONLY);
+ if (conn->fd == -1) {
+ i_error("stats: open(%s) failed: %m", conn->path);
+ conn->open_failed = TRUE;
+ return FALSE;
+ }
+ return TRUE;
+}
+
struct stats_connection *
stats_connection_create(const char *path)
{
@@ -24,9 +40,7 @@
conn = i_new(struct stats_connection, 1);
conn->refcount = 1;
conn->path = i_strdup(path);
- conn->fd = open(path, O_WRONLY);
- if (conn->fd == -1)
- i_error("stats: open(%s) failed: %m", path);
+ stats_connection_open(conn);
return conn;
}
@@ -57,8 +71,10 @@
static bool pipe_warned = FALSE;
ssize_t ret;
- if (conn->fd == -1)
- return;
+ if (conn->fd == -1) {
+ if (!stats_connection_open(conn))
+ return;
+ }
if (str_len(str) > PIPE_BUF && !pipe_warned) {
i_warning("stats update sent more bytes that PIPE_BUF "
@@ -69,11 +85,13 @@
ret = write(conn->fd, str_data(str), str_len(str));
if (ret != (ssize_t)str_len(str)) {
- if (ret < 0)
- i_error("write(%s) failed: %m", conn->path);
- else if ((size_t)ret != str_len(str))
+ if (ret < 0) {
+ /* don't log EPIPE errors. they can happen when
+ Dovecot is stopped. */
+ if (errno != EPIPE)
+ i_error("write(%s) failed: %m", conn->path);
+ } else if ((size_t)ret != str_len(str))
i_error("write(%s) wrote partial update", conn->path);
- /* this shouldn't happen, just stop sending updates */
if (close(conn->fd) < 0)
i_error("close(%s) failed: %m", conn->path);
conn->fd = -1;
More information about the dovecot-cvs
mailing list