xref: /freebsd/contrib/llvm-project/libcxx/src/experimental/log_hardening_failure.cpp (revision e64bea71c21eb42e97aa615188ba91f6cce0d36d)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include <__config>
10 #include <__log_hardening_failure>
11 #include <cstdio>
12 
13 #ifdef __BIONIC__
14 #  include <syslog.h>
15 #endif // __BIONIC__
16 
17 _LIBCPP_BEGIN_NAMESPACE_STD
18 
__log_hardening_failure(const char * message)19 void __log_hardening_failure(const char* message) noexcept {
20   // Always log the message to `stderr` in case the platform-specific system calls fail.
21   std::fputs(message, stderr);
22 
23 #if defined(__BIONIC__)
24   // Show error in logcat. The latter two arguments are ignored on Android.
25   openlog("libc++", 0, 0);
26   syslog(LOG_CRIT, "%s", message);
27   closelog();
28 #endif
29 }
30 
31 _LIBCPP_END_NAMESPACE_STD
32