1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-06 07:45:50 +02:00

[245714] don't launch a server when we're not able to read from the socket in the ServerLauncher

This commit is contained in:
David McKnight 2008-09-03 19:24:12 +00:00
parent daf798e433
commit 1484919e21

View file

@ -14,6 +14,7 @@
* Contributors: * Contributors:
* David McKnight (IBM) - [193426] don't display exceptions * David McKnight (IBM) - [193426] don't display exceptions
* David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed * David McKnight (IBM) - [226561] [apidoc] Add API markup to RSE Javadocs where extend / implement is allowed
* David McKnight (IBM) - [245714] [dstore] Multiple user ID/password prompts and connect fails
*******************************************************************************/ *******************************************************************************/
package org.eclipse.dstore.core.server; package org.eclipse.dstore.core.server;
@ -207,6 +208,8 @@ public class ServerLauncher extends Thread {
String password = null; String password = null;
_port = null; _port = null;
boolean problemReadingSocket = false;
try try
{ {
user = _reader.readLine(); user = _reader.readLine();
@ -218,15 +221,19 @@ public class ServerLauncher extends Thread {
// don't display exceptions 193426 // don't display exceptions 193426
//e.printStackTrace(); //e.printStackTrace();
_port = "0"; //$NON-NLS-1$ _port = "0"; //$NON-NLS-1$
// this is probably an SSL exception
_writer.println(IDataStoreConstants.SERVER_FAILURE + e);
problemReadingSocket = true;
} }
if (_serverPortRange != null && (_port == null || _port.equals("0"))) //$NON-NLS-1$ if (_serverPortRange != null && (_port == null || _port.equals("0"))) //$NON-NLS-1$
{ {
_port = _serverPortRange; _port = _serverPortRange;
} }
if (!problemReadingSocket)
{ {
boolean isError = false; boolean isError = false;
if (_serverPortRange != null && _port != _serverPortRange) if (_serverPortRange != null && _port != _serverPortRange)
@ -241,144 +248,144 @@ public class ServerLauncher extends Thread {
} }
if (!isError) if (!isError)
{ {
// start new server // start new server
try try
{
String launchStatus = null;
String ticket = new String("" + System.currentTimeMillis()); //$NON-NLS-1$
String theOS = System.getProperty("os.name"); //$NON-NLS-1$
String timeout = "120000"; //$NON-NLS-1$
if (!theOS.toLowerCase().startsWith("win")) //$NON-NLS-1$
{ {
// assuming unix compatable String launchStatus = null;
// String ticket = new String("" + System.currentTimeMillis()); //$NON-NLS-1$
// Get the property which
// contains the authorization String theOS = System.getProperty("os.name"); //$NON-NLS-1$
// script path String timeout = "120000"; //$NON-NLS-1$
//
String authPath = System.getProperty("RSE.AUTH"); //$NON-NLS-1$
File authFile = null; if (!theOS.toLowerCase().startsWith("win")) //$NON-NLS-1$
if (authPath != null && authPath.length() > 0)
{ {
authFile = new File(authPath); // assuming unix compatable
} //
if (authFile == null || !authFile.exists()) // Get the property which
{ // contains the authorization
authPath = "perl " + _path + File.separator + "auth.pl"; //$NON-NLS-1$ //$NON-NLS-2$ // script path
} //
String authPath = System.getProperty("RSE.AUTH"); //$NON-NLS-1$
String authString = File authFile = null;
authPath if (authPath != null && authPath.length() > 0)
+ " " //$NON-NLS-1$
+ user
+ " " //$NON-NLS-1$
+ _path
+ " " //$NON-NLS-1$
+ _port
+ " " //$NON-NLS-1$
+ timeout
+ " " //$NON-NLS-1$
+ ticket
+ " " //$NON-NLS-1$
+ System.getProperty("java.home") //$NON-NLS-1$
;
String[] authArray = { "sh", "-c", authString }; //$NON-NLS-1$ //$NON-NLS-2$
// test password
_serverProcess = Runtime.getRuntime().exec(authArray);
_outReader = new BufferedReader(new InputStreamReader(_serverProcess.getInputStream()));
_errReader = new BufferedReader(new InputStreamReader(_serverProcess.getErrorStream()));
BufferedWriter inWriter = new BufferedWriter(new OutputStreamWriter(_serverProcess.getOutputStream()));
// write password
if (password != null)
{
inWriter.write(password);
inWriter.newLine();
inWriter.flush();
launchStatus = _outReader.readLine();
}
}
else
{
// launch new server
String[] cmdArray =
{ {
"java", //$NON-NLS-1$ authFile = new File(authPath);
"-DA_PLUGIN_PATH=" + _path, //$NON-NLS-1$ }
"-DDSTORE_SPIRIT_ON=true", //$NON-NLS-1$ if (authFile == null || !authFile.exists())
"org.eclipse.dstore.core.server.Server", //$NON-NLS-1$ {
_port, authPath = "perl " + _path + File.separator + "auth.pl"; //$NON-NLS-1$ //$NON-NLS-2$
timeout, }
ticket};
String authString =
_serverProcess = Runtime.getRuntime().exec(cmdArray); authPath
_outReader = new BufferedReader(new InputStreamReader(_serverProcess.getInputStream())); + " " //$NON-NLS-1$
_errReader = new BufferedReader(new InputStreamReader(_serverProcess.getErrorStream())); + user
+ " " //$NON-NLS-1$
launchStatus = "success"; //$NON-NLS-1$ + _path
} + " " //$NON-NLS-1$
+ _port
if ((launchStatus == null) || !launchStatus.equals("success")) //$NON-NLS-1$ + " " //$NON-NLS-1$
{ + timeout
_writer.println(IDataStoreConstants.AUTHENTICATION_FAILED); + " " //$NON-NLS-1$
} + ticket
else + " " //$NON-NLS-1$
{ + System.getProperty("java.home") //$NON-NLS-1$
// look for the server startup string, it needs to occur ;
// somewhere in the line.
String status = _errReader.readLine(); String[] authArray = { "sh", "-c", authString }; //$NON-NLS-1$ //$NON-NLS-2$
while (status!=null && (status.indexOf(ServerReturnCodes.RC_DSTORE_SERVER_MAGIC) < 0))
{ // test password
status = _errReader.readLine(); _serverProcess = Runtime.getRuntime().exec(authArray);
}
// now read the real server status _outReader = new BufferedReader(new InputStreamReader(_serverProcess.getInputStream()));
if (status != null) _errReader = new BufferedReader(new InputStreamReader(_serverProcess.getErrorStream()));
{ BufferedWriter inWriter = new BufferedWriter(new OutputStreamWriter(_serverProcess.getOutputStream()));
status = _errReader.readLine(); // write password
} if (password != null)
if ((status != null) && status.equals(ServerReturnCodes.RC_SUCCESS)) {
{ inWriter.write(password);
_port = _errReader.readLine(); inWriter.newLine();
_errReader.readLine(); inWriter.flush();
_writer.println(IDataStoreConstants.CONNECTED);
_writer.println(_port); launchStatus = _outReader.readLine();
_writer.println(ticket); }
System.out.println("launched new server on " + _port); //$NON-NLS-1$
connected = true;
} }
else else
{ {
if (status == null)
{ // launch new server
status = new String(IDataStoreConstants.UNKNOWN_PROBLEM); String[] cmdArray =
} {
// TODO Make sure that the client doesnt try "java", //$NON-NLS-1$
// connecting forever "-DA_PLUGIN_PATH=" + _path, //$NON-NLS-1$
_writer.println(status); "-DDSTORE_SPIRIT_ON=true", //$NON-NLS-1$
"org.eclipse.dstore.core.server.Server", //$NON-NLS-1$
_serverProcess.destroy(); _port,
_serverProcess = null; timeout,
_outReader.close(); ticket};
_outReader = null;
_serverProcess = Runtime.getRuntime().exec(cmdArray);
_errReader.close(); _outReader = new BufferedReader(new InputStreamReader(_serverProcess.getInputStream()));
_errReader = null; _errReader = new BufferedReader(new InputStreamReader(_serverProcess.getErrorStream()));
launchStatus = "success"; //$NON-NLS-1$
} }
if ((launchStatus == null) || !launchStatus.equals("success")) //$NON-NLS-1$
{
_writer.println(IDataStoreConstants.AUTHENTICATION_FAILED);
}
else
{
// look for the server startup string, it needs to occur
// somewhere in the line.
String status = _errReader.readLine();
while (status!=null && (status.indexOf(ServerReturnCodes.RC_DSTORE_SERVER_MAGIC) < 0))
{
status = _errReader.readLine();
}
// now read the real server status
if (status != null)
{
status = _errReader.readLine();
}
if ((status != null) && status.equals(ServerReturnCodes.RC_SUCCESS))
{
_port = _errReader.readLine();
_errReader.readLine();
_writer.println(IDataStoreConstants.CONNECTED);
_writer.println(_port);
_writer.println(ticket);
System.out.println("launched new server on " + _port); //$NON-NLS-1$
connected = true;
}
else
{
if (status == null)
{
status = new String(IDataStoreConstants.UNKNOWN_PROBLEM);
}
// TODO Make sure that the client doesnt try
// connecting forever
_writer.println(status);
_serverProcess.destroy();
_serverProcess = null;
_outReader.close();
_outReader = null;
_errReader.close();
_errReader = null;
}
}
}
catch (IOException e)
{
_writer.println(IDataStoreConstants.SERVER_FAILURE + e);
} }
}
catch (IOException e)
{
_writer.println(IDataStoreConstants.SERVER_FAILURE + e);
}
} }
} }