From ff50d42c3e0918f8e465d7264bedc9ce626a88ea Mon Sep 17 00:00:00 2001 From: pierantoniomerlino Date: Thu, 21 Nov 2024 14:24:11 +0100 Subject: [PATCH] Fixed sonar complains Signed-off-by: pierantoniomerlino --- .../eclipse/kura/linux/net/util/LinuxNetworkUtil.java | 10 +++++++--- .../kura/linux/net/dhcp/DhcpServerManagerTest.java | 4 ---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/kura/org.eclipse.kura.linux.net/src/main/java/org/eclipse/kura/linux/net/util/LinuxNetworkUtil.java b/kura/org.eclipse.kura.linux.net/src/main/java/org/eclipse/kura/linux/net/util/LinuxNetworkUtil.java index 75ebd99cd9..a55bc44d3b 100644 --- a/kura/org.eclipse.kura.linux.net/src/main/java/org/eclipse/kura/linux/net/util/LinuxNetworkUtil.java +++ b/kura/org.eclipse.kura.linux.net/src/main/java/org/eclipse/kura/linux/net/util/LinuxNetworkUtil.java @@ -293,20 +293,24 @@ public static boolean toolExists(String tool) { * @return true if the unit is installed */ public static boolean systemdSystemUnitExists(String unitName) { - PROCESS_BUILDER.command("sh", "-c", "systemctl status " + unitName); + PROCESS_BUILDER.command("systemctl", "status", unitName); Process process; try { process = PROCESS_BUILDER.start(); - StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), logger::debug); + StreamGobbler streamGobbler = new StreamGobbler(process.getInputStream(), logger::info); ExecutorService executor = Executors.newSingleThreadExecutor(); Future future = executor.submit(streamGobbler); int exitCode = process.waitFor(); future.get(10, TimeUnit.SECONDS); return exitCode < 4; - } catch (IOException | ExecutionException | TimeoutException | InterruptedException e) { + } catch (IOException | ExecutionException | TimeoutException e) { logger.error(String.format("Cannot check %s unit existence", unitName), e); return false; + } catch (InterruptedException e1) { + Thread.currentThread().interrupt(); + logger.error(String.format("Cannot check %s unit existence", unitName), e1); + return false; } } diff --git a/kura/test/org.eclipse.kura.linux.net.test/src/test/java/org/eclipse/kura/linux/net/dhcp/DhcpServerManagerTest.java b/kura/test/org.eclipse.kura.linux.net.test/src/test/java/org/eclipse/kura/linux/net/dhcp/DhcpServerManagerTest.java index 48d6df7ed9..2ab9d3e69a 100644 --- a/kura/test/org.eclipse.kura.linux.net.test/src/test/java/org/eclipse/kura/linux/net/dhcp/DhcpServerManagerTest.java +++ b/kura/test/org.eclipse.kura.linux.net.test/src/test/java/org/eclipse/kura/linux/net/dhcp/DhcpServerManagerTest.java @@ -446,8 +446,4 @@ private void thenReturnedLeaseReaderIs(Class dhcpServerLeaseReader) { private void thenToolIs(DhcpServerTool expectedTool) { assertEquals(expectedTool, this.tool); } - - private void thenConverterIsNotPresent() { - assertFalse(this.returnedConfigConverter.isPresent()); - } }