[dovecot-cvs] dovecot/src/master log.c,1.7.2.3,1.7.2.4

tss at dovecot.org tss at dovecot.org
Fri Oct 13 18:59:42 UTC 2006


Update of /var/lib/cvs/dovecot/src/master
In directory talvi:/tmp/cvs-serv28916

Modified Files:
      Tag: branch_1_0
	log.c 
Log Message:
Don't crash in log deinitialization.



Index: log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/master/log.c,v
retrieving revision 1.7.2.3
retrieving revision 1.7.2.4
diff -u -d -r1.7.2.3 -r1.7.2.4
--- log.c	11 Oct 2006 12:22:30 -0000	1.7.2.3
+++ log.c	13 Oct 2006 17:59:40 -0000	1.7.2.4
@@ -31,7 +31,7 @@
 static unsigned int throttle_count;
 
 static int log_it(struct log_io *log_io, const char *line, bool continues);
-static void log_read(void *context);
+static int log_read(struct log_io *log_io);
 static void log_throttle_timeout(void *context);
 
 static bool log_write_pending(struct log_io *log_io)
@@ -71,6 +71,13 @@
 		to = timeout_add(1000, log_throttle_timeout, NULL);
 }
 
+static void log_read_callback(void *context)
+{
+	struct log_io *log_io = context;
+
+	(void)log_read(log_io);
+}
+
 static void log_unthrottle(struct log_io *log_io)
 {
 	if (log_io->io != NULL)
@@ -79,7 +86,7 @@
 	if (--throttle_count == 0 && to != NULL)
 		timeout_remove(&to);
 	log_io->io = io_add(i_stream_get_fd(log_io->stream),
-			    IO_READ, log_read, log_io);
+			    IO_READ, log_read_callback, log_io);
 }
 
 static int log_it(struct log_io *log_io, const char *line, bool continues)
@@ -123,23 +130,22 @@
 	return 1;
 }
 
-static void log_read(void *context)
+static int log_read(struct log_io *log_io)
 {
-	struct log_io *log_io = context;
 	const unsigned char *data;
 	const char *line;
 	size_t size;
 	int ret;
 
 	if (!log_write_pending(log_io))
-		return;
+		return 0;
 
 	ret = i_stream_read(log_io->stream);
 	if (ret < 0) {
 		if (ret == -1) {
 			/* closed */
 			log_unref(log_io);
-			return;
+			return -1;
 		}
 
 		/* buffer full. treat it as one line */
@@ -148,14 +154,15 @@
 		i_stream_skip(log_io->stream, size);
 
 		if (!log_it(log_io, line, TRUE))
-			return;
+			return 0;
 	}
 
 	if (!log_write_pending(log_io))
-		return;
+		return 0;
 
 	if (log_io->log_counter < log_io->max_lines_per_sec)
 		log_unthrottle(log_io);
+	return 0;
 }
 
 int log_create_pipe(struct log_io **log_r, unsigned int max_lines_per_sec)
@@ -284,8 +291,8 @@
 		next = log_ios->next;
 		/* do one final log read in case there's still something
 		   waiting */
-		log_read(log_ios);
-		log_unref(log_ios);
+		if (log_read(log_ios) == 0)
+			log_unref(log_ios);
 		log_ios = next;
 	}
 



More information about the dovecot-cvs mailing list