Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c6faa6b9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Allow redirecting log to console" into main

parents 7dc33f35 60e30510
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -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);