Fixes for include path, jshell, and process issues.
* Put MD specific include files (e.g. jni_md.h) in a subdirectory named 'freebsd' rather than 'bsd'. [1] * Remove the necessity to always have /usr/local/include in the header paths and linker paths. This allows jshell to use the system iconv.h rather than the third party one and link correctly. [2] * Fix getting process commands and arguments on FreeBSD. * Bump PORTREVISION. All fixes need forward porting to openjdk12. PR: 236754 [1], 236759 [2] Submitted by: Kurt Miller [2]
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
PORTNAME= openjdk
|
||||
PORTVERSION= ${JDK_MAJOR_VERSION}.${JDK_MINOR_VERSION}.${JDK_PATCH_VERSION}.${JDK_BUILD_NUMBER}.${BSD_JDK_VERSION}
|
||||
PORTREVISION= 1
|
||||
PORTREVISION= 2
|
||||
CATEGORIES= java devel
|
||||
MASTER_SITES= https://github.com/battleblow/openjdk-jdk11u/archive/
|
||||
PKGNAMESUFFIX?= ${JDK_MAJOR_VERSION}
|
||||
@@ -38,7 +38,6 @@ MAKE_ENV= LANG="C" \
|
||||
CLASSPATH="" \
|
||||
JAVA_HOME="" \
|
||||
LD_LIBRARY_PATH="" \
|
||||
LDFLAGS=-L${LOCALBASE}/lib \
|
||||
CC=/usr/bin/cc \
|
||||
CXX=/usr/bin/c++ \
|
||||
MAKEFLAGS="" \
|
||||
@@ -73,16 +72,14 @@ CONFIGURE_ARGS= --with-boot-jdk=${BOOTSTRAPJDKDIR} \
|
||||
--with-freetype-lib=${LOCALBASE}/lib \
|
||||
--with-libjpeg=system \
|
||||
--with-giflib=system \
|
||||
--with-giflib-include=${LOCALBASE}/include \
|
||||
--with-giflib-lib=${LOCALBASE}/lib \
|
||||
--with-libpng=system \
|
||||
--with-zlib=system \
|
||||
--with-lcms=system \
|
||||
--with-extra-cflags=-I${LOCALBASE}/include \
|
||||
--with-extra-cxxflags=-I${LOCALBASE}/include \
|
||||
--with-extra-ldflags=-L${LOCALBASE}/lib \
|
||||
--with-toolchain-type=clang \
|
||||
--x-includes=${LOCALBASE}/include \
|
||||
--x-libraries=${LOCALBASE}/lib \
|
||||
--with-package-path=${LOCALBASE} \
|
||||
--with-cacerts-file=${FILESDIR}/cacerts \
|
||||
--with-version-string=${JDK_MAJOR_VERSION}.${JDK_MINOR_VERSION}.${JDK_PATCH_VERSION}+${JDK_BUILD_NUMBER}-${BSD_JDK_VERSION} \
|
||||
--with-native-debug-symbols=none \
|
||||
@@ -124,7 +121,8 @@ post-patch:
|
||||
@${FIND} ${WRKSRC} -name '*.orig' -delete
|
||||
@${CHMOD} 755 ${WRKSRC}/configure
|
||||
@${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|' \
|
||||
${WRKSRC}/configure
|
||||
${WRKSRC}/configure \
|
||||
${WRKSRC}/src/hotspot/os/bsd/os_bsd.cpp
|
||||
|
||||
do-install:
|
||||
@${MKDIR} ${STAGEDIR}${INSTALLDIR}
|
||||
|
||||
11
java/openjdk11/files/patch-make_autoconf_flags-cflags.m4
Normal file
11
java/openjdk11/files/patch-make_autoconf_flags-cflags.m4
Normal file
@@ -0,0 +1,11 @@
|
||||
--- make/autoconf/flags-cflags.m4
|
||||
+++ make/autoconf/flags-cflags.m4
|
||||
@@ -416,7 +416,7 @@ AC_DEFUN([FLAGS_SETUP_CFLAGS_HELPER],
|
||||
elif test "x$OPENJDK_TARGET_OS" = xaix; then
|
||||
CFLAGS_OS_DEF_JVM="-DAIX"
|
||||
elif test "x$OPENJDK_TARGET_OS" = xbsd; then
|
||||
- CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_BSDONLY_SOURCE -DPACKAGE_PATH='\"$PACKAGE_PATH\"'"
|
||||
+ CFLAGS_OS_DEF_JVM="-D_ALLBSD_SOURCE -D_BSDONLY_SOURCE"
|
||||
CFLAGS_OS_DEF_JDK="-D_ALLBSD_SOURCE -D_BSDONLY_SOURCE -D_REENTRANT"
|
||||
elif test "x$OPENJDK_TARGET_OS" = xwindows; then
|
||||
CFLAGS_OS_DEF_JVM="-D_WINDOWS -DWIN32 -D_JNI_IMPLEMENTATION_"
|
||||
99
java/openjdk11/files/patch-make_autoconf_lib-bundled.m4
Normal file
99
java/openjdk11/files/patch-make_autoconf_lib-bundled.m4
Normal file
@@ -0,0 +1,99 @@
|
||||
--- make/autoconf/lib-bundled.m4
|
||||
+++ make/autoconf/lib-bundled.m4
|
||||
@@ -58,18 +58,26 @@ AC_DEFUN_ONCE([LIB_SETUP_LIBJPEG],
|
||||
|
||||
if test "x${with_libjpeg}" = "xbundled"; then
|
||||
USE_EXTERNAL_LIBJPEG=false
|
||||
+ JPEG_CFLAGS=""
|
||||
+ JPEG_LIBS=""
|
||||
elif test "x${with_libjpeg}" = "xsystem"; then
|
||||
- AC_CHECK_HEADER(jpeglib.h, [],
|
||||
- [ AC_MSG_ERROR([--with-libjpeg=system specified, but jpeglib.h not found!])])
|
||||
- AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, [],
|
||||
- [ AC_MSG_ERROR([--with-libjpeg=system specified, but no libjpeg found])])
|
||||
-
|
||||
+ PKG_CHECK_MODULES(JPEG, libjpeg, [LIBJPEG_FOUND=yes], [LIBJPEG_FOUND=no])
|
||||
+ if test "x${LIBJPEG_FOUND}" = "xno"; then
|
||||
+ AC_CHECK_HEADER(jpeglib.h, [],
|
||||
+ [ AC_MSG_ERROR([--with-libjpeg=system specified, but jpeglib.h not found!])])
|
||||
+ AC_CHECK_LIB(jpeg, jpeg_CreateDecompress, [],
|
||||
+ [ AC_MSG_ERROR([--with-libjpeg=system specified, but no libjpeg found])])
|
||||
+ JPEG_CFLAGS=""
|
||||
+ JPEG_LIBS="-ljpeg"
|
||||
+ fi
|
||||
USE_EXTERNAL_LIBJPEG=true
|
||||
else
|
||||
AC_MSG_ERROR([Invalid use of --with-libjpeg: ${with_libjpeg}, use 'system' or 'bundled'])
|
||||
fi
|
||||
|
||||
AC_SUBST(USE_EXTERNAL_LIBJPEG)
|
||||
+ AC_SUBST(JPEG_CFLAGS)
|
||||
+ AC_SUBST(JPEG_LIBS)
|
||||
])
|
||||
|
||||
################################################################################
|
||||
@@ -79,6 +87,10 @@ AC_DEFUN_ONCE([LIB_SETUP_GIFLIB],
|
||||
[
|
||||
AC_ARG_WITH(giflib, [AS_HELP_STRING([--with-giflib],
|
||||
[use giflib from build system or OpenJDK source (system, bundled) @<:@bundled@:>@])])
|
||||
+ AC_ARG_WITH(giflib-include, [AS_HELP_STRING([--with-giflib-include],
|
||||
+ [specify directory for the system giflib include files])])
|
||||
+ AC_ARG_WITH(giflib-lib, [AS_HELP_STRING([--with-giflib-lib],
|
||||
+ [specify directory for the system giflib library])])
|
||||
|
||||
AC_MSG_CHECKING([for which giflib to use])
|
||||
# default is bundled
|
||||
@@ -91,11 +103,40 @@ AC_DEFUN_ONCE([LIB_SETUP_GIFLIB],
|
||||
|
||||
if test "x${with_giflib}" = "xbundled"; then
|
||||
USE_EXTERNAL_LIBGIF=false
|
||||
+ GIFLIB_CFLAGS=""
|
||||
+ GIFLIB_LIBS=""
|
||||
elif test "x${with_giflib}" = "xsystem"; then
|
||||
- AC_CHECK_HEADER(gif_lib.h, [],
|
||||
- [ AC_MSG_ERROR([--with-giflib=system specified, but gif_lib.h not found!])])
|
||||
- AC_CHECK_LIB(gif, DGifGetCode, [],
|
||||
- [ AC_MSG_ERROR([--with-giflib=system specified, but no giflib found!])])
|
||||
+ GIFLIB_H_FOUND=no
|
||||
+ if test "x${with_giflib_include}" != x; then
|
||||
+ GIFLIB_CFLAGS="-I${with_giflib_include}"
|
||||
+ GIFLIB_H_FOUND=yes
|
||||
+ fi
|
||||
+ if test "x$GIFLIB_H_FOUND" = xno; then
|
||||
+ AC_CHECK_HEADER(gif_lib.h,
|
||||
+ [
|
||||
+ GIFLIB_CFLAGS=""
|
||||
+ GIFLIB_H_FOUND=yes
|
||||
+ ])
|
||||
+ fi
|
||||
+ if test "x$GIFLIB_H_FOUND" = xno; then
|
||||
+ AC_MSG_ERROR([--with-giflib=system specified, but gif_lib.h not found!])
|
||||
+ fi
|
||||
+
|
||||
+ GIFLIB_LIB_FOUND=no
|
||||
+ if test "x${with_giflib_lib}" != x; then
|
||||
+ GIFLIB_LIBS="-L${with_giflib_lib} -lgif"
|
||||
+ GIFLIB_LIB_FOUND=yes
|
||||
+ fi
|
||||
+ if test "x$GIFLIB_LIB_FOUND" = xno; then
|
||||
+ AC_CHECK_LIB(gif, DGifGetCode,
|
||||
+ [
|
||||
+ GIFLIB_LIBS="-lgif"
|
||||
+ GIFLIB_LIB_FOUND=yes
|
||||
+ ])
|
||||
+ fi
|
||||
+ if test "x$GIFLIB_LIB_FOUND" = xno; then
|
||||
+ AC_MSG_ERROR([--with-giflib=system specified, but no giflib found!])
|
||||
+ fi
|
||||
|
||||
USE_EXTERNAL_LIBGIF=true
|
||||
else
|
||||
@@ -103,6 +144,8 @@ AC_DEFUN_ONCE([LIB_SETUP_GIFLIB],
|
||||
fi
|
||||
|
||||
AC_SUBST(USE_EXTERNAL_LIBGIF)
|
||||
+ AC_SUBST(GIFLIB_CFLAGS)
|
||||
+ AC_SUBST(GIFLIB_LIBS)
|
||||
])
|
||||
|
||||
################################################################################
|
||||
17
java/openjdk11/files/patch-make_autoconf_lib-cups.m4
Normal file
17
java/openjdk11/files/patch-make_autoconf_lib-cups.m4
Normal file
@@ -0,0 +1,17 @@
|
||||
--- make/autoconf/lib-cups.m4
|
||||
+++ make/autoconf/lib-cups.m4
|
||||
@@ -75,14 +75,6 @@ AC_DEFUN_ONCE([LIB_SETUP_CUPS],
|
||||
DEFAULT_CUPS=yes
|
||||
])
|
||||
fi
|
||||
- if test "x$CUPS_FOUND" = xno -a "x$OPENJDK_TARGET_OS" = xbsd; then
|
||||
- AC_MSG_CHECKING([for cups headers])
|
||||
- if test -s "${PACKAGE_PATH}/include/cups/cups.h"; then
|
||||
- CUPS_CFLAGS="-I${PACKAGE_PATH}/include"
|
||||
- CUPS_FOUND=yes
|
||||
- fi
|
||||
- AC_MSG_RESULT([$CUPS_FOUND])
|
||||
- fi
|
||||
if test "x$CUPS_FOUND" = xno; then
|
||||
HELP_MSG_MISSING_DEPENDENCY([cups])
|
||||
AC_MSG_ERROR([Could not find cups! $HELP_MSG ])
|
||||
13
java/openjdk11/files/patch-make_autoconf_libraries.m4
Normal file
13
java/openjdk11/files/patch-make_autoconf_libraries.m4
Normal file
@@ -0,0 +1,13 @@
|
||||
--- make/autoconf/libraries.m4
|
||||
+++ make/autoconf/libraries.m4
|
||||
@@ -182,8 +182,8 @@ AC_DEFUN_ONCE([LIB_SETUP_MISC_LIBS],
|
||||
|
||||
if test "x$OPENJDK_TARGET_OS" = "xbsd"; then
|
||||
if test "x$OPENJDK_TARGET_OS_ENV" = "xbsd.openbsd"; then
|
||||
- ICONV_CFLAGS="-I$PACKAGE_PATH/include"
|
||||
- ICONV_LDFLAGS="-L$PACKAGE_PATH/lib"
|
||||
+ ICONV_CFLAGS="-I/usr/local/include"
|
||||
+ ICONV_LDFLAGS="-L/usr/local/lib"
|
||||
ICONV_LIBS=-liconv
|
||||
else
|
||||
ICONV_CFLAGS=
|
||||
11
java/openjdk11/files/patch-make_autoconf_platform.m4
Normal file
11
java/openjdk11/files/patch-make_autoconf_platform.m4
Normal file
@@ -0,0 +1,11 @@
|
||||
--- make/autoconf/platform.m4
|
||||
+++ make/autoconf/platform.m4
|
||||
@@ -497,6 +497,8 @@ AC_DEFUN([PLATFORM_SETUP_LEGACY_VARS_HELPER],
|
||||
OPENJDK_$1_OS_INCLUDE_SUBDIR="win32"
|
||||
elif test "x$OPENJDK_TARGET_OS" = "xmacosx"; then
|
||||
OPENJDK_$1_OS_INCLUDE_SUBDIR="darwin"
|
||||
+ elif test "x$OPENJDK_TARGET_OS" = "xbsd"; then
|
||||
+ OPENJDK_$1_OS_INCLUDE_SUBDIR=`echo ${OPENJDK_TARGET_OS_ENV} | cut -d'.' -f2`
|
||||
fi
|
||||
AC_SUBST(OPENJDK_$1_OS_INCLUDE_SUBDIR)
|
||||
])
|
||||
14
java/openjdk11/files/patch-make_autoconf_spec.gmk.in
Normal file
14
java/openjdk11/files/patch-make_autoconf_spec.gmk.in
Normal file
@@ -0,0 +1,14 @@
|
||||
--- make/autoconf/spec.gmk.in
|
||||
+++ make/autoconf/spec.gmk.in
|
||||
@@ -746,7 +746,11 @@ TAR_SUPPORTS_TRANSFORM:=@TAR_SUPPORTS_TRANSFORM@
|
||||
ENABLE_AOT:=@ENABLE_AOT@
|
||||
ENABLE_INTREE_EC:=@ENABLE_INTREE_EC@
|
||||
USE_EXTERNAL_LIBJPEG:=@USE_EXTERNAL_LIBJPEG@
|
||||
+JPEG_CFLAGS:=@JPEG_CFLAGS@
|
||||
+JPEG_LIBS:=@JPEG_LIBS@
|
||||
USE_EXTERNAL_LIBGIF:=@USE_EXTERNAL_LIBGIF@
|
||||
+GIFLIB_CFLAGS:=@GIFLIB_CFLAGS@
|
||||
+GIFLIB_LIBS:=@GIFLIB_LIBS@
|
||||
USE_EXTERNAL_LIBZ:=@USE_EXTERNAL_LIBZ@
|
||||
LIBZ_CFLAGS:=@LIBZ_CFLAGS@
|
||||
LIBZ_LIBS:=@LIBZ_LIBS@
|
||||
26
java/openjdk11/files/patch-make_autoconf_toolchain.m4
Normal file
26
java/openjdk11/files/patch-make_autoconf_toolchain.m4
Normal file
@@ -0,0 +1,26 @@
|
||||
--- make/autoconf/toolchain.m4
|
||||
+++ make/autoconf/toolchain.m4
|
||||
@@ -998,22 +998,7 @@ AC_DEFUN_ONCE([TOOLCHAIN_MISC_CHECKS],
|
||||
[
|
||||
# The package path is used only on macosx?
|
||||
# FIXME: clean this up, and/or move it elsewhere.
|
||||
- AC_ARG_WITH(package-path, [AS_HELP_STRING([--with-package-path],
|
||||
- [package path to be used for location of third party packages])])
|
||||
- PACKAGE_PATH="$with_package_path"
|
||||
- if test "x$PACKAGE_PATH" = x; then
|
||||
- case $OPENJDK_TARGET_OS_ENV in
|
||||
- bsd.freebsd|bsd.openbsd)
|
||||
- PACKAGE_PATH=/usr/local
|
||||
- ;;
|
||||
- bsd.netbsd)
|
||||
- PACKAGE_PATH=/usr/pkg
|
||||
- ;;
|
||||
- *)
|
||||
- PACKAGE_PATH=/opt/local
|
||||
- ;;
|
||||
- esac
|
||||
- fi
|
||||
+ PACKAGE_PATH=/opt/local
|
||||
AC_SUBST(PACKAGE_PATH)
|
||||
|
||||
# Check for extra potential brokenness.
|
||||
77
java/openjdk11/files/patch-make_lib_Awt2dLibraries.gmk
Normal file
77
java/openjdk11/files/patch-make_lib_Awt2dLibraries.gmk
Normal file
@@ -0,0 +1,77 @@
|
||||
--- make/lib/Awt2dLibraries.gmk
|
||||
+++ make/lib/Awt2dLibraries.gmk
|
||||
@@ -364,7 +364,7 @@ endif
|
||||
################################################################################
|
||||
|
||||
# The fast floor code loses precision.
|
||||
-LCMS_CFLAGS=-DCMS_DONT_USE_FAST_FLOOR
|
||||
+LCMS_CFLAGS+=-DCMS_DONT_USE_FAST_FLOOR
|
||||
|
||||
LCMS_CFLAGS_JDKLIB := $(filter-out -xc99=%none, $(CFLAGS_JDKLIB))
|
||||
|
||||
@@ -417,7 +417,6 @@ $(BUILD_LIBLCMS): $(BUILD_LIBAWT)
|
||||
# work because we have to declare all variables as volatile in result.
|
||||
|
||||
ifeq ($(USE_EXTERNAL_LIBJPEG), true)
|
||||
- LIBJPEG_LIBS := -ljpeg
|
||||
BUILD_LIBJAVAJPEG_INCLUDE_FILES := \
|
||||
imageioJPEG.c \
|
||||
jpegdecoder.c
|
||||
@@ -425,7 +424,6 @@ ifeq ($(USE_EXTERNAL_LIBJPEG), true)
|
||||
# as includes, instead the system headers should be used.
|
||||
LIBJPEG_HEADERS_FROM_SRC := false
|
||||
else
|
||||
- LIBJPEG_LIBS :=
|
||||
BUILD_LIBJAVAJPEG_INCLUDE_FILES :=
|
||||
endif
|
||||
|
||||
@@ -433,12 +431,12 @@ $(eval $(call SetupJdkLibrary, BUILD_LIBJAVAJPEG, \
|
||||
NAME := javajpeg, \
|
||||
INCLUDE_FILES := $(BUILD_LIBJAVAJPEG_INCLUDE_FILES), \
|
||||
OPTIMIZATION := HIGHEST, \
|
||||
- CFLAGS := $(CFLAGS_JDKLIB), \
|
||||
+ CFLAGS := $(CFLAGS_JDKLIB) $(JPEG_CFLAGS), \
|
||||
HEADERS_FROM_SRC := $(LIBJPEG_HEADERS_FROM_SRC), \
|
||||
DISABLED_WARNINGS_gcc := clobbered implicit-fallthrough shift-negative-value, \
|
||||
LDFLAGS := $(LDFLAGS_JDKLIB) \
|
||||
$(call SET_SHARED_LIBRARY_ORIGIN), \
|
||||
- LIBS := $(LIBJPEG_LIBS) $(JDKLIB_LIBS), \
|
||||
+ LIBS := $(JDKLIB_LIBS) $(JPEG_LIBS), \
|
||||
LIBS_windows := $(WIN_JAVA_LIB) jvm.lib, \
|
||||
))
|
||||
|
||||
@@ -766,7 +764,6 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
|
||||
LIBSPLASHSCREEN_HEADER_DIRS += libsplashscreen/giflib
|
||||
else
|
||||
LIBSPLASHSCREEN_EXCLUDES := giflib
|
||||
- GIFLIB_LIBS := -lgif
|
||||
endif
|
||||
|
||||
ifeq ($(USE_EXTERNAL_LIBJPEG), false)
|
||||
@@ -774,8 +771,6 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
|
||||
# additions to this library, and this was not done previously in the build.
|
||||
# LIBSPLASHSCREEN_EXTRA_SRC += libjavajpeg
|
||||
LIBSPLASHSCREEN_EXTRA_SRC += $(TOPDIR)/src/java.desktop/share/native/libjavajpeg
|
||||
- else
|
||||
- LIBJPEG_LIBS := -ljpeg
|
||||
endif
|
||||
|
||||
ifeq ($(USE_EXTERNAL_LIBPNG), false)
|
||||
@@ -855,7 +850,7 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
|
||||
EXCLUDES := $(LIBSPLASHSCREEN_EXCLUDES), \
|
||||
OPTIMIZATION := LOW, \
|
||||
CFLAGS := $(CFLAGS_JDKLIB) $(LIBSPLASHSCREEN_CFLAGS) \
|
||||
- $(GIFLIB_CFLAGS) $(LIBJPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS), \
|
||||
+ $(GIFLIB_CFLAGS) $(JPEG_CFLAGS) $(PNG_CFLAGS) $(LIBZ_CFLAGS), \
|
||||
EXTRA_HEADER_DIRS := $(LIBSPLASHSCREEN_HEADER_DIRS), \
|
||||
DISABLED_WARNINGS_gcc := sign-compare type-limits unused-result \
|
||||
maybe-uninitialized shift-negative-value implicit-fallthrough, \
|
||||
@@ -869,7 +864,7 @@ ifeq ($(ENABLE_HEADLESS_ONLY), false)
|
||||
LDFLAGS_windows := -delayload:user32.dll, \
|
||||
LDFLAGS_bsd := $(ICONV_LDFLAGS), \
|
||||
LIBS := $(JDKLIB_LIBS) $(LIBSPLASHSCREEN_LIBS) $(LIBZ_LIBS) \
|
||||
- $(GIFLIB_LIBS) $(LIBJPEG_LIBS) $(PNG_LIBS), \
|
||||
+ $(GIFLIB_LIBS) $(JPEG_LIBS) $(PNG_LIBS), \
|
||||
LIBS_aix := -liconv, \
|
||||
))
|
||||
|
||||
14
java/openjdk11/files/patch-src_hotspot_os_bsd_os__bsd.cpp
Normal file
14
java/openjdk11/files/patch-src_hotspot_os_bsd_os__bsd.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
--- src/hotspot/os/bsd/os_bsd.cpp
|
||||
+++ src/hotspot/os/bsd/os_bsd.cpp
|
||||
@@ -377,8 +377,10 @@ void os::init_system_properties_values() {
|
||||
#ifndef DEFAULT_LIBPATH
|
||||
#ifdef __APPLE__
|
||||
#define DEFAULT_LIBPATH "/lib:/usr/lib"
|
||||
+#elif defined(__NetBSD__)
|
||||
+ #define DEFAULT_LIBPATH "/usr/lib:/usr/pkg/lib"
|
||||
#else
|
||||
- #define DEFAULT_LIBPATH "/usr/lib:" PACKAGE_PATH "/lib"
|
||||
+ #define DEFAULT_LIBPATH "/usr/lib:%%LOCALBASE%%/lib"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
--- src/java.base/bsd/native/libjava/ProcessHandleImpl_bsd.c
|
||||
+++ src/java.base/bsd/native/libjava/ProcessHandleImpl_bsd.c
|
||||
@@ -41,7 +41,8 @@
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
-#include <sys/user.h> // For kinfo_proc
|
||||
+#include <sys/param.h> // For MAXPATHLEN
|
||||
+#include <sys/user.h> // For kinfo_proc
|
||||
#endif
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
@@ -109,8 +110,14 @@ jint os_getChildren(JNIEnv *env, jlong jpid, jlongArray jarray,
|
||||
}
|
||||
|
||||
// Get buffer size needed to read all processes
|
||||
+#if defined(__OpenBSD__)
|
||||
+ u_int namelen = 6;
|
||||
+ int mib[6] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), 0};
|
||||
+#else
|
||||
+ u_int namelen = 4;
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
|
||||
- if (sysctl(mib, 4, NULL, &bufSize, NULL, 0) < 0) {
|
||||
+#endif
|
||||
+ if (sysctl(mib, namelen, NULL, &bufSize, NULL, 0) < 0) {
|
||||
JNU_ThrowByNameWithLastError(env,
|
||||
"java/lang/RuntimeException", "sysctl failed");
|
||||
return -1;
|
||||
@@ -123,8 +130,12 @@ jint os_getChildren(JNIEnv *env, jlong jpid, jlongArray jarray,
|
||||
return -1;
|
||||
}
|
||||
|
||||
+#if defined(__OpenBSD__)
|
||||
+ mib[5] = bufSize / sizeof(struct kinfo_proc);
|
||||
+#endif
|
||||
+
|
||||
// Read process info for all processes
|
||||
- if (sysctl(mib, 4, buffer, &bufSize, NULL, 0) < 0) {
|
||||
+ if (sysctl(mib, namelen, buffer, &bufSize, NULL, 0) < 0) {
|
||||
JNU_ThrowByNameWithLastError(env,
|
||||
"java/lang/RuntimeException", "sysctl failed");
|
||||
free(buffer);
|
||||
@@ -204,9 +215,15 @@ pid_t os_getParentPidAndTimings(JNIEnv *env, pid_t jpid,
|
||||
size_t bufSize = sizeof kp;
|
||||
|
||||
// Read the process info for the specific pid
|
||||
+#if defined(__OpenBSD__)
|
||||
+ u_int namelen = 6;
|
||||
+ int mib[6] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, bufSize, 1};
|
||||
+#else
|
||||
+ u_int namelen = 4;
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
|
||||
+#endif
|
||||
|
||||
- if (sysctl(mib, 4, &kp, &bufSize, NULL, 0) == -1) {
|
||||
+ if (sysctl(mib, namelen, &kp, &bufSize, NULL, 0) == -1) {
|
||||
/*
|
||||
* Check errno and throw an exception only if appropriate.
|
||||
*
|
||||
@@ -232,13 +249,13 @@ pid_t os_getParentPidAndTimings(JNIEnv *env, pid_t jpid,
|
||||
ppid = kp.KI_PPID;
|
||||
}
|
||||
|
||||
- // Get cputime if for current process
|
||||
- if (pid == getpid()) {
|
||||
#ifdef __OpenBSD__
|
||||
- jlong microsecs = kp.p_uutime_sec * 1000 * 1000 + kp.p_uutime_usec +
|
||||
- kp.p_ustime_sec * 1000 * 1000 + kp.p_ustime_usec;
|
||||
- *totalTime = microsecs * 1000;
|
||||
+ jlong microsecs = kp.p_uutime_sec * 1000 * 1000 + kp.p_uutime_usec +
|
||||
+ kp.p_ustime_sec * 1000 * 1000 + kp.p_ustime_usec;
|
||||
+ *totalTime = microsecs * 1000;
|
||||
#else
|
||||
+ // Get cputime if for current process
|
||||
+ if (pid == getpid()) {
|
||||
struct rusage usage;
|
||||
if (getrusage(RUSAGE_SELF, &usage) == 0) {
|
||||
jlong microsecs =
|
||||
@@ -246,8 +263,8 @@ pid_t os_getParentPidAndTimings(JNIEnv *env, pid_t jpid,
|
||||
usage.ru_stime.tv_sec * 1000 * 1000 + usage.ru_stime.tv_usec;
|
||||
*totalTime = microsecs * 1000;
|
||||
}
|
||||
-#endif
|
||||
}
|
||||
+#endif
|
||||
|
||||
return ppid;
|
||||
}
|
||||
@@ -260,9 +277,15 @@ static uid_t getUID(pid_t pid) {
|
||||
size_t bufSize = sizeof kp;
|
||||
|
||||
// Read the process info for the specific pid
|
||||
+#if defined(__OpenBSD__)
|
||||
+ u_int namelen = 6;
|
||||
+ int mib[6] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid, bufSize, 1};
|
||||
+#else
|
||||
+ u_int namelen = 4;
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
|
||||
+#endif
|
||||
|
||||
- if (sysctl(mib, 4, &kp, &bufSize, NULL, 0) == 0) {
|
||||
+ if (sysctl(mib, namelen, &kp, &bufSize, NULL, 0) == 0) {
|
||||
if (bufSize > 0 && kp.KI_PID == pid) {
|
||||
return kp.KI_UID;
|
||||
}
|
||||
@@ -275,22 +298,121 @@ static uid_t getUID(pid_t pid) {
|
||||
* into the Info object.
|
||||
*/
|
||||
void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
|
||||
- int mib[4], maxargs, nargs, i;
|
||||
+ int mib[4], nargs, i;
|
||||
size_t size;
|
||||
- char *args, *cp, *sp, *np;
|
||||
+ char *args;
|
||||
|
||||
// Get the UID first. This is done here because it is cheap to do it here
|
||||
// on other platforms like Linux/Solaris/AIX where the uid comes from the
|
||||
// same source like the command line info.
|
||||
unix_getUserInfo(env, jinfo, getUID(pid));
|
||||
|
||||
+#ifdef __OpenBSD__
|
||||
+ // Get the buffer size needed
|
||||
+ mib[0] = CTL_KERN;
|
||||
+ mib[1] = KERN_PROC_ARGS;
|
||||
+ mib[2] = pid;
|
||||
+ mib[3] = KERN_PROC_ARGV;
|
||||
+
|
||||
+ if (sysctl(mib, 4, NULL, &size, NULL, 0) == -1) {
|
||||
+ JNU_ThrowByNameWithLastError(env,
|
||||
+ "java/lang/RuntimeException", "sysctl failed");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ // Allocate space for args and get the arguments
|
||||
+ args = (char *)malloc(size);
|
||||
+ if (args == NULL) {
|
||||
+ JNU_ThrowOutOfMemoryError(env, "malloc failed");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ do { // a block to break out of on error
|
||||
+ char **argv;
|
||||
+ jstring cmdexe = NULL;
|
||||
+ jclass clazzString;
|
||||
+ jobject argsArray;
|
||||
+
|
||||
+ if (sysctl(mib, 4, args, &size, NULL, 0) == -1) {
|
||||
+ if (errno != EINVAL) {
|
||||
+ JNU_ThrowByNameWithLastError(env,
|
||||
+ "java/lang/RuntimeException", "sysctl failed");
|
||||
+ }
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
+ // count the number of argv elements
|
||||
+ argv = (char **)args;
|
||||
+ nargs = 0;
|
||||
+ while (*argv++)
|
||||
+ nargs++;
|
||||
+
|
||||
+ if (nargs < 1)
|
||||
+ break;
|
||||
+
|
||||
+ // reset argv and store command executable path
|
||||
+ argv = (char **)args;
|
||||
+ if ((cmdexe = JNU_NewStringPlatform(env, *argv++)) == NULL)
|
||||
+ break;
|
||||
+ (*env)->SetObjectField(env, jinfo, ProcessHandleImpl_Info_commandID, cmdexe);
|
||||
+ if ((*env)->ExceptionCheck(env))
|
||||
+ break;
|
||||
+ nargs--;
|
||||
+
|
||||
+ // process remaining arguments
|
||||
+ // Create a String array for nargs elements
|
||||
+ if ((clazzString = JNU_ClassString(env)) == NULL)
|
||||
+ break;
|
||||
+ if ((argsArray = (*env)->NewObjectArray(env, nargs, clazzString, NULL)) == NULL)
|
||||
+ break;
|
||||
+
|
||||
+ for (i = 0; i < nargs; i++) {
|
||||
+ jstring str;
|
||||
+ if ((str = JNU_NewStringPlatform(env, argv[i])) == NULL)
|
||||
+ break;
|
||||
+
|
||||
+ (*env)->SetObjectArrayElement(env, argsArray, i, str);
|
||||
+ if ((*env)->ExceptionCheck(env))
|
||||
+ break;
|
||||
+ }
|
||||
+ if (i == nargs) // no errors in for loop?
|
||||
+ (*env)->SetObjectField(env, jinfo, ProcessHandleImpl_Info_argumentsID, argsArray);
|
||||
+ } while (0);
|
||||
+ // Free the arg buffer
|
||||
+ free(args);
|
||||
+#else
|
||||
+ int maxargs;
|
||||
+ char cmd[MAXPATHLEN];
|
||||
+ jstring cmdexe = NULL;
|
||||
+
|
||||
+ // Get the resolved name of the executable
|
||||
+ size = sizeof(cmd);
|
||||
+ mib[0] = CTL_KERN;
|
||||
+ mib[1] = KERN_PROC;
|
||||
+ mib[2] = KERN_PROC_PATHNAME;
|
||||
+ mib[3] = pid;
|
||||
+ if (sysctl(mib, 4, cmd, &size, NULL, 0) == -1) {
|
||||
+ if (errno != EINVAL && errno != ESRCH && errno != EPERM) {
|
||||
+ JNU_ThrowByNameWithLastError(env,
|
||||
+ "java/lang/RuntimeException", "sysctl failed");
|
||||
+ }
|
||||
+ return;
|
||||
+ }
|
||||
+ // Make sure it is null terminated
|
||||
+ cmd[MAXPATHLEN - 1] = '\0';
|
||||
+
|
||||
+ // Store the command executable
|
||||
+ if ((cmdexe = JNU_NewStringPlatform(env, cmd)) == NULL) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
// Get the maximum size of the arguments
|
||||
mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_ARGMAX;
|
||||
size = sizeof(maxargs);
|
||||
if (sysctl(mib, 2, &maxargs, &size, NULL, 0) == -1) {
|
||||
- JNU_ThrowByNameWithLastError(env,
|
||||
- "java/lang/RuntimeException", "sysctl failed");
|
||||
+ JNU_ThrowByNameWithLastError(env,
|
||||
+ "java/lang/RuntimeException", "sysctl failed");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -301,51 +423,44 @@ void os_getCmdlineAndUserInfo(JNIEnv *env, jobject jinfo, pid_t pid) {
|
||||
return;
|
||||
}
|
||||
|
||||
- do { // a block to break out of on error
|
||||
- char *argsEnd;
|
||||
- jstring cmdexe = NULL;
|
||||
- unsigned namelen;
|
||||
+ // A block to break out of on error
|
||||
+ do {
|
||||
+ char *cp, *argsEnd = NULL;
|
||||
|
||||
mib[0] = CTL_KERN;
|
||||
-#if defined(__OpenBSD__)
|
||||
- mib[1] = KERN_PROC_ARGS;
|
||||
- mib[2] = pid;
|
||||
- namelen = 3;
|
||||
-#elif defined(__FreeBSD__)
|
||||
- mib[0] = CTL_KERN;
|
||||
mib[1] = KERN_PROC;
|
||||
mib[2] = KERN_PROC_ARGS;
|
||||
mib[3] = pid;
|
||||
- namelen = 4;
|
||||
-#endif
|
||||
size = (size_t) maxargs;
|
||||
- if (sysctl(mib, namelen, args, &size, NULL, 0) == -1) {
|
||||
- if (errno != EINVAL) {
|
||||
+ if (sysctl(mib, 4, args, &size, NULL, 0) == -1) {
|
||||
+ if (errno != EINVAL && errno != ESRCH && errno != EPERM) {
|
||||
JNU_ThrowByNameWithLastError(env,
|
||||
"java/lang/RuntimeException", "sysctl failed");
|
||||
}
|
||||
break;
|
||||
}
|
||||
- memcpy(&nargs, args, sizeof(nargs));
|
||||
|
||||
- cp = &args[sizeof(nargs)]; // Strings start after nargs
|
||||
- argsEnd = &args[size];
|
||||
+ // At this point args should hold a flattened argument string with
|
||||
+ // arguments delimited by NUL and size should hold the overall length
|
||||
+ // of the string
|
||||
|
||||
- // Store the command executable path
|
||||
- if ((cmdexe = JNU_NewStringPlatform(env, cp)) == NULL) {
|
||||
- break;
|
||||
- }
|
||||
+ // Make sure the string is NUL terminated
|
||||
+ args[size] = '\0';
|
||||
|
||||
- // Skip trailing nulls after the executable path
|
||||
- for (cp = cp + strnlen(cp, argsEnd - cp); cp < argsEnd; cp++) {
|
||||
- if (*cp != '\0') {
|
||||
- break;
|
||||
- }
|
||||
+ // Count the number of arguments
|
||||
+ nargs = 0;
|
||||
+ argsEnd = &args[size];
|
||||
+ for (cp = args; *cp != '\0' && (cp < argsEnd); nargs++) {
|
||||
+ cp += strnlen(cp, (argsEnd - cp)) + 1;
|
||||
}
|
||||
|
||||
- unix_fillArgArray(env, jinfo, nargs, cp, argsEnd, cmdexe, NULL);
|
||||
+ // Copy over all the args
|
||||
+ cp = args;
|
||||
+ unix_fillArgArray(env, jinfo, nargs, cp, argsEnd, cmdexe, args);
|
||||
} while (0);
|
||||
+
|
||||
// Free the arg buffer
|
||||
free(args);
|
||||
+#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user