From: Mathieu Baudier Date: Sat, 3 Jan 2015 11:43:45 +0000 (+0000) Subject: Can monitor and kill systemn call X-Git-Tag: argeo-slc-2.1.7~145 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=048b713a355431f71dd1c35d091950ee16451cba;p=gpl%2Fargeo-slc.git Can monitor and kill systemn call git-svn-id: https://svn.argeo.org/slc/trunk@7618 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- 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;