@Override public void run() { try { Log.i(TAG, "Starting openvpn"); startOpenVPNThreadArgs(mArgv, mProcessEnv); Log.i(TAG, "Giving up"); } catch (Exception e) { VpnStatus.logException("Starting OpenVPN Thread", e); Log.e(TAG, "OpenVPNThread Got " + e.toString()); } finally { int exitvalue = 0; try { if (mProcess != null) exitvalue = mProcess.waitFor(); } catch (IllegalThreadStateException ite) { VpnStatus.logError("Illegal Thread state: " + ite.getLocalizedMessage()); } catch (InterruptedException ie) { VpnStatus.logError("InterruptedException: " + ie.getLocalizedMessage()); } if (exitvalue != 0) { VpnStatus.logError("Process exited with exit value " + exitvalue); if (mBrokenPie) { /* This will probably fail since the NoPIE binary is probably not written */ String[] noPieArgv = VPNLaunchHelper.replacePieWithNoPie(mArgv); // We are already noPIE, nothing to gain if (!noPieArgv.equals(mArgv)) { mArgv = noPieArgv; VpnStatus.logInfo("PIE Version could not be executed. Trying no PIE version"); run(); return; } } } VpnStatus.updateStateString( "NOPROCESS", "No process running.", R.string.state_noprocess, ConnectionStatus.LEVEL_NOTCONNECTED); if (mDumpPath != null) { try { BufferedWriter logout = new BufferedWriter(new FileWriter(mDumpPath + ".log")); SimpleDateFormat timeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN); for (LogItem li : VpnStatus.getlogbuffer()) { String time = timeformat.format(new Date(li.getLogtime())); logout.write(time + " " + li.getString(mService) + "\n"); } logout.close(); VpnStatus.logError(R.string.minidump_generated); } catch (IOException e) { VpnStatus.logError("Writing minidump log: " + e.getLocalizedMessage()); } } mService.processDied(); Log.i(TAG, "Exiting"); } }
public AsyncTask start(boolean looped) { this.stoprequested = false; this.looped = looped; try { this.thread.start(); } catch (IllegalThreadStateException ex) { ex.printStackTrace(); } return this; }
@Override protected Set<Checksum> stage(StageRequest request) throws IOException, CacheException { try { FileAttributes attributes = request.getFileAttributes(); String[] fetchCommand = getFetchCommand(request.getReplicaUri(), attributes); new HsmRunSystem( name, MAX_LINES, request.getDeadline() - System.currentTimeMillis(), fetchCommand) .execute(); return readChecksumFromHsm(request.getFile()); } catch (IllegalThreadStateException e) { throw new CacheException(3, e.getMessage(), e); } }
/** * Calls interrupt() on each of the running threads. * * @throws IllegalThreadStateException if threads were not started */ public synchronized void interrupt() { if (!started) throw new IllegalThreadStateException(getClass().getSimpleName() + " not started !"); for (Runner t : runners) { try { t.interrupt(); } catch (IllegalThreadStateException ex) { // t might have finished its execution ex.printStackTrace(); } } }
@Override protected Set<URI> flush(FlushRequest request) throws IOException, CacheException { try { Set<URI> locations = new HashSet<>(); String[] storeCommand = getFlushCommand(request.getReplicaUri(), request.getFileAttributes()); String output = new HsmRunSystem( name, MAX_LINES, request.getDeadline() - System.currentTimeMillis(), storeCommand) .execute(); for (String uri : Splitter.on("\n").trimResults().omitEmptyStrings().split(output)) { try { locations.add(new URI(uri)); } catch (URISyntaxException e) { throw new CacheException(2, "HSM script produced bad URI: " + e.getMessage(), e); } } return locations; } catch (IllegalThreadStateException e) { throw new CacheException(3, e.getMessage(), e); } }
public boolean ConnectToNXT(NXTInfo info) { if (m_connected) return true; setM_connected(m_connecter.connectTo(info.name, info.deviceAddress, NXTCommFactory.BLUETOOTH)); if (!m_connected) return false; m_is = m_connecter.getInputStream(); m_os = m_connecter.getOutputStream(); if (m_is == null || m_os == null) { setM_connected(false); } if (!m_connected) return false; try { m_reader.start(); // Start to listen for incoming messages } catch (IllegalThreadStateException e) { e.printStackTrace(); } return m_connected; }
public static String[] waitProcesEnd(Process p, int timeOutInSeconds) { int exitCode = -1; int timeout = 120; if (timeout < timeOutInSeconds) { timeout = timeOutInSeconds; } Calendar calendar = Calendar.getInstance(); Date current = new Date(); calendar.setTime(current); calendar.add(Calendar.SECOND, timeout); Date conditionTimeOut = calendar.getTime(); while (true) { try { exitCode = p.exitValue(); break; } catch (IllegalThreadStateException e) { Date now = new Date(); if (now.after(conditionTimeOut)) { e.printStackTrace(); throw new IllegalArgumentException( "process may be die, the timeout for wait the process is " + String.valueOf(timeout) + " seconds"); } } } String output = ""; BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(p.getInputStream(), "GBK")); } catch (UnsupportedEncodingException e1) { reader = new BufferedReader(new InputStreamReader(p.getInputStream())); e1.printStackTrace(); } try { // System.getProperty("line.separator"); while (true) { String line = reader.readLine(); if (line == null) { break; } else { output = output + line + "\n"; } } if (!output.equals("")) { output = output.substring(0, output.length() - "\n".length()); } } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException("Failed to read output of process:" + e.getMessage()); } finally { try { reader.close(); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException("Failed to read output of process:" + e.getMessage()); } } String[] result = {output, String.valueOf(exitCode)}; return result; }