X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Ftasks%2FSystemCall.java;fp=runtime%2Forg.argeo.slc.core%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fcore%2Fexecution%2Ftasks%2FSystemCall.java;h=d4093ad58ee05b021f3a06b28dee5fd4fb5f45d9;hb=048b713a355431f71dd1c35d091950ee16451cba;hp=6d916462c7ad44817ae3a45e620b4751140ac8cf;hpb=b6c77a37546f422c48809086292a3d58c59b913a;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java index 6d916462c..d4093ad58 100644 --- a/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java +++ b/runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java @@ -120,6 +120,10 @@ public class SystemCall implements Runnable { /** Chroot to the this path (must not be empty) */ private String chroot = null; + // Current + /** Current watchdog, null if process is completed */ + ExecuteWatchdog currentWatchdog = null; + /** Empty constructor */ public SystemCall() { @@ -203,7 +207,7 @@ public class SystemCall implements Runnable { executorToUse = executor; else executorToUse = new DefaultExecutor(); - executorToUse.setWatchdog(new ExecuteWatchdog(watchdogTimeout)); + executorToUse.setWatchdog(createWatchdog()); if (redirectStreams) { // Redirect standard streams @@ -474,6 +478,7 @@ public class SystemCall implements Runnable { testResult.addResultPart(new SimpleResultPart( TestStatus.PASSED, msg)); } + releaseWatchdog(); } public void onProcessFailed(ExecuteException e) { @@ -489,6 +494,7 @@ public class SystemCall implements Runnable { else log.error(msg, e); } + releaseWatchdog(); } }; } @@ -612,6 +618,27 @@ public class SystemCall implements Runnable { return this; } + // CONTROL + public synchronized Boolean isRunning() { + return currentWatchdog != null; + } + + private synchronized ExecuteWatchdog createWatchdog() { + if (currentWatchdog != null) + throw new SlcException("A process is already being monitored"); + currentWatchdog = new ExecuteWatchdog(watchdogTimeout); + return currentWatchdog; + } + + private synchronized void releaseWatchdog() { + currentWatchdog = null; + } + + public synchronized void kill() { + if (currentWatchdog != null) + currentWatchdog.destroyProcess(); + } + /** */ public void setCmd(String command) { this.cmd = command;