. Using dladdr(3) to determine the path to the current executable, and
hence the path for the shared libraries doesn't always work on FreeBSD. It definitely fails on FreeBSD 4.11 and FreeBSD 6-CURRENT under the tested environments. In fact, the dladdr(3) man page even warns of these problems. While there is work under way to fix this, it isn't available yet. Given that situation, switch to trying /proc/curproc/file, which is similar to what Linux does, and if that fails, drop back to checking argv[0] and iterating through $PATH as in jdk 1.4. Both these methods work correctly in testing. Reported by: das Reviewed by: maintainer timeout
This commit is contained in:
parent
f52838c044
commit
60df7b3098
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=135100
62
java/jdk15/files/patch-j2se-bin-java_md.c
Normal file
62
java/jdk15/files/patch-j2se-bin-java_md.c
Normal file
@ -0,0 +1,62 @@
|
||||
$FreeBSD$
|
||||
|
||||
--- ../../j2se/src/solaris/bin/java_md.c 15 Feb 2005 02:06:26 -0000 1.6
|
||||
+++ ../../j2se/src/solaris/bin/java_md.c 20 Apr 2005 12:08:02 -0000
|
||||
@@ -906,8 +904,7 @@
|
||||
if (execname != NULL) /* Already determined */
|
||||
return (execname);
|
||||
|
||||
-/* XXXBSD: is it right for us ?*/
|
||||
-#if defined(__sun) || defined(__FreeBSD__)
|
||||
+#if defined(__sun)
|
||||
{
|
||||
Dl_info dlinfo;
|
||||
if (dladdr((void*)&SetExecname, &dlinfo)) {
|
||||
@@ -928,12 +925,47 @@
|
||||
exec_path = strdup(buf);
|
||||
}
|
||||
}
|
||||
+#elif defined(__FreeBSD__)
|
||||
+ /* Try /proc/curproc/file if exec_path hasn't been found */
|
||||
+
|
||||
+ if (exec_path == NULL) {
|
||||
+ const char* self = "/proc/curproc/file";
|
||||
+ char buf[PATH_MAX+1];
|
||||
+ int len = readlink(self, buf, PATH_MAX);
|
||||
+ if (len >= 0) {
|
||||
+ buf[len] = '\0'; /* readlink doesn't nul terminate */
|
||||
+ exec_path = strdup(buf);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Try the dladdr(3) method FreeBSD if exec_path hasn't been found.
|
||||
+ * Requires a recent version of FreeBSD.
|
||||
+ */
|
||||
+
|
||||
+ /*
|
||||
+ if (exec_path == NULL) {
|
||||
+ Dl_info dlinfo;
|
||||
+ if (dladdr((void*)&SetExecname, &dlinfo)) {
|
||||
+ char *resolved = (char*)MemAlloc(PATH_MAX+1);
|
||||
+ if (resolved != NULL) {
|
||||
+ exec_path = realpath(dlinfo.dli_fname, resolved);
|
||||
+ if (exec_path == NULL) {
|
||||
+ free(resolved);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ */
|
||||
+
|
||||
#else /* !__sun && !__linux */
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
#endif
|
||||
|
||||
+ /* Fall back to examining argv[0] and our path */
|
||||
+
|
||||
if (exec_path == NULL) {
|
||||
exec_path = FindExecName(argv[0]);
|
||||
}
|
62
java/jdk16/files/patch-j2se-bin-java_md.c
Normal file
62
java/jdk16/files/patch-j2se-bin-java_md.c
Normal file
@ -0,0 +1,62 @@
|
||||
$FreeBSD$
|
||||
|
||||
--- ../../j2se/src/solaris/bin/java_md.c 15 Feb 2005 02:06:26 -0000 1.6
|
||||
+++ ../../j2se/src/solaris/bin/java_md.c 20 Apr 2005 12:08:02 -0000
|
||||
@@ -906,8 +904,7 @@
|
||||
if (execname != NULL) /* Already determined */
|
||||
return (execname);
|
||||
|
||||
-/* XXXBSD: is it right for us ?*/
|
||||
-#if defined(__sun) || defined(__FreeBSD__)
|
||||
+#if defined(__sun)
|
||||
{
|
||||
Dl_info dlinfo;
|
||||
if (dladdr((void*)&SetExecname, &dlinfo)) {
|
||||
@@ -928,12 +925,47 @@
|
||||
exec_path = strdup(buf);
|
||||
}
|
||||
}
|
||||
+#elif defined(__FreeBSD__)
|
||||
+ /* Try /proc/curproc/file if exec_path hasn't been found */
|
||||
+
|
||||
+ if (exec_path == NULL) {
|
||||
+ const char* self = "/proc/curproc/file";
|
||||
+ char buf[PATH_MAX+1];
|
||||
+ int len = readlink(self, buf, PATH_MAX);
|
||||
+ if (len >= 0) {
|
||||
+ buf[len] = '\0'; /* readlink doesn't nul terminate */
|
||||
+ exec_path = strdup(buf);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ /*
|
||||
+ * Try the dladdr(3) method FreeBSD if exec_path hasn't been found.
|
||||
+ * Requires a recent version of FreeBSD.
|
||||
+ */
|
||||
+
|
||||
+ /*
|
||||
+ if (exec_path == NULL) {
|
||||
+ Dl_info dlinfo;
|
||||
+ if (dladdr((void*)&SetExecname, &dlinfo)) {
|
||||
+ char *resolved = (char*)MemAlloc(PATH_MAX+1);
|
||||
+ if (resolved != NULL) {
|
||||
+ exec_path = realpath(dlinfo.dli_fname, resolved);
|
||||
+ if (exec_path == NULL) {
|
||||
+ free(resolved);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ */
|
||||
+
|
||||
#else /* !__sun && !__linux */
|
||||
{
|
||||
/* Not implemented */
|
||||
}
|
||||
#endif
|
||||
|
||||
+ /* Fall back to examining argv[0] and our path */
|
||||
+
|
||||
if (exec_path == NULL) {
|
||||
exec_path = FindExecName(argv[0]);
|
||||
}
|
Loading…
Reference in New Issue
Block a user