summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2016-12-04 13:03:25 +0100
committerArne Schwabe <arne@rfc2549.org>2016-12-04 13:03:25 +0100
commit73b79c6874341584d468d58e7a474ca283b062fb (patch)
treea7d5444a9179a5a879839f298eafd81f513c0827
parent1dd3f0d7d5ec6c9a70e92994d34a7521808ba8ec (diff)
Fix notify if no cached logfiles are available.
-rw-r--r--main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java106
1 files changed, 52 insertions, 54 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
index 67bd105e..459333fb 100644
--- a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
+++ b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java
@@ -141,77 +141,75 @@ class LogFileHandler extends Handler {
VpnStatus.logException(e);
e.printStackTrace();
// ignore reading file error
+ } finally {
+ synchronized (VpnStatus.readFileLock) {
+ VpnStatus.readFileLog = true;
+ VpnStatus.readFileLock.notifyAll();
+ }
}
}
protected void readCacheContents(InputStream in) throws IOException {
- try {
- BufferedInputStream logFile = new BufferedInputStream(in);
+ BufferedInputStream logFile = new BufferedInputStream(in);
- byte[] buf = new byte[16384];
- int read = logFile.read(buf, 0, 5);
- int itemsRead = 0;
+ byte[] buf = new byte[16384];
+ int read = logFile.read(buf, 0, 5);
+ int itemsRead = 0;
- readloop:
- while (read >= 5) {
- int skipped = 0;
- while (buf[skipped] != MAGIC_BYTE) {
- skipped++;
- if (!(logFile.read(buf, skipped + 4, 1) == 1) || skipped + 10 > buf.length) {
- VpnStatus.logDebug(String.format(Locale.US, "Skipped %d bytes and no a magic byte found", skipped));
- break readloop;
- }
+ readloop:
+ while (read >= 5) {
+ int skipped = 0;
+ while (buf[skipped] != MAGIC_BYTE) {
+ skipped++;
+ if (!(logFile.read(buf, skipped + 4, 1) == 1) || skipped + 10 > buf.length) {
+ VpnStatus.logDebug(String.format(Locale.US, "Skipped %d bytes and no a magic byte found", skipped));
+ break readloop;
}
- if (skipped > 0)
- VpnStatus.logDebug(String.format(Locale.US, "Skipped %d bytes before finding a magic byte", skipped));
-
- int len = ByteBuffer.wrap(buf, skipped + 1, 4).asIntBuffer().get();
-
- // Marshalled LogItem
- int pos = 0;
- byte buf2[] = new byte[buf.length];
-
- while (pos < len) {
- byte b = (byte) logFile.read();
- if (b == MAGIC_BYTE) {
- VpnStatus.logDebug(String.format(Locale.US, "Unexpected magic byte found at pos %d, abort current log item", pos));
+ }
+ if (skipped > 0)
+ VpnStatus.logDebug(String.format(Locale.US, "Skipped %d bytes before finding a magic byte", skipped));
+
+ int len = ByteBuffer.wrap(buf, skipped + 1, 4).asIntBuffer().get();
+
+ // Marshalled LogItem
+ int pos = 0;
+ byte buf2[] = new byte[buf.length];
+
+ while (pos < len) {
+ byte b = (byte) logFile.read();
+ if (b == MAGIC_BYTE) {
+ VpnStatus.logDebug(String.format(Locale.US, "Unexpected magic byte found at pos %d, abort current log item", pos));
+ read = logFile.read(buf, 1, 4) + 1;
+ continue readloop;
+ } else if (b == MAGIC_BYTE + 1) {
+ b = (byte) logFile.read();
+ if (b == 0)
+ b = MAGIC_BYTE;
+ else if (b == 1)
+ b = MAGIC_BYTE + 1;
+ else {
+ VpnStatus.logDebug(String.format(Locale.US, "Escaped byte not 0 or 1: %d", b));
read = logFile.read(buf, 1, 4) + 1;
continue readloop;
- } else if (b == MAGIC_BYTE + 1) {
- b = (byte) logFile.read();
- if (b == 0)
- b = MAGIC_BYTE;
- else if (b == 1)
- b = MAGIC_BYTE + 1;
- else {
- VpnStatus.logDebug(String.format(Locale.US, "Escaped byte not 0 or 1: %d", b));
- read = logFile.read(buf, 1, 4) + 1;
- continue readloop;
- }
}
- buf2[pos++] = b;
}
+ buf2[pos++] = b;
+ }
- restoreLogItem(buf2, len);
+ restoreLogItem(buf2, len);
- //Next item
- read = logFile.read(buf, 0, 5);
- itemsRead++;
- if (itemsRead > 2 * VpnStatus.MAXLOGENTRIES) {
- VpnStatus.logError("Too many logentries read from cache, aborting.");
- read = 0;
- }
-
- }
- VpnStatus.logDebug(R.string.reread_log, itemsRead);
- } finally {
- synchronized (VpnStatus.readFileLock) {
- VpnStatus.readFileLog = true;
- VpnStatus.readFileLock.notifyAll();
+ //Next item
+ read = logFile.read(buf, 0, 5);
+ itemsRead++;
+ if (itemsRead > 2 * VpnStatus.MAXLOGENTRIES) {
+ VpnStatus.logError("Too many logentries read from cache, aborting.");
+ read = 0;
}
+
}
+ VpnStatus.logDebug(R.string.reread_log, itemsRead);
}
protected void restoreLogItem(byte[] buf, int len) throws UnsupportedEncodingException {