From 5768648cde99e99e957dacee52babf9050ee992f Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 22 Dec 2020 18:16:06 -0800 Subject: [PATCH] Make dhclient not block (#187) --- .../org/photonvision/common/networking/NetworkManager.java | 2 +- .../main/java/org/photonvision/common/util/ShellExec.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/photon-server/src/main/java/org/photonvision/common/networking/NetworkManager.java b/photon-server/src/main/java/org/photonvision/common/networking/NetworkManager.java index d00daaf74..5258ec4b4 100644 --- a/photon-server/src/main/java/org/photonvision/common/networking/NetworkManager.java +++ b/photon-server/src/main/java/org/photonvision/common/networking/NetworkManager.java @@ -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!"); } diff --git a/photon-server/src/main/java/org/photonvision/common/util/ShellExec.java b/photon-server/src/main/java/org/photonvision/common/util/ShellExec.java index 700aacfcb..b59e51996 100644 --- a/photon-server/src/main/java/org/photonvision/common/util/ShellExec.java +++ b/photon-server/src/main/java/org/photonvision/common/util/ShellExec.java @@ -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