changeset 6:a043b7d7269c

truncate output files after processing them
author Carl Byington <carl@five-ten-sg.com>
date Fri, 17 May 2013 12:22:33 -0700
parents efe0b291233a
children d5bb92a8ea25
files src/wflogs-config.cpp
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/wflogs-config.cpp	Fri May 17 12:06:21 2013 -0700
+++ b/src/wflogs-config.cpp	Fri May 17 12:22:33 2013 -0700
@@ -77,7 +77,9 @@
 void CONTEXT::openo(bool msg) {
     open_time = time(NULL);
     localtime_r(&open_time, &open_tm);
-    fdo = ::open(tempin, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+    int flags = O_CREAT | O_WRONLY;
+    if (!msg) flags |= O_TRUNC;
+    fdo = ::open(tempin, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
     if (fdo == -1) {
         if (msg) {
             char buf[maxlen];
@@ -110,7 +112,7 @@
         if (fstat(fd, &openfdstat)) {
             close();
             snprintf(buf, sizeof(buf), "syslog file %s cannot stat after open", fn);
-            tokp->token_error(buf);
+            if (msg) tokp->token_error(buf);
         }
         // specify that this fd gets closed on exec, so that wflogs
         // won't have access to it.