From 3bd1c753a68aea079c0be08152ecd7c8b55273f7 Mon Sep 17 00:00:00 2001 From: Catfriend1 Date: Tue, 7 Aug 2018 19:22:15 +0200 Subject: [PATCH] Root only - Temporarily increase fs.inotify.max_user_watches to 128K (fixes #1208) (#1209) Forum discussion: https://forum.syncthing.net/t/android-failed-to-set-up-inotify-handler-please-increase-inotify-limits/11924/15 --- .../service/SyncthingRunnable.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java index 9d31b7c8..bb09db6c 100644 --- a/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java +++ b/app/src/main/java/com/nutomic/syncthingandroid/service/SyncthingRunnable.java @@ -130,6 +130,7 @@ public class SyncthingRunnable implements Runnable { try { if (wakeLock != null) wakeLock.acquire(); + increaseInotifyWatches(); HashMap targetEnv = buildEnvironment(); process = setupAndLaunch(targetEnv); @@ -260,6 +261,20 @@ public class SyncthingRunnable implements Runnable { return syncthingPIDs; } + /** + * Root-only: Temporarily increase "fs.inotify.max_user_watches" + * as Android has a default limit of 8192 watches. + * Manually run "sysctl fs.inotify" in a root shell terminal to check current limit. + */ + private void increaseInotifyWatches() { + if (!mUseRoot || !Shell.SU.available()) { + Log.i(TAG, "increaseInotifyWatches: Root is not available. Cannot increase inotify limit."); + return; + } + int exitCode = Util.runShellCommand("sysctl -n -w fs.inotify.max_user_watches=131072\n", true); + Log.i(TAG, "increaseInotifyWatches: sysctl returned " + Integer.toString(exitCode)); + } + /** * Look for a running libsyncthing.so process and nice its IO. */