<!-- -->
<!-- passShellEnvironment Should the shell environment variables (if -->
<!-- any) be passed to the CGI script? [false] -->
+ <!-- -->
+ <!-- stderrTimeout The time (in milliseconds) to wait for the -->
+ <!-- reading of stdErr to complete before -->
+ <!-- terminating the CGI process. [2000] -->
<!--
<servlet>
private String cgiExecutable = "perl";
/** the encoding to use for parameters */
- private String parameterEncoding = System.getProperty("file.encoding",
- "UTF-8");
+ private String parameterEncoding =
+ System.getProperty("file.encoding", "UTF-8");
+
+ /**
+ * The time (in milliseconds) to wait for the reading of stdErr to complete
+ * before terminating the CGI process.
+ */
+ private long stderrTimeout = 2000;
/** object used to ensure multiple threads don't try to expand same file */
static Object expandFileLock = new Object();
parameterEncoding = getServletConfig().getInitParameter("parameterEncoding");
}
+ if (getServletConfig().getInitParameter("stderrTimeout") != null) {
+ stderrTimeout = Long.parseLong(getServletConfig().getInitParameter(
+ "stderrTimeout"));
+ }
+
}
BufferedReader cgiHeaderReader = null;
InputStream cgiOutput = null;
BufferedReader commandsStdErr = null;
+ Thread errReaderThread = null;
BufferedOutputStream commandsStdIn = null;
Process proc = null;
int bufRead = -1;
(new InputStreamReader(proc.getErrorStream()));
final BufferedReader stdErrRdr = commandsStdErr ;
- new Thread() {
+ errReaderThread = new Thread() {
@Override
public void run () {
sendToLog(stdErrRdr) ;
}
- }.start() ;
+ };
+ errReaderThread.start();
InputStream cgiHeaderStream =
new HTTPHeaderInputStream(proc.getInputStream());
log ("Exception closing output stream " + ioe);
}
}
+ // Make sure the error stream reader has finished
+ if (errReaderThread != null) {
+ try {
+ errReaderThread.join(stderrTimeout);
+ } catch (InterruptedException e) {
+ log ("Interupted waiting for stderr reader thread");
+ }
+ }
if (debug > 4) {
log ("Running finally block");
}