From 048b713a355431f71dd1c35d091950ee16451cba Mon Sep 17 00:00:00 2001 From: Mathieu Baudier Date: Sat, 3 Jan 2015 11:43:45 +0000 Subject: [PATCH] Can monitor and kill systemn call git-svn-id: https://svn.argeo.org/slc/trunk@7618 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../slc/core/execution/tasks/SystemCall.java | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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; -- 2.39.2