Skip to content

Commit e3abc2e

Browse files
committed
[AppsLauncher] Check if sudo is (not) available using the termination code 127.
1 parent 49c0bc5 commit e3abc2e

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

core/mo-services-impl/nmf-software-management-impl/src/main/java/esa/mo/sm/impl/provider/AppsLauncherManager.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import esa.mo.helpertools.helpers.HelperMisc;
3333
import esa.mo.helpertools.misc.Const;
3434
import esa.mo.sm.impl.util.OSValidator;
35-
import esa.mo.sm.impl.util.ShellCommander;
3635
import java.io.File;
3736
import java.io.FileInputStream;
3837
import java.io.IOException;
@@ -126,9 +125,23 @@ public AppsLauncherManager(COMServicesProvider comServices)
126125
}
127126

128127
if(osValidator.isUnix()){
129-
ShellCommander shell = new ShellCommander();
130-
String out = shell.runCommandAndGetOutputMessageAndError("sudo --help");
131-
sudoAvailable = !out.contains("command not found");
128+
try {
129+
String[] params = new String[]{"sh", "-c", "sudo --help"};
130+
Process p = Runtime.getRuntime().exec(params, null, null);
131+
try {
132+
boolean terminated = p.waitFor(1, TimeUnit.SECONDS);
133+
if(terminated){
134+
sudoAvailable = (p.exitValue() != 127);
135+
}
136+
} catch (InterruptedException ex) {
137+
Logger.getLogger(AppsLauncherManager.class.getName()).log(
138+
Level.SEVERE, "The process did no finish yet...", ex);
139+
sudoAvailable = false;
140+
}
141+
} catch (IOException ex) {
142+
Logger.getLogger(AppsLauncherManager.class.getName()).log(
143+
Level.SEVERE, "The process could not be executed!", ex);
144+
}
132145
}
133146
}
134147

0 commit comments

Comments
 (0)