Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Bug 1324217 - Checks %TMP% and %TEMP% paths on windows, and tries to …
Browse files Browse the repository at this point in the history
…create them if needed
  • Loading branch information
josejulio authored and spinder committed Sep 6, 2017
1 parent 5d0421c commit 50669ee
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
import org.apache.log4j.Level;
import org.apache.log4j.LogManager;
import org.apache.log4j.xml.DOMConfigurator;
import org.rhq.core.system.OperatingSystemType;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -499,32 +500,36 @@ public static void main(String[] args) {
}
}

private void checkTempDir() {
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
private void checkTempDir(File tmpDir, String tmpDirKey) {
if (!tmpDir.exists()) {
LOG.warn("Invalid java.io.tmpdir: [" + tmpDir.getAbsolutePath() + "] does not exist.");
LOG.warn("Invalid " + tmpDirKey + ": [" + tmpDir.getAbsolutePath() + "] does not exist.");
try {
LOG.info("Creating java.io.tmpdir: [" + tmpDir.getAbsolutePath() + "]");
LOG.info("Creating " + tmpDirKey + ": [" + tmpDir.getAbsolutePath() + "]");
tmpDir.mkdir();
} catch (Throwable t) {
throw new RuntimeException("Startup failed: Could not create missing java.io.tmpdir ["
+ tmpDir.getAbsolutePath() + "]", t);
throw new RuntimeException("Startup failed: Could not create missing " + tmpDirKey + " ["
+ tmpDir.getAbsolutePath() + "]", t);
}
}
if (!tmpDir.isDirectory()) {
throw new RuntimeException("Startup failed: java.io.tmpdir [" + tmpDir.getAbsolutePath()
+ "] is not a directory");
throw new RuntimeException("Startup failed: " + tmpDirKey + " [" + tmpDir.getAbsolutePath()
+ "] is not a directory");
}
if (!tmpDir.canRead() || !tmpDir.canExecute()) {
throw new RuntimeException("Startup failed: java.io.tmpdir [" + tmpDir.getAbsolutePath()
+ "] is not readable");
throw new RuntimeException("Startup failed: " + tmpDirKey + " [" + tmpDir.getAbsolutePath()
+ "] is not readable");
}
if (!tmpDir.canWrite()) {
throw new RuntimeException("Startup failed: java.io.tmpdir [" + tmpDir.getAbsolutePath()
+ "] is not writable");
throw new RuntimeException("Startup failed: " + tmpDirKey + " [" + tmpDir.getAbsolutePath()
+ "] is not writable");
}
}

private void checkTempDir() {
final String javaIoTmpDir = "java.io.tmpdir";
checkTempDir(new File(System.getProperty(javaIoTmpDir)), javaIoTmpDir);
}

/**
* Constructor for {@link AgentMain} that loads the agent configuration and prepare some additional internal data.
*
Expand Down Expand Up @@ -578,6 +583,27 @@ public AgentMain(String[] args) throws Exception {

checkTempDir();

if (SystemInfoFactory.createSystemInfo().getOperatingSystemType().equals(OperatingSystemType.WINDOWS)) {
// Windows LocalSystemAccount temp folder (defined by %TEMP%) doesn't exist.
// This user is default when using the wrapper.
// Perform the same checks for the values of these environments
// Log an error if something goes wrong, this won't cause problem to all the users, unless they bundle
// deployment scripts make use of %tmp% or %temp%
final String[] TMP_ENVIRONMENT_NAMES = { "TMP", "TEMP" };
for (String tmpEnvironment : TMP_ENVIRONMENT_NAMES) {
String tmpDirPath = null;
try {
tmpDirPath = System.getenv(tmpEnvironment);
if (tmpDirPath != null) {
checkTempDir(new File(tmpDirPath), tmpEnvironment);
}
} catch (RuntimeException ex) {
LOG.error(ex, AgentI18NResourceKeys.AGENT_UNABLE_TO_USE_TEMP_DIR_FROM_ENV,
tmpDirPath, tmpEnvironment);
}
}
}

return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ public interface AgentI18NResourceKeys {
@I18NMessage("This agent has auto-update enabled and the build identifier of [{0}] does not match the latest build identifier [{1}] - this agent will be considered unsupported and an agent update will now be applied")
String AGENT_BUILD_DOES_NOT_MATCH_AUTO_UPDATE_NOW = "AgentMain.agent-build-no-match-update-now";

@I18NMessage("Unable to use temporal directory [{0}] found on environment [{1}]. This might lead to unexpected results when deploying bundles on this Platform that use the variable %{1}%.")
String AGENT_UNABLE_TO_USE_TEMP_DIR_FROM_ENV = "AgentMain.agent-unable-to-use-temp-dir-from-env";

@I18NMessage("The agent is not talking to its primary server [{0}:{1,number,#}] - it is talking to [{2}:{3,number,#}]")
String NOT_TALKING_TO_PRIMARY_SERVER = "PrimaryServerSwitchoverThread.not-talking-to-primary";

Expand Down

0 comments on commit 50669ee

Please sign in to comment.