From 9104bab21851801a347c352c6ceb56171c17e2ca Mon Sep 17 00:00:00 2001 From: Jorrit Jongma Date: Wed, 5 Feb 2014 14:26:15 +0100 Subject: [PATCH] Change version checking behavior to prevent stall In some cases, calling "su -[v|V]" could result in a broken pipe, preventing the containing shell from receiving the exit command and terminating, resulting in an infinite wait. Instead of calling su from sh now, we directly call su, and work-around the entire problem. --- .../src/eu/chainfire/libsuperuser/Shell.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java b/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java index 63fa5de..5c9caad 100644 --- a/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java +++ b/libsuperuser/src/eu/chainfire/libsuperuser/Shell.java @@ -113,10 +113,10 @@ public static List run(String shell, String[] commands, String[] environ } int i = 0; environment = new String[newEnvironment.size()]; - for (Map.Entry entry : newEnvironment.entrySet()) { - environment[i] = entry.getKey() + "=" + entry.getValue(); - i++; - } + for (Map.Entry entry : newEnvironment.entrySet()) { + environment[i] = entry.getKey() + "=" + entry.getValue(); + i++; + } } // setup our process, retrieve STDIN stream, and STDOUT/STDERR gobblers @@ -145,7 +145,7 @@ public static List run(String shell, String[] commands, String[] environ // lets be safe and do this on Android as well try { STDIN.close(); - } catch (IOException e) { + } catch (IOException e) { } STDOUT.join(); STDERR.join(); @@ -296,14 +296,12 @@ public static boolean available() { * @return String containing the su version or null */ public static String version(boolean internal) { - // we add an additional exit call, because the command - // line options are not available in all su versions, - // thus potentially launching a shell instead - - List ret = Shell.run("sh", new String[] { - internal ? "su -V" : "su -v", - "exit" - }, null, false); + List ret = Shell.run( + internal ? "su -V" : "su -v", + new String[] { }, + null, + false + ); if (ret == null) return null; for (String line : ret) {