Commit 36b312b6 by Bach Dániel

add logging

parent 89ad48aa
......@@ -37,9 +37,12 @@ def reload_firewall(data4, data6, save_config=True):
if isinstance(data6, dict):
data6 = ('\n'.join(data6['filter']) + '\n')
ns_exec(NETNS, ('ip6tables-restore', '-c'), data6)
ns_exec(NETNS, ('iptables-restore', '-c'), data4)
try:
ns_exec(NETNS, ('ip6tables-restore', '-c'), data6)
ns_exec(NETNS, ('iptables-restore', '-c'), data4)
except:
logging.critical('Unhandled exception: ', exc_info=True)
raise
if save_config:
with open(FIREWALL_CONF, 'w') as f:
......
......@@ -30,14 +30,18 @@ dhcp_no_free_re = re.compile(r'\S DHCPDISCOVER '
def sudo(args, stdin=None):
FNULL = open(devnull, 'w')
args = ('/usr/bin/sudo', ) + args
logger.debug('EXEC {}'.format(' '.join(args)))
p = sp.Popen(args, stdin=sp.PIPE, stderr=sp.PIPE, stdout=sp.PIPE)
if isinstance(stdin, basestring):
proc = sp.Popen(args, stdin=sp.PIPE, stderr=FNULL)
return proc.communicate(stdin)
stdout, stderr = p.communicate(stdin)
else:
return sp.check_output(args, stderr=FNULL)
stdout, stderr = p.communicate()
if p.returncode != 0:
raise sp.CalledProcessError(
p.returncode, sp.list2cmdline(args), stderr)
return stdout
def ns_exec(netns, args, stdin=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment