1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-12-23 11:21:29 +00:00

Don't use Process#exit() to avoid exit code 9.

Process#exit() seems to cause syncthing to return exit code 9 all
the time. Using SIGINT instead always gives a clean exit (at least
on my Android 6 device).
This commit is contained in:
Felix Ableitner 2016-03-11 23:00:23 +01:00
parent 963704778a
commit 91f9231501

View file

@ -217,21 +217,9 @@ public class SyncthingRunnable implements Runnable {
/**
* Look for running libsyncthing.so processes and kill them.
* Try a SIGTERM once, then try again (twice) with SIGKILL.
* Try a SIGINT first, then try again with SIGKILL.
*/
public void killSyncthing() {
final Process p = mSyncthing.get();
if (p != null) {
mSyncthing.set(null);
p.destroy();
try {
p.waitFor();
} catch (InterruptedException e) {
Log.w(TAG_KILL, "Failed to kill Syncthing's process", e);
}
}
// Ensure kill
for (int i = 0; i < 2; i++) {
Process ps = null;
DataOutputStream psOut = null;
@ -269,18 +257,18 @@ public class SyncthingRunnable implements Runnable {
*
* @param force Whether to use a SIGKILL.
*/
private static void killProcessId(String id, boolean force) {
private void killProcessId(String id, boolean force) {
Process kill = null;
DataOutputStream killOut = null;
try {
kill = Runtime.getRuntime().exec("sh");
kill = Runtime.getRuntime().exec((useRoot()) ? "su" : "sh");
killOut = new DataOutputStream(kill.getOutputStream());
if (!force) {
killOut.writeBytes("kill " + id + "\n");
killOut.writeBytes("kill -SIGINT " + id + "\n");
killOut.writeBytes("sleep 1\n");
} else {
killOut.writeBytes("sleep 3\n");
killOut.writeBytes("kill -9 " + id + "\n");
killOut.writeBytes("kill -SIGKILL " + id + "\n");
}
killOut.writeBytes("exit\n");
killOut.flush();
@ -322,8 +310,6 @@ public class SyncthingRunnable implements Runnable {
mErrorLog += line + "\n";
}
} catch (IOException e) {
// NOTE: This is sometimes called on shutdown, as
// Process.destroy() closes the stream.
Log.w(TAG, "Failed to read Syncthing's command line output", e);
}
}