diff --git a/core/src/main/java/hudson/WebAppMain.java b/core/src/main/java/hudson/WebAppMain.java index 72374e498ea6b9529b75000a8ea301d896aee93a..6b361f6000d60c9481ba37260b2c1f3f8106aab5 100644 --- a/core/src/main/java/hudson/WebAppMain.java +++ b/core/src/main/java/hudson/WebAppMain.java @@ -4,9 +4,18 @@ import com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider import com.thoughtworks.xstream.core.JVM; import hudson.model.Hudson; import hudson.model.User; -import hudson.triggers.Trigger; import hudson.triggers.SafeTimerTask; -import hudson.util.*; +import hudson.triggers.Trigger; +import hudson.util.HudsonIsLoading; +import hudson.util.IncompatibleServletVersionDetected; +import hudson.util.IncompatibleVMDetected; +import hudson.util.InsufficientPermissionDetected; +import hudson.util.NoHomeDir; +import hudson.util.RingBufferLogHandler; +import hudson.util.NoTempDir; +import org.jvnet.localizer.LocaleProvider; +import org.kohsuke.stapler.Stapler; +import org.kohsuke.stapler.StaplerRequest; import javax.naming.Context; import javax.naming.InitialContext; @@ -20,16 +29,12 @@ import javax.xml.transform.TransformerFactoryConfigurationError; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Properties; +import java.net.URL; +import java.net.URLClassLoader; import java.util.Locale; +import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; -import java.net.URLClassLoader; -import java.net.URL; - -import org.kohsuke.stapler.Stapler; -import org.kohsuke.stapler.StaplerRequest; -import org.jvnet.localizer.LocaleProvider; /** * Entry point when Hudson is used as a webapp. @@ -97,6 +102,17 @@ public class WebAppMain implements ServletContextListener { return; } + // some containers (in particular Tomcat) doesn't abort a launch + // even if the temp directory doesn't exist. + // check that and report an error + try { + File f = File.createTempFile("test", "test"); + f.delete(); + } catch (IOException e) { + context.setAttribute(APP,new NoTempDir(e)); + return; + } + // Tomcat breaks XSLT with JDK 5.0 and onward. Check if that's the case, and if so, // try to correct it try { diff --git a/core/src/main/java/hudson/util/NoTempDir.java b/core/src/main/java/hudson/util/NoTempDir.java new file mode 100644 index 0000000000000000000000000000000000000000..12cfff9055e14780382f017752fff2228e494f20 --- /dev/null +++ b/core/src/main/java/hudson/util/NoTempDir.java @@ -0,0 +1,32 @@ +package hudson.util; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +/** + * Model object used to display the error top page if + * there appears to be no temporary directory. + * + *

+ * index.jelly would display a nice friendly error page. + * + * @author Kohsuke Kawaguchi + */ +public class NoTempDir { + public final IOException exception; + + public NoTempDir(IOException exception) { + this.exception = exception; + } + + public String getStackTrace() { + StringWriter sw = new StringWriter(); + exception.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } + + public String getTempDir() { + return System.getProperty("java.io.tmpdir"); + } +} diff --git a/core/src/main/resources/hudson/util/NoTempDir/index.jelly b/core/src/main/resources/hudson/util/NoTempDir/index.jelly new file mode 100644 index 0000000000000000000000000000000000000000..aa92ba7bf18f1a54054b71d1656abbb12abcbdb8 --- /dev/null +++ b/core/src/main/resources/hudson/util/NoTempDir/index.jelly @@ -0,0 +1,11 @@ + + + + + +

[!]${%Error}

+

${%description(it.tempDir)}

+
${it.stackTrace}
+ + + \ No newline at end of file diff --git a/core/src/main/resources/hudson/util/NoTempDir/index.properties b/core/src/main/resources/hudson/util/NoTempDir/index.properties new file mode 100644 index 0000000000000000000000000000000000000000..715da0ad157b81ad729306090e573f6ff34ee680 --- /dev/null +++ b/core/src/main/resources/hudson/util/NoTempDir/index.properties @@ -0,0 +1,4 @@ +description=\ + Unable to create a temporary file. This is most likely caused by \ + a mis-configuration of the container. The JVM seems to be told to use \ + "{0}" as the temporary directory. Does this directory exist and is it writable? \ No newline at end of file