r869 - trunk/varnish-cache/bin/varnishlog

des at projects.linpro.no des at projects.linpro.no
Mon Aug 21 14:57:32 CEST 2006


Author: des
Date: 2006-08-21 14:57:32 +0200 (Mon, 21 Aug 2006)
New Revision: 869

Modified:
   trunk/varnish-cache/bin/varnishlog/varnishlog.c
Log:
When writing to a file, open it with O_APPEND rather than O_TRUNC.

Modified: trunk/varnish-cache/bin/varnishlog/varnishlog.c
===================================================================
--- trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-08-21 12:55:56 UTC (rev 868)
+++ trunk/varnish-cache/bin/varnishlog/varnishlog.c	2006-08-21 12:57:32 UTC (rev 869)
@@ -4,12 +4,13 @@
  * Log tailer for Varnish
  */
 
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
+#include <fcntl.h>
+#include <regex.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
-#include <regex.h>
 
 #include "compat/vis.h"
 
@@ -175,36 +176,25 @@
 static void
 do_write(struct VSL_data *vd, const char *w_opt)
 {
-	FILE *wfile = NULL;
-	unsigned u;
-	int i;
+	int fd, i;
 	unsigned char *p;
 
 	if (!strcmp(w_opt, "-"))
-		wfile = stdout;
+		fd = STDOUT_FILENO;
 	else
-		wfile = fopen(w_opt, "w");
-	if (wfile == NULL) {
+		fd = open(w_opt, O_WRONLY|O_APPEND|O_CREAT, 0644);
+	if (fd < 0) {
 		perror(w_opt);
 		exit (1);
 	}
-	u = 0;
 	while (1) {
 		i = VSL_NextLog(vd, &p);
 		if (i < 0)
 			break;
-		if (i == 0) {
-			fflush(wfile);
-			fprintf(stderr, "\nFlushed\n");
-		} else {
-			i = fwrite(p, 5 + p[1], 1, wfile);
+		if (i > 0) {
+			i = write(fd, p, 5 + p[1]);
 			if (i != 1)
 				perror(w_opt);
-			u++;
-			if (!(u % 1000)) {
-				fprintf(stderr, "%u\r", u);
-				fflush(stderr);
-			}
 		}
 	}
 	exit (0);




More information about the varnish-commit mailing list