From c9b9c390d26a1c609923bd69aa9290896d3dbcc1 Mon Sep 17 00:00:00 2001 From: des Date: Mon, 21 Aug 2006 12:57:32 +0000 Subject: [PATCH] When writing to a file, open it with O_APPEND rather than O_TRUNC. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@869 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishlog/varnishlog.c | 30 ++++++++--------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/varnish-cache/bin/varnishlog/varnishlog.c b/varnish-cache/bin/varnishlog/varnishlog.c index 10395da9..b6cacba7 100644 --- a/varnish-cache/bin/varnishlog/varnishlog.c +++ b/varnish-cache/bin/varnishlog/varnishlog.c @@ -4,12 +4,13 @@ * Log tailer for Varnish */ -#include #include -#include +#include +#include +#include #include +#include #include -#include #include "compat/vis.h" @@ -175,36 +176,25 @@ do_order(struct VSL_data *vd, int argc, char **argv) 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); -- 2.39.5