Skip to content
Permalink
Browse files
8254702: jpackage app launcher crashes on CentOS
Reviewed-by: almatvee, erikj, herrick
  • Loading branch information
Alexey Semenyuk committed Feb 5, 2021
1 parent 7a6c176 commit fac3c2d25817e56e972ca8a7b816e46a169a2d32
@@ -28,9 +28,17 @@ include LibCommon.gmk
################################################################################


JPACKAGE_APPLAUNCHER_SRC := \
$(call FindSrcDirsForComponent, jdk.jpackage, applauncher) \
$(call FindSrcDirsForComponent, jdk.jpackage, common)
ifeq ($(call isTargetOs, linux), true)
JPACKAGE_APPLAUNCHER_SRC := \
$(call FindSrcDirsForComponent, jdk.jpackage, applauncher)
JPACKAGE_APPLAUNCHER_TOOLCHAIN := TOOLCHAIN_DEFAULT
JPACKAGE_APPLAUNCHER_INCLUDE_FILES := %.c
else
JPACKAGE_APPLAUNCHER_SRC := \
$(call FindSrcDirsForComponent, jdk.jpackage, applauncher) \
$(call FindSrcDirsForComponent, jdk.jpackage, common)
JPACKAGE_APPLAUNCHER_TOOLCHAIN := TOOLCHAIN_LINK_CXX
endif


ifeq ($(call isTargetOs, windows), true)
@@ -44,27 +52,63 @@ endif

JPACKAGE_OUTPUT_DIR := $(JDK_OUTPUTDIR)/modules/$(MODULE)/jdk/jpackage/internal/resources
JPACKAGE_CXXFLAGS_windows := -EHsc -DUNICODE -D_UNICODE
JPACKAGE_CFLAGS_windows := -DUNICODE -D_UNICODE
JPACKAGE_APPLAUNCHER_INCLUDES := $(addprefix -I, $(JPACKAGE_APPLAUNCHER_SRC))

# Output app launcher executable in resources dir, and symbols in the object dir
$(eval $(call SetupJdkExecutable, BUILD_JPACKAGE_APPLAUNCHEREXE, \
NAME := jpackageapplauncher, \
OUTPUT_DIR := $(JPACKAGE_OUTPUT_DIR), \
SYMBOLS_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jpackageapplauncher, \
SRC := $(JPACKAGE_APPLAUNCHER_SRC), \
TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
INCLUDE_FILES := $(JPACKAGE_APPLAUNCHER_INCLUDE_FILES), \
TOOLCHAIN := $(JPACKAGE_APPLAUNCHER_TOOLCHAIN), \
OPTIMIZATION := LOW, \
CXXFLAGS := $(call JpackageWithStaticCrt, $(CXXFLAGS_JDKEXE)) \
$(addprefix -I, $(JPACKAGE_APPLAUNCHER_SRC)), \
$(JPACKAGE_APPLAUNCHER_INCLUDES), \
CFLAGS := $(call JpackageWithStaticCrt, $(CFLAGS_JDKEXE)) \
$(JPACKAGE_APPLAUNCHER_INCLUDES), \
CFLAGS_macosx := -Wno-format-nonliteral, \
CXXFLAGS_windows := $(JPACKAGE_CXXFLAGS_windows), \
CFLAGS_windows := $(JPACKAGE_CFLAGS_windows), \
LDFLAGS := $(LDFLAGS_JDKEXE), \
LIBS_macosx := -framework Cocoa, \
LIBS := $(LIBCXX), \
LIBS_linux := -ldl, \
LIBS_macosx := $(LIBCXX) -framework Cocoa, \
LIBS_windows := $(LIBCXX), \
LIBS_linux := -nodefaultlibs -lc -ldl, \
))

$(BUILD_JPACKAGE_APPLAUNCHEREXE): $(call FindLib, java.base, java)
JPACKAGE_TARGETS += $(BUILD_JPACKAGE_APPLAUNCHEREXE)


################################################################################

ifeq ($(call isTargetOs, linux), true)

JPACKAGE_LIBAPPLAUNCHER_SRC := \
$(call FindSrcDirsForComponent, jdk.jpackage, applauncher) \
$(call FindSrcDirsForComponent, jdk.jpackage, libapplauncher) \
$(call FindSrcDirsForComponent, jdk.jpackage, common)

JPACKAGE_LIBAPPLAUNCHER_INCLUDES := $(addprefix -I, $(JPACKAGE_LIBAPPLAUNCHER_SRC))

