Skip to content

Commit

Permalink
Move abortAnalysis() to GoblintServer
Browse files Browse the repository at this point in the history
  • Loading branch information
karoliineh committed Jan 12, 2024
1 parent 2ad4f9a commit f767b0f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
16 changes: 1 addition & 15 deletions src/main/java/analysis/GoblintAnalysis.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.zeroturnaround.exec.InvalidExitValueException;
import org.zeroturnaround.exec.ProcessExecutor;
import org.zeroturnaround.exec.ProcessResult;
import org.zeroturnaround.process.UnixProcess;
import util.FileWatcher;

import java.io.File;
Expand Down Expand Up @@ -51,8 +50,6 @@

public class GoblintAnalysis implements ServerAnalysis {

private final static int SIGINT = 2;

private final MagpieServer magpieServer;
private final GoblintServer goblintServer;
private final GoblintService goblintService;
Expand Down Expand Up @@ -109,7 +106,7 @@ public void analyze(Collection<? extends Module> files, AnalysisConsumer consume
if (lastAnalysisTask != null && !lastAnalysisTask.isDone()) {
lastAnalysisTask.cancel(true);
try {
abortAnalysis();
goblintServer.abortAnalysis();
log.info("--------------- This analysis has been aborted -------------");
} catch (IOException e) {
log.error("Aborting analysis failed.");
Expand Down Expand Up @@ -144,17 +141,6 @@ public void analyze(Collection<? extends Module> files, AnalysisConsumer consume
}


/**
* Aborts the previous running analysis by sending a SIGINT signal to Goblint.
*/
private void abortAnalysis() throws IOException {
Process goblintProcess = goblintServer.getGoblintRunProcess().getProcess();
int pid = Math.toIntExact(goblintProcess.pid());
UnixProcess unixProcess = new UnixProcess(pid);
unixProcess.kill(SIGINT);
}


/**
* Reloads Goblint config if it has been changed or is currently invalid.
*/
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/goblintserver/GoblintServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.zeroturnaround.exec.ProcessExecutor;
import org.zeroturnaround.exec.StartedProcess;
import org.zeroturnaround.exec.listener.ProcessListener;
import org.zeroturnaround.process.UnixProcess;

import java.io.ByteArrayOutputStream;
import java.io.File;
Expand All @@ -35,7 +36,7 @@
public class GoblintServer {

private static final String GOBLINT_SOCKET = "goblint.sock";

private static final int SIGINT = 2;
private final MagpieServer magpieServer;
private final GobPieConfiguration configuration;
private final String[] goblintRunCommand;
Expand All @@ -51,8 +52,14 @@ public GoblintServer(MagpieServer magpieServer, GobPieConfiguration configuratio
this.goblintRunCommand = constructGoblintRunCommand();
}

public StartedProcess getGoblintRunProcess() {
return goblintRunProcess;
/**
* Aborts the previous running analysis by sending a SIGINT signal to Goblint.
*/
public void abortAnalysis() throws IOException {
Process goblintProcess = goblintRunProcess.getProcess();
int pid = Math.toIntExact(goblintProcess.pid());
UnixProcess unixProcess = new UnixProcess(pid);
unixProcess.kill(SIGINT);
}

public String getGoblintSocket() {
Expand Down

0 comments on commit f767b0f

Please sign in to comment.