]> git.argeo.org Git - gpl/argeo-slc.git/blobdiff - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/tasks/SystemCall.java
Can monitor and kill systemn call
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / tasks / SystemCall.java
index 6d916462c7ad44817ae3a45e620b4751140ac8cf..d4093ad58ee05b021f3a06b28dee5fd4fb5f45d9 100644 (file)
@@ -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;