[dovecot-cvs] dovecot/src/imap rawlog.c,1.2,1.3

cras at procontrol.fi cras at procontrol.fi
Thu Nov 7 05:28:50 EET 2002


Update of /home/cvs/dovecot/src/imap
In directory danu:/tmp/cvs-serv19764

Modified Files:
	rawlog.c 
Log Message:
Print timestamp marks into rawlog.



Index: rawlog.c
===================================================================
RCS file: /home/cvs/dovecot/src/imap/rawlog.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- rawlog.c	6 Nov 2002 13:06:56 -0000	1.2
+++ rawlog.c	7 Nov 2002 03:28:48 -0000	1.3
@@ -15,15 +15,31 @@
 #include <sys/stat.h>
 #include <sys/socket.h>
 
+#define TIMESTAMP_WAIT_TIME 5
+#define TIMESTAMP_FORMAT " * OK [RAWLOG TIMESTAMP] %Y-%m-%d %H:%M:%S\n"
+
 static IOLoop ioloop;
 static int client_in, client_out, imap_in, imap_out;
 static int log_in, log_out;
 
+static time_t last_write = 0;
+static int last_lf = TRUE;
+
 static void copy(int in, int out, int log)
 {
+	struct tm *tm;
 	char buf[1024];
 	ssize_t r_ret, s_ret;
 
+	if (last_lf && ioloop_time - last_write > TIMESTAMP_WAIT_TIME) {
+		tm = localtime(&ioloop_time);
+
+		if (strftime(buf, sizeof(buf), TIMESTAMP_FORMAT, tm) <= 0)
+			i_fatal("strftime() failed");
+		if (write_full(log, buf, strlen(buf)) < 0)
+			i_fatal("Can't write to log file: %m");
+	}
+
 	net_set_nonblock(in, TRUE);
 	r_ret = read(in, buf, sizeof(buf));
 	if (r_ret <= 0) {
@@ -35,6 +51,7 @@
 		return;
 	}
 
+	last_lf = buf[r_ret-1] == '\n';
 	if (write_full(log, buf, r_ret) < 0)
 		i_fatal("Can't write to log file: %m");
 
@@ -51,6 +68,8 @@
 		}
 		r_ret -= s_ret;
 	} while (r_ret > 0);
+
+	last_write = time(NULL);
 }
 
 static void imap_input(void *context __attr_unused__, int fd __attr_unused__,




More information about the dovecot-cvs mailing list