Skip to content

Commit

Permalink
Change version checking behavior to prevent stall
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Chainfire committed Feb 5, 2014
1 parent 3f8be11 commit 9104bab
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions libsuperuser/src/eu/chainfire/libsuperuser/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ public static List<String> run(String shell, String[] commands, String[] environ
}
int i = 0;
environment = new String[newEnvironment.size()];
for (Map.Entry<String, String> entry : newEnvironment.entrySet()) {
environment[i] = entry.getKey() + "=" + entry.getValue();
i++;
}
for (Map.Entry<String, String> entry : newEnvironment.entrySet()) {
environment[i] = entry.getKey() + "=" + entry.getValue();
i++;
}
}

// setup our process, retrieve STDIN stream, and STDOUT/STDERR gobblers
Expand Down Expand Up @@ -145,7 +145,7 @@ public static List<String> 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();
Expand Down Expand Up @@ -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<String> ret = Shell.run("sh", new String[] {
internal ? "su -V" : "su -v",
"exit"
}, null, false);
List<String> ret = Shell.run(
internal ? "su -V" : "su -v",
new String[] { },
null,
false
);
if (ret == null) return null;

for (String line : ret) {
Expand Down

0 comments on commit 9104bab

Please sign in to comment.