Make dhclient not block (#187)

This commit is contained in:
Matt
2020-12-22 18:16:06 -08:00
committed by GitHub
parent 6856427f86
commit 5768648cde
2 changed files with 6 additions and 3 deletions

View File

@@ -100,7 +100,7 @@ public class NetworkManager {
if (!config.staticIp.equals("")) {
shell.executeBashCommand("ip addr del " + config.staticIp + "/8 dev eth0");
}
shell.executeBashCommand("dhclient eth0");
shell.executeBashCommand("dhclient eth0", false);
} catch (Exception e) {
logger.error("Exception while setting DHCP!");
}

View File

@@ -39,6 +39,10 @@ public class ShellExec {
this.readError = readError;
}
public int executeBashCommand(String command) throws IOException {
return executeBashCommand(command, true);
}
/**
* Execute a bash command. We can handle complex bash commands including multiple executions (; |
* and ||), quotes, expansions ($), escapes (\), e.g.: "cd /abc/def; mv ghi 'older ghi '$(whoami)"
@@ -46,10 +50,9 @@ public class ShellExec {
* @param command Bash command to execute
* @return true if bash got started, but your command may have failed.
*/
public int executeBashCommand(String command) throws IOException {
public int executeBashCommand(String command, boolean wait) throws IOException {
logger.debug("Executing \"" + command + "\"");
boolean wait = true;
boolean success = false;
Runtime r = Runtime.getRuntime();
// Use bash -c so we can handle things like multi commands separated by ; and