diff options
author | Arlo Breault <arlolra@gmail.com> | 2014-03-23 09:24:26 -0700 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-07-16 12:16:49 +0200 |
commit | 15e170e01b3f67325f952d0becda0438fa879907 (patch) | |
tree | 3c9f235db67491c0708a5fccfaf34cfa95ce548b /src/common/log.c | |
parent | 98541f2892335a5a512a6c01b2f2227bde1d649e (diff) | |
download | tor-15e170e01b3f67325f952d0becda0438fa879907.tar.gz tor-15e170e01b3f67325f952d0becda0438fa879907.zip |
Add an option to overwrite logs
* Issue #5583
Diffstat (limited to 'src/common/log.c')
-rw-r--r-- | src/common/log.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/common/log.c b/src/common/log.c index 517fa4faaa..7c8a48746a 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -1010,12 +1010,16 @@ mark_logs_temp(void) * logfile fails, -1 is returned and errno is set appropriately (by open(2)). */ int -add_file_log(const log_severity_list_t *severity, const char *filename) +add_file_log(const log_severity_list_t *severity, const char *filename, + const int truncate) { int fd; logfile_t *lf; - fd = tor_open_cloexec(filename, O_WRONLY|O_CREAT|O_APPEND, 0644); + int open_flags = O_WRONLY|O_CREAT; + open_flags |= truncate ? O_TRUNC : O_APPEND; + + fd = tor_open_cloexec(filename, open_flags, 0644); if (fd<0) return -1; if (tor_fd_seekend(fd)<0) { @@ -1297,3 +1301,10 @@ switch_logs_debug(void) UNLOCK_LOGS(); } +/** Truncate all the log files. */ +void +truncate_logs(void) +{ + for (logfile_t *lf = logfiles; lf; lf = lf->next) + ftruncate(lf->fd, 0); +} |