dovecot-2.0: lib-master: Error handling fixes when reading config.
dovecot at dovecot.org
dovecot at dovecot.org
Sat Feb 20 18:20:24 EET 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/7394d1b828f7
changeset: 10795:7394d1b828f7
user: Timo Sirainen <tss at iki.fi>
date: Sat Feb 20 18:19:32 2010 +0200
description:
lib-master: Error handling fixes when reading config.
diffstat:
src/lib-master/master-service-settings.c | 33 ++++++++++++++++++++++-----------
1 files changed, 22 insertions(+), 11 deletions(-)
diffs (73 lines):
diff -r 68169de12764 -r 7394d1b828f7 src/lib-master/master-service-settings.c
--- a/src/lib-master/master-service-settings.c Sat Feb 20 18:07:18 2010 +0200
+++ b/src/lib-master/master-service-settings.c Sat Feb 20 18:19:32 2010 +0200
@@ -221,8 +221,9 @@
}
static int
-config_read_reply_header(struct istream *input,
- struct master_service_settings_output *output_r)
+config_read_reply_header(struct istream *input, const char *path,
+ struct master_service_settings_output *output_r,
+ const char **error_r)
{
const char *line;
ssize_t ret;
@@ -232,8 +233,14 @@
if (line != NULL)
break;
}
- if (ret <= 0)
- return ret;
+ if (ret <= 0) {
+ if (ret == 0)
+ return 1;
+ *error_r = input->stream_errno != 0 ?
+ t_strdup_printf("read(%s) failed: %m", path) :
+ t_strdup_printf("read(%s) failed: EOF", path);
+ return -1;
+ }
T_BEGIN {
const char *const *arg = t_strsplit(line, "\t");
@@ -249,7 +256,7 @@
output_r->used_remote = TRUE;
}
} T_END;
- return 1;
+ return 0;
}
int master_service_settings_read(struct master_service *service,
@@ -317,11 +324,14 @@
timeout = now + CONFIG_READ_TIMEOUT_SECS;
do {
alarm(timeout - now);
- ret = !config_socket ? 1 :
- config_read_reply_header(istream, output_r);
- if (ret > 0) {
+ ret = !config_socket ? 0 :
+ config_read_reply_header(istream, path,
+ output_r, error_r);
+ if (ret == 0) {
ret = settings_parse_stream_read(parser,
istream);
+ if (ret < 0)
+ *error_r = settings_parser_get_error(parser);
}
alarm(0);
if (ret <= 0)
@@ -335,9 +345,10 @@
i_stream_unref(&istream);
if (ret != 0) {
- *error_r = ret > 0 ? t_strdup_printf(
- "Timeout reading config from %s", path) :
- settings_parser_get_error(parser);
+ if (ret > 0) {
+ *error_r = t_strdup_printf(
+ "Timeout reading config from %s", path);
+ }
(void)close(fd);
return -1;
}
More information about the dovecot-cvs
mailing list