dovecot: If EOF is triggered with keyboard (^D), make sure to re...

dovecot at dovecot.org dovecot at dovecot.org
Fri Jan 25 13:36:39 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/febb2592e616
changeset: 7188:febb2592e616
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Jan 25 13:36:35 2008 +0200
description:
If EOF is triggered with keyboard (^D), make sure to return EOF for future
reads as well.

diffstat:

1 file changed, 7 insertions(+)
src/lib/istream-file.c |    7 +++++++

diffs (38 lines):

diff -r d9b87e3ce6c8 -r febb2592e616 src/lib/istream-file.c
--- a/src/lib/istream-file.c	Tue Jan 22 09:33:40 2008 +0200
+++ b/src/lib/istream-file.c	Fri Jan 25 13:36:35 2008 +0200
@@ -18,6 +18,7 @@ struct file_istream {
 
 	unsigned int file:1;
 	unsigned int autoclose_fd:1;
+	unsigned int seen_eof:1;
 };
 
 static void i_stream_file_close(struct iostream_private *stream)
@@ -54,6 +55,10 @@ static ssize_t i_stream_file_read(struct
 			ret = pread(stream->fd, stream->w_buffer + stream->pos,
 				    size, stream->istream.v_offset +
 				    (stream->pos - stream->skip));
+		} else if (fstream->seen_eof) {
+			/* don't try to read() again. EOF from keyboard (^D)
+			   requires this to work right. */
+			ret = 0;
 		} else {
 			ret = read(stream->fd, stream->w_buffer + stream->pos,
 				   size);
@@ -64,6 +69,7 @@ static ssize_t i_stream_file_read(struct
 	if (ret == 0) {
 		/* EOF */
 		stream->istream.eof = TRUE;
+		fstream->seen_eof = TRUE;
 		return -1;
 	}
 
@@ -114,6 +120,7 @@ static void i_stream_file_seek(struct is
 	stream->istream.stream_errno = 0;
 	stream->istream.v_offset = v_offset;
 	stream->skip = stream->pos = 0;
+	fstream->seen_eof = FALSE;
 }
 
 static void i_stream_file_sync(struct istream_private *stream)


More information about the dovecot-cvs mailing list