$(eval $(call SetupJdkLibrary, BUILD_JPACKAGE_LIBAPPLAUNCHER, \
NAME := jpackageapplauncher, \
OUTPUT_DIR := $(JPACKAGE_OUTPUT_DIR), \
SYMBOLS_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/libjpackageapplauncher, \
SRC := $(JPACKAGE_LIBAPPLAUNCHER_SRC), \
EXCLUDE_FILES := LinuxLauncher.c LinuxPackage.c, \
TOOLCHAIN := TOOLCHAIN_LINK_CXX, \
OPTIMIZATION := LOW, \
CXXFLAGS := $(CXXFLAGS_JDKLIB) $(JPACKAGE_LIBAPPLAUNCHER_INCLUDES), \
CFLAGS := $(CFLAGS_JDKLIB) $(JPACKAGE_LIBAPPLAUNCHER_INCLUDES), \
LDFLAGS := $(LDFLAGS_JDKLIB), \
LIBS := $(LIBCXX) -ldl, \
))

JPACKAGE_TARGETS += $(BUILD_JPACKAGE_LIBAPPLAUNCHER)

endif

TARGETS += $(BUILD_JPACKAGE_APPLAUNCHEREXE)

################################################################################

@@ -80,7 +124,7 @@ ifeq ($(call isTargetOs, windows), true)
LIBS := $(LIBCXX), \
))

TARGETS += $(BUILD_LIB_JPACKAGE)
JPACKAGE_TARGETS += $(BUILD_LIB_JPACKAGE)

# Build Wix custom action helper
# Output library in resources dir, and symbols in the object dir
@@ -96,7 +140,7 @@ ifeq ($(call isTargetOs, windows), true)
LIBS_windows := msi.lib Shlwapi.lib User32.lib, \
))

TARGETS += $(BUILD_LIB_WIXHELPER)
JPACKAGE_TARGETS += $(BUILD_LIB_WIXHELPER)

JPACKAGE_MSIWRAPPER_SRC := \
$(call FindSrcDirsForComponent, jdk.jpackage, msiwrapper) \
@@ -114,22 +158,30 @@ ifeq ($(call isTargetOs, windows), true)
LIBS := $(LIBCXX), \
))

TARGETS += $(BUILD_JPACKAGE_MSIWRAPPER)
JPACKAGE_TARGETS += $(BUILD_JPACKAGE_MSIWRAPPER)

# Build non-console version of launcher
$(eval $(call SetupJdkExecutable, BUILD_JPACKAGE_APPLAUNCHERWEXE, \
NAME := jpackageapplauncherw, \
OUTPUT_DIR := $(JPACKAGE_OUTPUT_DIR), \
SYMBOLS_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jpackageapplauncherw, \
SRC := $(BUILD_JPACKAGE_APPLAUNCHEREXE_SRC), \
TOOLCHAIN := $(BUILD_JPACKAGE_APPLAUNCHEREXE_TOOLCHAIN), \
OPTIMIZATION := $(BUILD_JPACKAGE_APPLAUNCHEREXE_OPTIMIZATION), \
CXXFLAGS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_CXXFLAGS), \
CXXFLAGS_windows := $(BUILD_JPACKAGE_APPLAUNCHEREXE_CXXFLAGS_windows) -DJP_LAUNCHERW, \
LDFLAGS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_LDFLAGS), \
LIBS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_LIBS), \
))
NAME := jpackageapplauncherw, \
OUTPUT_DIR := $(JPACKAGE_OUTPUT_DIR), \
SYMBOLS_DIR := $(SUPPORT_OUTPUTDIR)/native/$(MODULE)/jpackageapplauncherw, \
SRC := $(BUILD_JPACKAGE_APPLAUNCHEREXE_SRC), \
TOOLCHAIN := $(BUILD_JPACKAGE_APPLAUNCHEREXE_TOOLCHAIN), \
OPTIMIZATION := $(BUILD_JPACKAGE_APPLAUNCHEREXE_OPTIMIZATION), \
CXXFLAGS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_CXXFLAGS), \
CXXFLAGS_windows := $(BUILD_JPACKAGE_APPLAUNCHEREXE_CXXFLAGS_windows) -DJP_LAUNCHERW, \
CFLAGS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_CFLAGS), \
CFLAGS_windows := $(BUILD_JPACKAGE_APPLAUNCHEREXE_CFLAGS_windows) -DJP_LAUNCHERW, \
LDFLAGS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_LDFLAGS), \
LIBS := $(BUILD_JPACKAGE_APPLAUNCHEREXE_LIBS), \
LIBS_windows := $(BUILD_JPACKAGE_APPLAUNCHEREXE_LIBS_windows), \
))

TARGETS += $(BUILD_JPACKAGE_APPLAUNCHERWEXE)
JPACKAGE_TARGETS += $(BUILD_JPACKAGE_APPLAUNCHERWEXE)

endif


TARGETS += $(JPACKAGE_TARGETS)

