mirror of
https://github.com/syncthing/syncthing-android.git
synced 2025-01-11 04:25:53 +00:00
Force crash if Syncthing exits with an error.
This should give us some useful info for all our native crashes.
This commit is contained in:
parent
602383f643
commit
115a9b5727
1 changed files with 14 additions and 4 deletions
|
@ -21,6 +21,8 @@ import eu.chainfire.libsuperuser.Shell;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the syncthing binary from command line, and prints its output to logcat.
|
* Runs the syncthing binary from command line, and prints its output to logcat.
|
||||||
|
*
|
||||||
|
* @see <a href="http://docs.syncthing.net/users/syncthing.html">Command Line Docs</a>
|
||||||
*/
|
*/
|
||||||
public class SyncthingRunnable implements Runnable {
|
public class SyncthingRunnable implements Runnable {
|
||||||
|
|
||||||
|
@ -42,6 +44,8 @@ public class SyncthingRunnable implements Runnable {
|
||||||
|
|
||||||
private String[] mCommand;
|
private String[] mCommand;
|
||||||
|
|
||||||
|
private String mErrorLog;
|
||||||
|
|
||||||
public enum Command {
|
public enum Command {
|
||||||
generate, // Generate keys, a config file and immediately exit.
|
generate, // Generate keys, a config file and immediately exit.
|
||||||
main, // Run the main Syncthing application.
|
main, // Run the main Syncthing application.
|
||||||
|
@ -121,6 +125,7 @@ public class SyncthingRunnable implements Runnable {
|
||||||
process = pb.start();
|
process = pb.start();
|
||||||
mSyncthing.set(process);
|
mSyncthing.set(process);
|
||||||
|
|
||||||
|
mErrorLog = "";
|
||||||
Thread lInfo = log(process.getInputStream(), Log.INFO);
|
Thread lInfo = log(process.getInputStream(), Log.INFO);
|
||||||
Thread lWarn = log(process.getErrorStream(), Log.WARN);
|
Thread lWarn = log(process.getErrorStream(), Log.WARN);
|
||||||
|
|
||||||
|
@ -131,11 +136,17 @@ public class SyncthingRunnable implements Runnable {
|
||||||
lInfo.join();
|
lInfo.join();
|
||||||
lWarn.join();
|
lWarn.join();
|
||||||
|
|
||||||
|
// Restart if that was requested.
|
||||||
if (ret == 3) {
|
if (ret == 3) {
|
||||||
Log.i(TAG, "Restarting syncthing");
|
Log.i(TAG, "Restarting syncthing");
|
||||||
mContext.startService(new Intent(mContext, SyncthingService.class)
|
mContext.startService(new Intent(mContext, SyncthingService.class)
|
||||||
.setAction(SyncthingService.ACTION_RESTART));
|
.setAction(SyncthingService.ACTION_RESTART));
|
||||||
}
|
}
|
||||||
|
// Force crash if Syncthing exits with an error.
|
||||||
|
else if (ret == 1 || ret > 4) {
|
||||||
|
throw new RuntimeException("Syncthing binary crashed with error code " +
|
||||||
|
Integer.toString(ret) + ", output:\n" + mErrorLog);
|
||||||
|
}
|
||||||
} while (ret == 3);
|
} while (ret == 3);
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
|
Log.e(TAG, "Failed to execute syncthing binary or read output", e);
|
||||||
|
@ -144,10 +155,6 @@ public class SyncthingRunnable implements Runnable {
|
||||||
wakeLock.release();
|
wakeLock.release();
|
||||||
if (process != null)
|
if (process != null)
|
||||||
process.destroy();
|
process.destroy();
|
||||||
if (ret != 0) {
|
|
||||||
Log.e(TAG_NATIVE, "Syncthing binary crashed with error code " +
|
|
||||||
Integer.toString(ret));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,6 +316,9 @@ public class SyncthingRunnable implements Runnable {
|
||||||
String line;
|
String line;
|
||||||
while ((line = br.readLine()) != null) {
|
while ((line = br.readLine()) != null) {
|
||||||
Log.println(priority, TAG_NATIVE, line);
|
Log.println(priority, TAG_NATIVE, line);
|
||||||
|
|
||||||
|
if (priority == Log.WARN)
|
||||||
|
mErrorLog += line + "\n";
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// NOTE: This is sometimes called on shutdown, as
|
// NOTE: This is sometimes called on shutdown, as
|
||||||
|
|
Loading…
Reference in a new issue