8248239: jpackage adds some arguments twice in case it is re-executed by JLI
Reviewed-by: herrick, almatvee
This commit is contained in:
parent
c0b9999c35
commit
5a365e8627
@ -24,14 +24,24 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "AppLauncher.h"
|
#include "AppLauncher.h"
|
||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
#include "UnixSysInfo.h"
|
#include "UnixSysInfo.h"
|
||||||
#include "Package.h"
|
#include "Package.h"
|
||||||
|
#include "Log.h"
|
||||||
|
#include "ErrorHandling.h"
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
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() {
|
void launchApp() {
|
||||||
setlocale(LC_ALL, "en_US.utf8");
|
setlocale(LC_ALL, "en_US.utf8");
|
||||||
@ -57,6 +67,56 @@ void launchApp() {
|
|||||||
ownerPackage.initAppLauncher(appLauncher);
|
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();
|
appLauncher.launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
|
|
||||||
AppLauncher::AppLauncher() {
|
AppLauncher::AppLauncher() {
|
||||||
|
setInitJvmFromCmdlineOnly(false);
|
||||||
launcherPath = SysInfo::getProcessModulePath();
|
launcherPath = SysInfo::getProcessModulePath();
|
||||||
args = SysInfo::getCommandArgs();
|
args = SysInfo::getCommandArgs();
|
||||||
}
|
}
|
||||||
@ -116,8 +117,17 @@ Jvm* AppLauncher::createJvmLauncher() const {
|
|||||||
|
|
||||||
(*jvm)
|
(*jvm)
|
||||||
.setPath(findJvmLib(cfgFile, defaultRuntimePath, jvmLibNames))
|
.setPath(findJvmLib(cfgFile, defaultRuntimePath, jvmLibNames))
|
||||||
.addArgument(launcherPath)
|
.addArgument(launcherPath);
|
||||||
.initFromConfigFile(cfgFile);
|
|
||||||
|
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();
|
return jvm.release();
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,11 @@ public:
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppLauncher& setInitJvmFromCmdlineOnly(bool v) {
|
||||||
|
initJvmFromCmdlineOnly = v;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
AppLauncher& addJvmLibName(const tstring& v) {
|
AppLauncher& addJvmLibName(const tstring& v) {
|
||||||
jvmLibNames.push_back(v);
|
jvmLibNames.push_back(v);
|
||||||
return *this;
|
return *this;
|
||||||
@ -78,6 +83,7 @@ private:
|
|||||||
tstring appDirPath;
|
tstring appDirPath;
|
||||||
tstring imageRoot;
|
tstring imageRoot;
|
||||||
tstring_array jvmLibNames;
|
tstring_array jvmLibNames;
|
||||||
|
bool initJvmFromCmdlineOnly;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // AppLauncher_h
|
#endif // AppLauncher_h
|
||||||
|
Loading…
x
Reference in New Issue
Block a user