0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-12-04 18:45:52 +00:00
termux-packages/packages/openjdk-17/0014-Fix-libjvm.so-path-when-run-from-Android-app.patch

73 lines
2.9 KiB
Diff

From 6f58e614fff1dfffbe66974c85be32152f1e18c7 Mon Sep 17 00:00:00 2001
From: Duy Tran Khanh <40482367+khanhduytran0@users.noreply.github.com>
Date: Fri, 11 Jun 2021 07:48:28 +0700
Subject: [PATCH] Fix libjvm.so path when run from Android app
---
src/java.base/unix/native/libjli/java_md.c | 49 ++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/src/java.base/unix/native/libjli/java_md.c b/src/java.base/unix/native/libjli/java_md.c
index 503a2457b043..1c1bd6798e8e 100644
--- a/src/java.base/unix/native/libjli/java_md.c
+++ b/src/java.base/unix/native/libjli/java_md.c
@@ -595,6 +595,55 @@ SetExecname(char **argv)
exec_path = JLI_StringDup(buf);
}
}
+#elif defined(__ANDROID__)
+ char *__java_home = getenv("JAVA_HOME");
+ // From http://hg.openjdk.java.net/mobile/jdk9/jdk/file/17bb8a98d5e3/src/java.base/unix/native/libjli/java_md_solinux.c#l844
+ /* For Android, 'self' would point to /system/bin/app_process
+ * since we are really executing a Dalvik program at this point.
+ * argv[0] points to the Dalvik application name and we set the
+ * path to __java_home.
+ */
+ char buf[PATH_MAX+1];
+ char *p = NULL;
+ if ((p = JLI_StrRChr(argv[0], '/')) != 0) {
+ /* may be running from command line */
+ p++;
+ if ((JLI_StrLen(p) == 4) && JLI_StrCmp(p, "java") == 0) {
+ /* started as 'java'. Must be command line */
+ JLI_TraceLauncher("SetExecName maybe command line = %s\n", argv[0]);
+ if (*argv[0] != '/') {
+ char *curdir = NULL;
+ /* get absolute path */
+ getcwd(buf, PATH_MAX);
+ curdir = JLI_StringDup(buf);
+ JLI_Snprintf(buf, PATH_MAX, "%s/%s", curdir, argv[0]);
+ JLI_MemFree(curdir);
+ } else {
+ JLI_Snprintf(buf, PATH_MAX, "%s", argv[0]);
+ }
+ } else {
+ /* Not command line, see if __java_home set */
+ if (__java_home != NULL) {
+ JLI_TraceLauncher("SetExecName not java = %s\n", __java_home);
+ JLI_Snprintf(buf, PATH_MAX, "%s/bin/java", __java_home);
+ } else {
+ /* Fake it as best we can or should we punt? */
+ JLI_TraceLauncher("SetExecName fake it = %s\n", argv[0]);
+ JLI_Snprintf(buf, PATH_MAX, "@TERMUX_PREFIX@/bin/java");
+ }
+ }
+ } else {
+ /* Not started as 'java', see if __java_home set */
+ if (__java_home != NULL) {
+ JLI_TraceLauncher("SetExecName not command line = %s\n", __java_home);
+ JLI_Snprintf(buf, PATH_MAX, "%s/bin/java", __java_home);
+ } else {
+ /* Fake it as best we can or should we punt? */
+ JLI_TraceLauncher("SetExecName fake it 2 = %s\n", argv[0]);
+ JLI_Snprintf(buf, PATH_MAX, "@TERMUX_PREFIX@/bin/java");
+ }
+ }
+ exec_path = JLI_StringDup(buf);
#else /* !__linux__ */
{
/* Not implemented */
--
2.44.0