Mercurial > wflogs-daemon
comparison src/wflogs-config.cpp @ 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 | 37eace15ef87 |
children | 306059d0f677 |
comparison
equal
deleted
inserted
replaced
5:efe0b291233a | 6:a043b7d7269c |
---|---|
75 | 75 |
76 | 76 |
77 void CONTEXT::openo(bool msg) { | 77 void CONTEXT::openo(bool msg) { |
78 open_time = time(NULL); | 78 open_time = time(NULL); |
79 localtime_r(&open_time, &open_tm); | 79 localtime_r(&open_time, &open_tm); |
80 fdo = ::open(tempin, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | 80 int flags = O_CREAT | O_WRONLY; |
81 if (!msg) flags |= O_TRUNC; | |
82 fdo = ::open(tempin, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); | |
81 if (fdo == -1) { | 83 if (fdo == -1) { |
82 if (msg) { | 84 if (msg) { |
83 char buf[maxlen]; | 85 char buf[maxlen]; |
84 snprintf(buf, sizeof(buf), "wflogs tempin file %s not writeable", tempin); | 86 snprintf(buf, sizeof(buf), "wflogs tempin file %s not writeable", tempin); |
85 tokp->token_error(buf); | 87 tokp->token_error(buf); |
108 } | 110 } |
109 if (msg) lseek(fd, 0, SEEK_END); | 111 if (msg) lseek(fd, 0, SEEK_END); |
110 if (fstat(fd, &openfdstat)) { | 112 if (fstat(fd, &openfdstat)) { |
111 close(); | 113 close(); |
112 snprintf(buf, sizeof(buf), "syslog file %s cannot stat after open", fn); | 114 snprintf(buf, sizeof(buf), "syslog file %s cannot stat after open", fn); |
113 tokp->token_error(buf); | 115 if (msg) tokp->token_error(buf); |
114 } | 116 } |
115 // specify that this fd gets closed on exec, so that wflogs | 117 // specify that this fd gets closed on exec, so that wflogs |
116 // won't have access to it. | 118 // won't have access to it. |
117 int oldflags = fcntl(fd, F_GETFD, 0); | 119 int oldflags = fcntl(fd, F_GETFD, 0); |
118 if (oldflags >= 0) { | 120 if (oldflags >= 0) { |