|
|
@@ -10,7 +10,6 @@ import os |
|
|
|
import signal |
|
|
|
import time |
|
|
|
import uuid |
|
|
|
import subprocess |
|
|
|
import psutil |
|
|
|
|
|
|
|
class LogReceiver(object): |
|
|
@@ -163,16 +162,26 @@ class ProcessManager(object): |
|
|
|
def __getitem__(self, key): |
|
|
|
return self.processes[key] |
|
|
|
|
|
|
|
def run_python(self, name, function, parameters): |
|
|
|
def run_function(self, name, function, parameters): |
|
|
|
"""Run a Python function that already exists""" |
|
|
|
new = Process(name, function, parameters) |
|
|
|
self.processes[new.pid] = new |
|
|
|
return new.pid |
|
|
|
|
|
|
|
def run_command(self, name, args): |
|
|
|
"""Execute a command line program""" |
|
|
|
def spwan_user_command(args): # pragma: no cover (runs in subprocess) |
|
|
|
p = subprocess.Popen(args, close_fds = True, cwd = "/tmp") |
|
|
|
sys.exit(p.wait()) |
|
|
|
return self.run_python(name, spwan_user_command, args) |
|
|
|
try: |
|
|
|
maxfd = os.sysconf("SC_OPEN_MAX") |
|
|
|
except Exception: |
|
|
|
maxfd = 256 |
|
|
|
os.closerange(3, maxfd) |
|
|
|
try: |
|
|
|
os.chdir("/tmp") |
|
|
|
except OSError: |
|
|
|
pass |
|
|
|
os.execvp(args[0], args) |
|
|
|
return self.run_function(name, spwan_user_command, args) |
|
|
|
|
|
|
|
def terminate(self, pid): |
|
|
|
return self.processes[pid].terminate() |
|
|
|