$(JPACKAGE_TARGETS): $(call FindLib, java.base, java)
@@ -83,6 +83,9 @@ public void prepareApplicationFiles(Map<String, ? super Object> params)
// create the primary launcher
createLauncherForEntryPoint(params, null);

// create app launcher shared library
createLauncherLib();

// create the additional launchers, if any
List<Map<String, ? super Object>> entryPoints
= ADD_LAUNCHERS.fetchFrom(params);
@@ -95,6 +98,17 @@ public void prepareApplicationFiles(Map<String, ? super Object> params)
copyApplication(params);
}

private void createLauncherLib() throws IOException {
Path path = appLayout.pathGroup().getPath(
ApplicationLayout.PathRole.LINUX_APPLAUNCHER_LIB);
try (InputStream resource = getResourceAsStream("libjpackageapplauncher.so")) {
writeEntry(resource, path);
}

path.toFile().setExecutable(true, false);
path.toFile().setWritable(true, true);
}

private void createLauncherForEntryPoint(Map<String, ? super Object> params,
Map<String, ? super Object> mainParams) throws IOException {
// Copy executable to launchers folder
@@ -0,0 +1,148 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <errno.h>
#include <linux/limits.h>
#include <unistd.h>
#include <libgen.h>
#include "JvmLauncher.h"
#include "LinuxPackage.h"


#define STATUS_FAILURE 1

typedef JvmlLauncherHandle (*JvmlLauncherAPI_CreateFunType)(int argc, char *argv[]);

static int appArgc;
static char **appArgv;


static JvmlLauncherData* initJvmlLauncherData(void) {
char* launcherLibPath = 0;
void* jvmLauncherLibHandle = 0;
JvmlLauncherAPI_GetAPIFunc getApi = 0;
JvmlLauncherAPI_CreateFunType createJvmlLauncher = 0;
JvmlLauncherAPI* api = 0;
JvmlLauncherHandle jvmLauncherHandle = 0;
JvmlLauncherData* result = 0;

launcherLibPath = getJvmLauncherLibPath();
if (!launcherLibPath) {
goto cleanup;
}

jvmLauncherLibHandle = dlopen(launcherLibPath, RTLD_NOW | RTLD_LOCAL);
if (!jvmLauncherLibHandle) {
JP_LOG_ERRMSG(dlerror());
goto cleanup;
}

getApi = dlsym(jvmLauncherLibHandle, "jvmLauncherGetAPI");
if (!getApi) {
JP_LOG_ERRMSG(dlerror());
goto cleanup;
}

api = (*getApi)();
if (!api) {
JP_LOG_ERRMSG("Failed to get JvmlLauncherAPI instance");
goto cleanup;
}

createJvmlLauncher = dlsym(jvmLauncherLibHandle, "jvmLauncherCreate");
if (!createJvmlLauncher) {
JP_LOG_ERRMSG(dlerror());
goto cleanup;
}

jvmLauncherHandle = (*createJvmlLauncher)(appArgc, appArgv);
if (!jvmLauncherHandle) {
goto cleanup;
}

result = jvmLauncherCreateJvmlLauncherData(api, jvmLauncherHandle);
/* Handle released in jvmLauncherCreateJvmlLauncherData() */
jvmLauncherHandle = 0;

cleanup:
if (jvmLauncherHandle) {
jvmLauncherCloseHandle(api, jvmLauncherHandle);
}
if (jvmLauncherLibHandle) {
dlclose(jvmLauncherLibHandle);
}
free(launcherLibPath);

return result;
}


static int launchJvm(JvmlLauncherData* cfg) {
void* jliLibHandle = 0;
void* JLI_Launch;
int exitCode = STATUS_FAILURE;

jliLibHandle = dlopen(cfg->jliLibPath, RTLD_NOW | RTLD_LOCAL);
if (!jliLibHandle) {
JP_LOG_ERRMSG(dlerror());
goto cleanup;
}

JLI_Launch = dlsym(jliLibHandle, "JLI_Launch");
if (!JLI_Launch) {
JP_LOG_ERRMSG(dlerror());
goto cleanup;
}

exitCode = jvmLauncherStartJvm(cfg, JLI_Launch);

cleanup:
if (jliLibHandle) {
dlclose(jliLibHandle);
}

return exitCode;
}


int main(int argc, char *argv[]) {
int exitCode = STATUS_FAILURE;
JvmlLauncherData* jvmLauncherData;

appArgc = argc;
appArgv = argv;

jvmLauncherData = initJvmlLauncherData();
if (jvmLauncherData) {
exitCode = launchJvm(jvmLauncherData);
free(jvmLauncherData);
}

return exitCode;
}
Loading

0 comments on commit fac3c2d

Please sign in to comment.