From 4e61d9703046fa2ea560c27a93b690b103831faf Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 15 Oct 2018 10:45:52 -0400 Subject: [PATCH 1/3] Report to logcat when android logging thread terminates unexpectedly. --- ports/libsimpleservo/src/jniapi.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/src/jniapi.rs index f4633429f11..efb67ff741e 100644 --- a/ports/libsimpleservo/src/jniapi.rs +++ b/ports/libsimpleservo/src/jniapi.rs @@ -483,7 +483,10 @@ fn redirect_stdout_to_logcat() { let end = if result == 0 { return; } else if result < 0 { - return; /* TODO: report problem */ + unsafe { + __android_log_write(3, tag, b"error in log thread; closing\0".as_ptr() as *const _); + } + return; } else { result as usize + cursor }; From e75beaa8d69a3ae79ee88f5de04cd4ec0db8b622 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 15 Oct 2018 10:46:24 -0400 Subject: [PATCH 2/3] Make android logging thread only process buffer slice that contains real data. --- ports/libsimpleservo/src/jniapi.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/src/jniapi.rs index efb67ff741e..00487b417eb 100644 --- a/ports/libsimpleservo/src/jniapi.rs +++ b/ports/libsimpleservo/src/jniapi.rs @@ -491,6 +491,9 @@ fn redirect_stdout_to_logcat() { result as usize + cursor }; + // Only modify the portion of the buffer that contains real data. + let buf = &mut buf[0..end]; + if let Some(last_newline_pos) = buf.iter().rposition(|&c| c == b'\n' as c_char) { buf[last_newline_pos] = b'\0' as c_char; unsafe { From 1332026bd4eac79ed975d6b7b43d5a7dd1ac6338 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 15 Oct 2018 10:47:12 -0400 Subject: [PATCH 3/3] Flush the android logging buffer when most recent read fills it up. --- ports/libsimpleservo/src/jniapi.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/libsimpleservo/src/jniapi.rs b/ports/libsimpleservo/src/jniapi.rs index 00487b417eb..ad027ec946a 100644 --- a/ports/libsimpleservo/src/jniapi.rs +++ b/ports/libsimpleservo/src/jniapi.rs @@ -509,7 +509,7 @@ fn redirect_stdout_to_logcat() { } else { cursor = 0; } - } else if cursor == BUF_AVAILABLE { + } else if end == BUF_AVAILABLE { // No newline found but the buffer is full, flush it anyway. // `buf.as_ptr()` is null-terminated by BUF_LENGTH being 1 less than BUF_AVAILABLE. unsafe {