diff options
| author | 2024-11-01 18:43:17 +0000 | |
|---|---|---|
| committer | 2024-11-01 18:43:17 +0000 | |
| commit | 5ea4fb77036d408058dd32f15ba57fcce7b91c5e (patch) | |
| tree | 2119874306ad030ce8a1835fccd1e637d4dc379a | |
| parent | 9e0155fb4119be3a7f0cbd782c674ce1dad61fc1 (diff) | |
| parent | c6faa6b9794e873c2aeabf263d8929b534e21ad4 (diff) | |
Merge "Allow redirecting log to console" into main am: c6faa6b979
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/3328587
Change-Id: Iebd773ebb030c003d83fcf7b4a115e7d440b9bcf
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
| -rw-r--r-- | ravenwood/runtime-jni/ravenwood_runtime.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ravenwood/runtime-jni/ravenwood_runtime.cpp b/ravenwood/runtime-jni/ravenwood_runtime.cpp index 3ff08483c956..2a3c26ed3ea3 100644 --- a/ravenwood/runtime-jni/ravenwood_runtime.cpp +++ b/ravenwood/runtime-jni/ravenwood_runtime.cpp @@ -173,6 +173,24 @@ static void Linux_setenv(JNIEnv* env, jobject, jstring javaName, jstring javaVal throwIfMinusOne(env, "setenv", setenv(name.c_str(), value.c_str(), overwrite ? 1 : 0)); } +static void maybeRedirectLog() { + auto ravenwoodLogOut = getenv("RAVENWOOD_LOG_OUT"); + if (ravenwoodLogOut == NULL) { + return; + } + ALOGI("RAVENWOOD_LOG_OUT set. Redirecting output to %s", ravenwoodLogOut); + + // Redirect stdin / stdout to /dev/tty. + int ttyFd = open(ravenwoodLogOut, O_WRONLY); + if (ttyFd == -1) { + ALOGW("$RAVENWOOD_LOG_OUT is set to %s, but failed to open: %s ", ravenwoodLogOut, + strerror(errno)); + return; + } + dup2(ttyFd, 1); + dup2(ttyFd, 2); +} + // ---- Registration ---- extern void register_android_system_OsConstants(JNIEnv* env); @@ -192,6 +210,8 @@ static const JNINativeMethod sMethods[] = }; extern "C" jint JNI_OnLoad(JavaVM* vm, void* /* reserved */) { + maybeRedirectLog(); + ALOGI("%s: JNI_OnLoad", __FILE__); JNIEnv* env = GetJNIEnvOrDie(vm); |