diff options
author | Samuel Holland <samuel@sholland.org> | 2018-01-08 04:34:28 -0600 |
---|---|---|
committer | Samuel Holland <samuel@sholland.org> | 2018-01-08 04:34:28 -0600 |
commit | ae2068dc166332f258db53e18dd75165ebd64851 (patch) | |
tree | eea881eb4ab512c37cc4b27926850e6bddc15d57 /app/src | |
parent | c4e91f8040968ad51ffccbd2ef9f17d4d322f579 (diff) |
Port over remaining error handling
This doesn't really belong here, but there's no sense in throwing it
away--even here, it's a minor optimization.
Signed-off-by: Samuel Holland <samuel@sholland.org>
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/com/wireguard/android/util/RootShell.java | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/src/main/java/com/wireguard/android/util/RootShell.java b/app/src/main/java/com/wireguard/android/util/RootShell.java index 35f4735b..6c90118e 100644 --- a/app/src/main/java/com/wireguard/android/util/RootShell.java +++ b/app/src/main/java/com/wireguard/android/util/RootShell.java @@ -58,6 +58,16 @@ public class RootShell { preamble = builder.toString(); } + private static boolean isExecutable(final String name) { + final String path = System.getenv("PATH"); + if (path == null) + return false; + for (final String dir : path.split(":")) + if (new File(dir, name).canExecute()) + return true; + return false; + } + /** * Run a command in a root shell. * @@ -68,6 +78,8 @@ public class RootShell { */ public int run(final List<String> output, final String command) { int exitValue = -1; + if (!isExecutable("su")) + return OsConstants.EACCES; try { final ProcessBuilder builder = new ProcessBuilder(); builder.environment().put("LANG", "C"); |