Skip to content
Permalink
Browse files

8248239: jpackage adds some arguments twice in case it is re-executed…

… by JLI

Reviewed-by: herrick, almatvee
  • Loading branch information
bell-sw authored and Alexey Semenyuk committed Jul 24, 2020
1 parent c0b9999 commit 5a365e8627919954c2bcdd5af1a08d9e7c6e6a14
@@ -24,14 +24,24 @@
*/

#include <stdio.h>
#include <stdlib.h>
#include "AppLauncher.h"
#include "FileUtils.h"
#include "UnixSysInfo.h"
#include "Package.h"
#include "Log.h"
#include "ErrorHandling.h"


namespace {

size_t hash(const std::string& str) {
size_t h = 0;
for(std::string::const_iterator it = str.begin(); it != str.end(); ++it) {
h = 31 * h + (*it & 0xff);
}
return h;
}

void launchApp() {
setlocale(LC_ALL, "en_US.utf8");
@@ -57,6 +67,56 @@ void launchApp() {
ownerPackage.initAppLauncher(appLauncher);
}

const std::string _JPACKAGE_LAUNCHER = "_JPACKAGE_LAUNCHER";

std::string launchInfo = SysInfo::getEnvVariable(std::nothrow,
_JPACKAGE_LAUNCHER, "");

const std::string thisLdLibraryPath = SysInfo::getEnvVariable(std::nothrow,
"LD_LIBRARY_PATH", "");

const size_t thisHash = hash(thisLdLibraryPath);

if (!launchInfo.empty()) {
LOG_TRACE(tstrings::any() << "Found "
<< _JPACKAGE_LAUNCHER << "=[" << launchInfo << "]");

tistringstream iss(launchInfo);
iss.exceptions(std::ios::failbit | std::ios::badbit);

size_t hash = 0;
iss >> hash;

launchInfo = "";

if (thisHash != hash) {
// This launcher execution is the result of execve() call from
// withing JVM.
// This means all JVM arguments are already configured in launcher
// process command line.
// No need to construct command line for JVM.
LOG_TRACE("Not building JVM arguments from cfg file");
appLauncher.setInitJvmFromCmdlineOnly(true);
}
} else {
// Changed LD_LIBRARY_PATH environment variable might result in
// execve() call from within JVM.
// Set _JPACKAGE_LAUNCHER environment variable accordingly so that
// restarted launcher process can detect a restart.

launchInfo = (tstrings::any() << thisHash).str();
}

JP_TRY;
if (0 != setenv(_JPACKAGE_LAUNCHER.c_str(), launchInfo.c_str(), 1)) {
JP_THROW(tstrings::any() << "setenv(" << _JPACKAGE_LAUNCHER
<< ", " << launchInfo << ") failed. Error: " << lastCRTError());
} else {
LOG_TRACE(tstrings::any() << "Set "
<< _JPACKAGE_LAUNCHER << "=[" << launchInfo << "]");
}
JP_CATCH_ALL;

appLauncher.launch();
}

@@ -35,6 +35,7 @@


AppLauncher::AppLauncher() {
setInitJvmFromCmdlineOnly(false);
launcherPath = SysInfo::getProcessModulePath();
args = SysInfo::getCommandArgs();
}
@@ -116,8 +117,17 @@ Jvm* AppLauncher::createJvmLauncher() const {

(*jvm)
.setPath(findJvmLib(cfgFile, defaultRuntimePath, jvmLibNames))
.addArgument(launcherPath)
.initFromConfigFile(cfgFile);
.addArgument(launcherPath);

if (initJvmFromCmdlineOnly) {
tstring_array::const_iterator argIt = args.begin();
const tstring_array::const_iterator argEnd = args.end();
for (; argIt != argEnd; ++argIt) {
(*jvm).addArgument(*argIt);
}
} else {
(*jvm).initFromConfigFile(cfgFile);
}

return jvm.release();
}
@@ -51,6 +51,11 @@ class AppLauncher {
return *this;
}

AppLauncher& setInitJvmFromCmdlineOnly(bool v) {
initJvmFromCmdlineOnly = v;
return *this;
}

AppLauncher& addJvmLibName(const tstring& v) {
jvmLibNames.push_back(v);
return *this;
@@ -78,6 +83,7 @@ class AppLauncher {
tstring appDirPath;
tstring imageRoot;
tstring_array jvmLibNames;
bool initJvmFromCmdlineOnly;
};

#endif // AppLauncher_h

0 comments on commit 5a365e8

Please sign in to comment.