Skip to content
Browse files

Avoiding race conditions when starting iodine

Conflicts:

	src/org/airportinternet/conn/Connector.java
  • Loading branch information...
1 parent a455ee2 commit 12b4f0b11b91755684e799193c027666b9f452d2 @Motiejus committed Mar 13, 2012
Showing with 14 additions and 4 deletions.
  1. +1 −0 src/org/airportinternet/conn/Connector.java
  2. +13 −4 src/org/airportinternet/conn/ForkConnector.java
View
1 src/org/airportinternet/conn/Connector.java
@@ -173,6 +173,7 @@ public IBinder onBind(Intent intent) {
* Called from Connector when message was received from iodine
*/
protected void sendLog(String message) {
+ Log.e("sendLog", message);
fullLog.append(message);
if (client != null) {
Message msg = Message.obtain();
View
17 src/org/airportinternet/conn/ForkConnector.java
@@ -23,8 +23,8 @@
private Handler mHandler = new Handler();
private Setting s;
- private Process proc;
- private BufferedReader in;
+ private Process proc = null;
+ private BufferedReader in = null;
private List<String> cmdc;
@@ -60,6 +60,9 @@ public void stop() {
}
}
+ /* Avoiding race condition below */
+ private boolean watchDogStartedTheProcess = false;
+
@Override
protected void start(Setting setting) {
s = setting;
@@ -70,7 +73,7 @@ protected void start(Setting setting) {
watchdog = new Thread() {
public void run() {
- Log.d("watchdog", "watchdog started");
+ Log.d("watchdog", "watchdog started, locking watchdogLock");
watchdogLock.lock();
try {
proc = new ProcessBuilder(cmdc).redirectErrorStream(
@@ -81,7 +84,9 @@ public void run() {
e.printStackTrace();
sendLog("Failed to start iodine");
}
+ watchDogStartedTheProcess = true;
watchdogCond.signal();
+ Log.d("watchdog", "unlocking watchdogLock");
watchdogLock.unlock();
try {
@@ -97,14 +102,18 @@ public void run() {
watchdog.start();
connecting();
+ Log.d("ForkConnector:start", "before locking watchdogLock");
watchdogLock.lock();
+ Log.d("ForkConnector:start", "locked watchdogLock");
try {
- watchdogCond.await();
+ while(!watchDogStartedTheProcess)
+ watchdogCond.await();
} catch (InterruptedException e) {
// should never happen
e.printStackTrace();
} finally {
watchdogLock.unlock();
+ Log.d("ForkConnector:start", "unlocked watchdogLock");
}
mHandler.post(poller);
running = true;

0 comments on commit 12b4f0b

Please sign in to comment.
Something went wrong with that request. Please try again.