summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-06-06 12:54:41 -0700
committerElliott Hughes <enh@google.com>2018-06-06 12:54:41 -0700
commit11a64eb0e8753a210c678a2e2ec32e95298b8ac2 (patch)
tree04019da3c0b3f79d360ff9bd27f125e1f0fe4007 /base
parentd580c441ab45a6b7278da003e19af64e9ea2cc71 (diff)
downloadsystem_core-11a64eb0e8753a210c678a2e2ec32e95298b8ac2.tar.gz
system_core-11a64eb0e8753a210c678a2e2ec32e95298b8ac2.tar.bz2
system_core-11a64eb0e8753a210c678a2e2ec32e95298b8ac2.zip
libbase: fix libbase_test.logging.StdioLogger.
I don't think the StdioLogger test ever passed. Move GetFileBasename to where we can use it from StdioLogger, and undo the mix of anonymous namespace vs static to consistently use static (which is the majority) while we're touching those lines. Bug: N/A Test: ran tests Change-Id: I95b3966cdb8af642bed71752bd7d4e3a86ac84ca
Diffstat (limited to 'base')
-rw-r--r--base/logging.cpp51
1 files changed, 25 insertions, 26 deletions
diff --git a/base/logging.cpp b/base/logging.cpp
index 978d56d07..35054ac82 100644
--- a/base/logging.cpp
+++ b/base/logging.cpp
@@ -58,13 +58,15 @@
#include <android-base/strings.h>
#include <android-base/threads.h>
-namespace {
+namespace android {
+namespace base {
+
+// BSD-based systems like Android/macOS have getprogname(). Others need us to provide one.
+#if defined(__GLIBC__) || defined(_WIN32)
+static const char* getprogname() {
#if defined(__GLIBC__)
-const char* getprogname() {
return program_invocation_short_name;
-}
#elif defined(_WIN32)
-const char* getprogname() {
static bool first = true;
static char progname[MAX_PATH] = {};
@@ -81,11 +83,28 @@ const char* getprogname() {
}
return progname;
+#endif
}
#endif
+static const char* GetFileBasename(const char* file) {
+ // We can't use basename(3) even on Unix because the Mac doesn't
+ // have a non-modifying basename.
+ const char* last_slash = strrchr(file, '/');
+ if (last_slash != nullptr) {
+ return last_slash + 1;
+ }
+#if defined(_WIN32)
+ const char* last_backslash = strrchr(file, '\\');
+ if (last_backslash != nullptr) {
+ return last_backslash + 1;
+ }
+#endif
+ return file;
+}
+
#if defined(__linux__)
-int OpenKmsg() {
+static int OpenKmsg() {
#if defined(__ANDROID__)
// pick up 'file w /dev/kmsg' environment from daemon's init rc file
const auto val = getenv("ANDROID_FILE__dev_kmsg");
@@ -100,10 +119,6 @@ int OpenKmsg() {
return TEMP_FAILURE_RETRY(open("/dev/kmsg", O_WRONLY | O_CLOEXEC));
}
#endif
-} // namespace
-
-namespace android {
-namespace base {
static std::mutex& LoggingLock() {
static auto& logging_lock = *new std::mutex();
@@ -216,7 +231,7 @@ void StdioLogger(LogId, LogSeverity severity, const char* /*tag*/, const char* /
unsigned int /*line*/, const char* message) {
if (severity >= WARNING) {
fflush(stdout);
- fprintf(stderr, "%s: %s\n", getprogname(), message);
+ fprintf(stderr, "%s: %s\n", GetFileBasename(getprogname()), message);
} else {
fprintf(stdout, "%s\n", message);
}
@@ -336,22 +351,6 @@ void SetAborter(AbortFunction&& aborter) {
Aborter() = std::move(aborter);
}
-static const char* GetFileBasename(const char* file) {
- // We can't use basename(3) even on Unix because the Mac doesn't
- // have a non-modifying basename.
- const char* last_slash = strrchr(file, '/');
- if (last_slash != nullptr) {
- return last_slash + 1;
- }
-#if defined(_WIN32)
- const char* last_backslash = strrchr(file, '\\');
- if (last_backslash != nullptr) {
- return last_backslash + 1;
- }
-#endif
- return file;
-}
-
// This indirection greatly reduces the stack impact of having lots of
// checks/logging in a function.
class LogMessageData {