summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-11-02 09:23:36 +0000
committerAlexey Samsonov <samsonov@google.com>2012-11-02 09:23:36 +0000
commitac8564e7ce11e31b1d29e92dbbcfa1a5d36bc596 (patch)
treeacd0de55e1439f2699c5b8c7ad5518d9cedee36c /lib
parentea0177e2b8bb5d1dbd22c7e2776f6299fa712799 (diff)
downloadcompiler-rt-ac8564e7ce11e31b1d29e92dbbcfa1a5d36bc596.tar.gz
compiler-rt-ac8564e7ce11e31b1d29e92dbbcfa1a5d36bc596.tar.bz2
compiler-rt-ac8564e7ce11e31b1d29e92dbbcfa1a5d36bc596.tar.xz
[Sanitizer]: add __sanitizer_set_report_fd function to alter file descriptor for error reports
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@167290 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/sanitizer_common/sanitizer_common.cc16
1 files changed, 15 insertions, 1 deletions
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index 614b7b9d..e6526f52 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -16,7 +16,9 @@
namespace __sanitizer {
-static fd_t report_fd = 2; // By default, dump to stderr.
+// By default, dump to stderr. If report_fd is kInvalidFd, try to obtain file
+// descriptor by opening file in report_path.
+static fd_t report_fd = 2;
static char report_path[4096]; // Set via __sanitizer_set_report_path.
static void (*DieCallback)(void);
@@ -138,6 +140,10 @@ void SortArray(uptr *array, uptr size) {
} // namespace __sanitizer
+using namespace __sanitizer; // NOLINT
+
+extern "C" {
+
void __sanitizer_set_report_path(const char *path) {
if (!path) return;
uptr len = internal_strlen(path);
@@ -151,3 +157,11 @@ void __sanitizer_set_report_path(const char *path) {
sizeof(__sanitizer::report_path), "%s.%d", path, GetPid());
__sanitizer::report_fd = kInvalidFd;
}
+
+void __sanitizer_set_report_fd(int fd) {
+ if (__sanitizer::report_fd > 2 && __sanitizer::report_fd != kInvalidFd)
+ internal_close(__sanitizer::report_fd);
+ __sanitizer::report_fd = fd;
+}
+
+} // extern "C"