diff options
author | Seth Vidal <skvidal@fedoraproject.org> | 2007-09-25 14:38:51 -0400 |
---|---|---|
committer | Seth Vidal <skvidal@fedoraproject.org> | 2007-09-25 14:38:51 -0400 |
commit | a785dfc7cb5e8bdf5859237ce0c15bf52b21e42a (patch) | |
tree | 554ee1179c0896ef59f08027b083de8fe9c1c385 | |
parent | 3675cf7df32d59000a45c2b2932ec8a19a0d1c9d (diff) | |
parent | 6d5746d617385978fb316ac90cc05eaa0f39b8b9 (diff) | |
download | third_party-func-a785dfc7cb5e8bdf5859237ce0c15bf52b21e42a.tar.gz third_party-func-a785dfc7cb5e8bdf5859237ce0c15bf52b21e42a.tar.xz third_party-func-a785dfc7cb5e8bdf5859237ce0c15bf52b21e42a.zip |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
* 'master' of ssh://git.fedoraproject.org/git/hosted/func:
catch some potentially bad args to the process.kill method
fix up logging a bit. I was sending the audit logs and the svc logs
Be a bit more paranoid about sub processes. Before
-rwxr-xr-x | minion/logger.py | 13 | ||||
-rwxr-xr-x | modules/process.py | 20 |
2 files changed, 28 insertions, 5 deletions
diff --git a/minion/logger.py b/minion/logger.py index 1e60dc0..7747824 100755 --- a/minion/logger.py +++ b/minion/logger.py @@ -55,7 +55,8 @@ class Logger(Singleton): self._no_handlers = False -class AuditLogger(Logger): +class AuditLogger(Singleton): + _no_handlers = True def __init__(self, logfilepath = "/var/log/func/audit.log"): self.loglevel = logging.INFO self._setup_logging() @@ -67,6 +68,16 @@ class AuditLogger(Logger): self.logger.info("%s called with %s" % (method, params)) + def _setup_logging(self): + self.logger = logging.getLogger("audit") + + def _setup_handlers(self, logfilepath="/var/log/func/audit.log"): + handler = logging.FileHandler(logfilepath, "a") + self.logger.setLevel(self.loglevel) + formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") + handler.setFormatter(formatter) + self.logger.addHandler(handler) + self._no_handlers = False diff --git a/modules/process.py b/modules/process.py index 1accbf5..78e5aea 100755 --- a/modules/process.py +++ b/modules/process.py @@ -16,6 +16,7 @@ # other modules import sub_process +import codes # our modules from modules import func_module @@ -40,7 +41,9 @@ class ProcessModule(func_module.FuncModule): flags.replace(";","") # prevent stupidity - cmd = sub_process.Popen("ps %s" % flags,stdout=sub_process.PIPE,shell=True) + + #FIXME: we need to swallow stdout/stderr as well, right now it spews to the console + cmd = sub_process.Popen(["/bin/ps", flags] ,executable="/bin/ps", stdout=sub_process.PIPE,shell=False) data = cmd.communicate()[0] results = [] @@ -51,13 +54,22 @@ class ProcessModule(func_module.FuncModule): return results - def kill(self,pid,level=""): - rc = sub_process.call("/bin/kill %s %s" % (pid, level), shell=True) + + def kill(self,pid,signal="TERM"): + if pid == "0": + raise codes.FuncException("Killing pid group 0 not permitted") + if signal == "": + # this is default /bin/kill behaviour, it claims, but enfore it anyway + signal = "-TERM" + if signal[0] != "-": + signal = "-%s" % signal + rc = sub_process.call(["/bin/kill",signal, pid], executable="/bin/kill", shell=False) + print rc return rc def pkill(self,name,level=""): # example killall("thunderbird","-9") - rc = sub_process.call("/usr/bin/pkill %s %s" % (name, level), shell=True) + rc = sub_process.call(["/usr/bin/pkill", name, level], executable="/usr/bin/pkill", shell=False) return rc methods = ProcessModule() |