Handle exit code 137 caused by SIGKILL.

Also don't restart Syncthing twice (via loop and via intent).
This commit is contained in:
Felix Ableitner 2016-04-04 22:43:50 +02:00
parent 88abd80c66
commit 7f090e3653
1 changed files with 38 additions and 30 deletions

View File

@ -108,8 +108,6 @@ public class SyncthingRunnable implements Runnable {
try { try {
if (wakeLock != null) if (wakeLock != null)
wakeLock.acquire(); wakeLock.acquire();
// Loop to handle Syncthing restarts (these always have an error code of 3).
do {
ProcessBuilder pb = (useRoot()) ProcessBuilder pb = (useRoot())
? new ProcessBuilder("su", "-c", TextUtils.join(" ", mCommand)) ? new ProcessBuilder("su", "-c", TextUtils.join(" ", mCommand))
: new ProcessBuilder(mCommand); : new ProcessBuilder(mCommand);
@ -136,18 +134,28 @@ public class SyncthingRunnable implements Runnable {
lInfo.join(); lInfo.join();
lWarn.join(); lWarn.join();
switch (ret) {
case 0:
case 2:
case 4:
// Valid exit codes, ignored.
break;
case 3:
// Restart if that was requested via Rest API call. // Restart if that was requested via Rest API call.
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));
} break;
case 137:
// Ignore SIGKILL that we use to stop Syncthing.
break;
case 1:
// fallthrough
default:
// Force crash if Syncthing exits with an error. // Force crash if Syncthing exits with an error.
else if (ret == 1 || ret > 4) {
throw new RuntimeException("Syncthing binary crashed with error code " + throw new RuntimeException("Syncthing binary crashed with error code " +
Integer.toString(ret) + ", output:\n" + mErrorLog); Integer.toString(ret) + ", output:\n" + mErrorLog);
} }
} 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);
} finally { } finally {