mirror of
https://github.com/syncthing/syncthing-android.git
synced 2024-12-23 19:31:30 +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:
parent
963704778a
commit
91f9231501
1 changed files with 5 additions and 19 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue