Skip to content

Commit

Permalink
[AppsLauncher] Check if sudo is (not) available using the termination…
Browse files Browse the repository at this point in the history
… code 127.
  • Loading branch information
CesarCoelho committed Dec 6, 2021
1 parent 49c0bc5 commit e3abc2e
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import esa.mo.helpertools.helpers.HelperMisc;
import esa.mo.helpertools.misc.Const;
import esa.mo.sm.impl.util.OSValidator;
import esa.mo.sm.impl.util.ShellCommander;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand Down Expand Up @@ -126,9 +125,23 @@ public AppsLauncherManager(COMServicesProvider comServices)
}

if(osValidator.isUnix()){
ShellCommander shell = new ShellCommander();
String out = shell.runCommandAndGetOutputMessageAndError("sudo --help");
sudoAvailable = !out.contains("command not found");
try {
String[] params = new String[]{"sh", "-c", "sudo --help"};
Process p = Runtime.getRuntime().exec(params, null, null);
try {
boolean terminated = p.waitFor(1, TimeUnit.SECONDS);
if(terminated){
sudoAvailable = (p.exitValue() != 127);
}
} catch (InterruptedException ex) {
Logger.getLogger(AppsLauncherManager.class.getName()).log(
Level.SEVERE, "The process did no finish yet...", ex);
sudoAvailable = false;
}
} catch (IOException ex) {
Logger.getLogger(AppsLauncherManager.class.getName()).log(
Level.SEVERE, "The process could not be executed!", ex);
}
}
}

Expand Down

0 comments on commit e3abc2e

Please sign in to comment.