diff options
author | Andy Getzendanner <durandal@google.com> | 2022-05-04 20:58:05 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-05-04 20:58:54 -0700 |
commit | 173dfe4a4c70f294a512aae4d0d0f5fc7db39241 (patch) | |
tree | 69713a45f8fb1ad3874a0f7e1e0a50b40f7d001a /absl/base/internal/raw_logging.cc | |
parent | e8cda74967d1fa43182f88396e9030e93501e1a1 (diff) |
raw_logging: Rename SafeWriteToStderr to indicate what about it is safe (answer: it's async-signal-safe).
Also, preserve errno across calls to make it actually signal-safe.
PiperOrigin-RevId: 446620926
Change-Id: I875fbec02b909e8424ddf763303b0d6007f8548f
Diffstat (limited to 'absl/base/internal/raw_logging.cc')
-rw-r--r-- | absl/base/internal/raw_logging.cc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/absl/base/internal/raw_logging.cc b/absl/base/internal/raw_logging.cc index acf20f2a..ca2a75f3 100644 --- a/absl/base/internal/raw_logging.cc +++ b/absl/base/internal/raw_logging.cc @@ -24,6 +24,7 @@ #include "absl/base/attributes.h" #include "absl/base/config.h" #include "absl/base/internal/atomic_hook.h" +#include "absl/base/internal/errno_saver.h" #include "absl/base/log_severity.h" // We know how to perform low-level writes to stderr in POSIX and Windows. For @@ -169,7 +170,7 @@ void RawLogVA(absl::LogSeverity severity, const char* file, int line, } else { DoRawLog(&buf, &size, "%s", kTruncated); } - SafeWriteToStderr(buffer, strlen(buffer)); + AsyncSignalSafeWriteToStderr(buffer, strlen(buffer)); } #else static_cast<void>(format); @@ -196,8 +197,11 @@ void DefaultInternalLog(absl::LogSeverity severity, const char* file, int line, } // namespace -void SafeWriteToStderr(const char *s, size_t len) { +void AsyncSignalSafeWriteToStderr(const char* s, size_t len) { + absl::base_internal::ErrnoSaver errno_saver; #if defined(ABSL_HAVE_SYSCALL_WRITE) + // We prefer calling write via `syscall` to minimize the risk of libc doing + // something "helpful". syscall(SYS_write, STDERR_FILENO, s, len); #elif defined(ABSL_HAVE_POSIX_WRITE) write(STDERR_FILENO, s, len); |