From bb6c14bfea961ac2cd5fc29c003ca2a7aaa59379 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Thu, 21 Sep 2006 21:20:29 +0000 Subject: [PATCH] - Use subprocess.call instead of os.system git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/trunk@378 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- server/action.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/server/action.py b/server/action.py index e648c355..736163d9 100644 --- a/server/action.py +++ b/server/action.py @@ -24,7 +24,8 @@ __date__ = "$Date$" __copyright__ = "Copyright (c) 2004 Cyril Jaquier" __license__ = "GPL" -import time, logging, os +import time, logging +from subprocess import call # Gets the instance of the logger. logSys = logging.getLogger("fail2ban.actions.action") @@ -211,13 +212,13 @@ class Action: @staticmethod def executeCmd(realCmd): logSys.debug(realCmd) - retval = os.system(realCmd) - #if not retval == 0: - # logSys.error("'" + cmd + "' returned " + `retval`) - # raise Exception("Execution of command '%s' failed" % cmd) - if retval == 0: - return True - else: - logSys.error("%s returned %x" % (realCmd, retval)) - return False - \ No newline at end of file + try: + retcode = call(realCmd, shell=True) + if retcode < 0: + logSys.error("%s returned %x" % (realCmd, -retcode)) + else: + logSys.debug("%s returned %x" % (realCmd, retcode)) + return True + except OSError, e: + logSys.error("%s failed with %s" % (realCmd, e)) + return False