diff options
author | Jung-uk Kim <jkim@FreeBSD.org> | 2015-07-02 18:18:16 +0000 |
---|---|---|
committer | Jung-uk Kim <jkim@FreeBSD.org> | 2015-07-02 18:18:16 +0000 |
commit | cee04cb56eef1f381145d169c62d3a85aded0198 (patch) | |
tree | f0b889b1f77c5553ae3154a1981972f9c1d27be3 /java/openjdk7/files | |
parent | - Fix broken preprocessor directives. (diff) |
Use sysctl(3) instead of procfs(5) when we need executable path from PID.
MFH: 2015Q3
Notes
Notes:
svn path=/head/; revision=391178
Diffstat (limited to 'java/openjdk7/files')
-rw-r--r-- | java/openjdk7/files/patch-src-os-bsd-vm-vmError_bsd.cpp | 63 | ||||
-rw-r--r-- | java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c | 58 |
2 files changed, 121 insertions, 0 deletions
diff --git a/java/openjdk7/files/patch-src-os-bsd-vm-vmError_bsd.cpp b/java/openjdk7/files/patch-src-os-bsd-vm-vmError_bsd.cpp new file mode 100644 index 000000000000..ae51000ce2b5 --- /dev/null +++ b/java/openjdk7/files/patch-src-os-bsd-vm-vmError_bsd.cpp @@ -0,0 +1,63 @@ +--- hotspot/src/os/bsd/vm/vmError_bsd.cpp.orig ++++ hotspot/src/os/bsd/vm/vmError_bsd.cpp +@@ -33,30 +33,50 @@ + #include <sys/syscall.h> + #include <unistd.h> + #include <signal.h> ++#ifdef __FreeBSD__ ++#include <limits.h> ++#include <sys/sysctl.h> ++#endif ++ ++#define GDB_CMD "gdb" ++ ++static void set_debugger(char *buf, int buflen) { ++ int pid = os::current_process_id(); ++#ifdef __FreeBSD__ ++ char cmd[PATH_MAX+1]; ++ int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid }; ++ size_t len = sizeof(cmd); ++ if (sysctl(name, 4, cmd, &len, NULL, 0) == 0 && len > 0) { ++ cmd[len] = '\0'; ++ jio_snprintf(buf, buflen, "%s %s %d", GDB_CMD, cmd, pid); ++ } else ++#endif ++ jio_snprintf(buf, buflen, "%s /proc/%d/file %d", GDB_CMD, pid, pid); ++} + + void VMError::show_message_box(char *buf, int buflen) { + bool yes; + do { +- error_string(buf, buflen); +- int len = (int)strlen(buf); ++ intx tid = os::current_thread_id(); ++ set_debugger(buf, buflen); ++ int len = (int)strlen(buf) + 1; ++ char *msg = &buf[len]; ++ error_string(msg, buflen - len); ++ len += (int)strlen(msg); + char *p = &buf[len]; + + jio_snprintf(p, buflen - len, + "\n\n" + "Do you want to debug the problem?\n\n" +- "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n" +- "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n" ++ "To debug, run '%s'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n" ++ "Enter 'yes' to launch " GDB_CMD " automatically (PATH must include " GDB_CMD ")\n" + "Otherwise, press RETURN to abort...", +- os::current_process_id(), os::current_process_id(), +- os::current_thread_id(), os::current_thread_id()); ++ buf, tid, tid); + +- yes = os::message_box("Unexpected Error", buf); ++ yes = os::message_box("Unexpected Error", msg); + + if (yes) { + // yes, user asked VM to launch debugger +- jio_snprintf(buf, buflen, "gdb /proc/%d/exe %d", +- os::current_process_id(), os::current_process_id()); +- + os::fork_and_exec(buf); + yes = false; + } diff --git a/java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c b/java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c new file mode 100644 index 000000000000..067ee2128002 --- /dev/null +++ b/java/openjdk7/files/patch-src-solaris-bin-java_md_solinux.c @@ -0,0 +1,58 @@ +--- jdk/src/solaris/bin/java_md_solinux.c.orig ++++ jdk/src/solaris/bin/java_md_solinux.c +@@ -35,6 +35,9 @@ + #include <sys/stat.h> + #include <unistd.h> + #include <sys/types.h> ++#ifdef __FreeBSD__ ++#include <sys/sysctl.h> ++#endif + #include "manifest_info.h" + #include "version_comp.h" + +@@ -899,9 +902,9 @@ + * onwards the filename returned in DL_info structure from dladdr is + * an absolute pathname so technically realpath isn't required. + * On Linux we read the executable name from /proc/self/exe. +- * On *BSD we read the executable name from /proc/curproc/file. ++ * On FreeBSD, we get the executable name via sysctl(3). + * As a fallback, and for platforms other than Solaris, Linux, and +- * *BSD, we use FindExecName to compute the executable name. ++ * FreeBSD, we use FindExecName to compute the executable name. + */ + const char* + SetExecname(char **argv) +@@ -928,13 +931,9 @@ + } + } + } +-#elif defined(__linux__) || defined(_ALLBSD_SOURCE) ++#elif defined(__linux__) + { +-#if defined(_ALLBSD_SOURCE) +- const char* self = "/proc/curproc/file"; +-#else + const char* self = "/proc/self/exe"; +-#endif + char buf[PATH_MAX+1]; + int len = readlink(self, buf, PATH_MAX); + if (len >= 0) { +@@ -942,7 +941,17 @@ + exec_path = JLI_StringDup(buf); + } + } +-#else /* !__solaris__ && !__linux__ && !_ALLBSD_SOURCE */ ++#elif defined(__FreeBSD__) ++ { ++ char buf[PATH_MAX+1]; ++ int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; ++ size_t len = sizeof(buf); ++ if (sysctl(name, 4, buf, &len, NULL, 0) == 0 && len > 0) { ++ buf[len] = '\0'; ++ exec_path = JLI_StringDup(buf); ++ } ++ } ++#else /* !__sun && !__linux && !__FreeBSD__ */ + { + /* Not implemented */ + } |