summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichail Kashkarov <m.kashkarov@partner.samsung.com>2017-10-17 14:20:57 +0300
committerMichail Kashkarov <m.kashkarov@partner.samsung.com>2017-10-17 15:04:06 +0300
commit25c255d16df5d81cc0774f02efa6e2ac24a3252e (patch)
treeaf0fe6f259143dec793bc13b4f3ec5b2a6803751
parent758ac241fbead9ab3bd6803512765b1af0573a35 (diff)
downloadlinaro-gcc-sandbox/mkashkarov/lsan_periodical_check_v2.tar.gz
linaro-gcc-sandbox/mkashkarov/lsan_periodical_check_v2.tar.bz2
linaro-gcc-sandbox/mkashkarov/lsan_periodical_check_v2.zip
Refactor, add O_TRUNC for opening file.sandbox/mkashkarov/lsan_periodical_check_v2
Change-Id: I5b8f9f47bbc1f2bc477a603873f045615ef14334
-rw-r--r--libsanitizer/lsan/lsan_common.cc31
-rw-r--r--libsanitizer/sanitizer_common/sanitizer_posix.cc2
2 files changed, 17 insertions, 16 deletions
diff --git a/libsanitizer/lsan/lsan_common.cc b/libsanitizer/lsan/lsan_common.cc
index e8a72b9f34c..5b9cf9b9312 100644
--- a/libsanitizer/lsan/lsan_common.cc
+++ b/libsanitizer/lsan/lsan_common.cc
@@ -490,6 +490,12 @@ static bool CheckForLeaks() {
return false;
}
+void MaybeRestoreLogPath() {
+ if (flags()->periodically_check_leaks ||
+ flags()->periodically_check_leaks_interval_ms)
+ __sanitizer_set_report_path(common_flags()->log_path);
+}
+
void DoLeakCheck() {
VReport(2, "[LSAN] DoLeakCheck\n");
BlockingMutexLock l(&global_mutex);
@@ -497,9 +503,7 @@ void DoLeakCheck() {
if (already_done) return;
already_done = true;
// Log path is modified if periodically checking for leaks
- if (flags()->periodically_check_leaks ||
- flags()->periodically_check_leaks_interval_ms)
- __sanitizer_set_report_path(common_flags()->log_path);
+ MaybeRestoreLogPath();
bool have_leaks = CheckForLeaks();
if (!have_leaks) {
return;
@@ -520,23 +524,20 @@ void DoRecoverableLeakCheckVoid() {
DoRecoverableLeakCheck();
}
-void LogPathAppend(const char* suffix) {
- if (!common_flags()->log_path) return;
+void MaybeAppendLogPath(const char* suffix) {
+ const char* log_path = common_flags()->log_path;
+ if (!log_path) return;
+ if ((internal_strcmp(log_path, "stderr") == 0) ||
+ (internal_strcmp(log_path, "stdout") == 0)) return;
+
char new_log_path[kMaxPathLength];
- internal_strlcat(new_log_path, common_flags()->log_path, kMaxPathLength);
- internal_strlcat(new_log_path, suffix, kMaxPathLength);
- __sanitizer_set_report_path(log_path_in_progress);
+ internal_snprintf(new_log_path, kMaxPathLength, "%s.%s", log_path, suffix);
+ __sanitizer_set_report_path(new_log_path);
}
void BackgroudLeakCheckingThread(void *arg) {
s32 interval_ms = flags()->periodically_check_leaks_interval_ms;
- // Append suffix to indicate leaks from this thread
- char log_path_in_progress[kMaxPathLength];
- const char* log_path_prefix = "-in-progress";
- internal_strlcat(log_path_in_progress, common_flags()->log_path, sizeof(log_path_in_progress));
- internal_strlcat(log_path_in_progress, log_path_prefix, sizeof(log_path_in_progress));
- __sanitizer_set_report_path(log_path_in_progress);
- // LogPathAppend()
+ MaybeAppendLogPath("in-progress");
while (true) {
SleepForMillis(interval_ms);
if (!lsan_check_in_progress)
diff --git a/libsanitizer/sanitizer_common/sanitizer_posix.cc b/libsanitizer/sanitizer_common/sanitizer_posix.cc
index eccbdf6b1fd..1a24cb60d58 100644
--- a/libsanitizer/sanitizer_common/sanitizer_posix.cc
+++ b/libsanitizer/sanitizer_common/sanitizer_posix.cc
@@ -208,7 +208,7 @@ fd_t OpenFile(const char *filename, FileAccessMode mode, error_t *errno_p) {
int flags;
switch (mode) {
case RdOnly: flags = O_RDONLY; break;
- case WrOnly: flags = O_WRONLY | O_CREAT; break;
+ case WrOnly: flags = O_WRONLY | O_CREAT | O_TRUNC; break;
case RdWr: flags = O_RDWR | O_CREAT; break;
}
fd_t res = internal_open(filename, flags, 0660);