From b02e8b72ab27dde15c25fd2d965dbbeca688ddfa Mon Sep 17 00:00:00 2001 From: Scott Griffy Date: Tue, 2 Sep 2014 12:38:49 -0700 Subject: [PATCH] unfinished solution for #2914 --- src/common/log.c | 4 ++-- src/common/torlog.h | 2 +- src/or/config.c | 3 ++- src/test/test_logging.c | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/log.c b/src/common/log.c index 2e51e5c..14fb50e 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -1011,13 +1011,13 @@ mark_logs_temp(void) */ int add_file_log(const log_severity_list_t *severity, const char *filename, - const int truncate) + const int truncate, const int safeLogging) { int fd; logfile_t *lf; int open_flags = O_WRONLY|O_CREAT; - open_flags |= truncate ? O_TRUNC : O_APPEND; + open_flags |= truncate || !safeLogging ? O_TRUNC : O_APPEND; fd = tor_open_cloexec(filename, open_flags, 0644); if (fd<0) diff --git a/src/common/torlog.h b/src/common/torlog.h index 34e39b4..c8d7ff4 100644 --- a/src/common/torlog.h +++ b/src/common/torlog.h @@ -131,7 +131,7 @@ void set_log_severity_config(int minSeverity, int maxSeverity, void add_stream_log(const log_severity_list_t *severity, const char *name, int fd); int add_file_log(const log_severity_list_t *severity, const char *filename, - const int truncate); + const int truncate, const int safeLog); #ifdef HAVE_SYSLOG_H int add_syslog_log(const log_severity_list_t *severity); #endif diff --git a/src/or/config.c b/src/or/config.c index 7800ec1..2d62ce6 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -4567,7 +4567,8 @@ options_init_logs(const or_options_t *old_options, or_options_t *options, } } } - if (add_file_log(severity, fname, truncate) < 0) { + int safeLog = strcmp(get_options()->SafeLogging, "1") == 0 ? 1 : 0; + if (add_file_log(severity, fname, truncate, safeLog) < 0) { log_warn(LD_CONFIG, "Couldn't open file for 'Log %s': %s", opt->value, strerror(errno)); ok = 0; diff --git a/src/test/test_logging.c b/src/test/test_logging.c index 9f57000..abb6283 100644 --- a/src/test/test_logging.c +++ b/src/test/test_logging.c @@ -89,7 +89,7 @@ test_sigsafe_err(void *arg) init_logging(); mark_logs_temp(); - add_file_log(&include_bug, fn, 0); + add_file_log(&include_bug, fn, 0, 1); // the 0 and 1 are to make sure no logs are truncated tor_log_update_sigsafe_err_fds(); close_temp_logs(); -- 1.7.10.4