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>
This commit is contained in:
parent
c4e91f8040
commit
ae2068dc16
@ -58,6 +58,16 @@ public class RootShell {
|
|||||||
preamble = builder.toString();
|
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.
|
* Run a command in a root shell.
|
||||||
*
|
*
|
||||||
@ -68,6 +78,8 @@ public class RootShell {
|
|||||||
*/
|
*/
|
||||||
public int run(final List<String> output, final String command) {
|
public int run(final List<String> output, final String command) {
|
||||||
int exitValue = -1;
|
int exitValue = -1;
|
||||||
|
if (!isExecutable("su"))
|
||||||
|
return OsConstants.EACCES;
|
||||||
try {
|
try {
|
||||||
final ProcessBuilder builder = new ProcessBuilder();
|
final ProcessBuilder builder = new ProcessBuilder();
|
||||||
builder.environment().put("LANG", "C");
|
builder.environment().put("LANG", "C");
|
||||||
|
Loading…
Reference in New Issue
Block a user