Skip to content

Commit

Permalink
Fixed sonar complains
Browse files Browse the repository at this point in the history
Signed-off-by: pierantoniomerlino <[email protected]>
  • Loading branch information
pierantoniomerlino committed Nov 21, 2024
1 parent d36776d commit ff50d42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit ff50d42

Please sign in to comment.