Commit e3781aff authored by Julien Muchembled's avatar Julien Muchembled

Reduce probability of dying when the system lacks memory

Some servers can only be accessed via their re6st IP. re6st itself uses little
memory so it should not die when it fails to fork.
parent e7649c78
......@@ -16,7 +16,7 @@ class MultiGatewayManager(dict):
if gw:
cmd = 'ip', '-4', 'route', cmd, '%s/32' % dest, 'via', gw
logging.trace('%r', cmd)
subprocess.call(cmd)
subprocess.check_call(cmd)
def add(self, dest, route):
try:
......@@ -150,7 +150,7 @@ class TunnelManager(object):
action = 'add'
args = 'ip', 'tuntap', action, 'dev', iface, 'mode', 'tap'
logging.debug('%r', args)
subprocess.call(args)
subprocess.check_call(args)
return iface
def delInterfaces(self):
......
......@@ -147,6 +147,14 @@ exit = exit()
class Popen(subprocess.Popen):
def __init__(self, *args, **kw):
try:
super(Popen, self).__init__(*args, **kw)
except OSError, e:
if e.errno != errno.ENOMEM:
raise
self.returncode = -1
def stop(self):
self.terminate()
t = threading.Timer(5, self.kill)
......@@ -230,8 +238,7 @@ def iterRoutes(network, exclude_prefix=None):
yield iface, prefix
def decrypt(key_path, data):
p = subprocess.Popen(
('openssl', 'rsautl', '-decrypt', '-inkey', key_path),
p = Popen(('openssl', 'rsautl', '-decrypt', '-inkey', key_path),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = p.communicate(data)
if p.returncode:
......@@ -242,7 +249,7 @@ def encrypt(cert, data):
r, w = os.pipe()
try:
threading.Thread(target=os.write, args=(w, cert)).start()
p = subprocess.Popen(('openssl', 'rsautl', '-encrypt', '-certin',
p = Popen(('openssl', 'rsautl', '-encrypt', '-certin',
'-inkey', '/proc/self/fd/%u' % r),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = p.communicate(data)
......
......@@ -369,7 +369,11 @@ def main():
try:
while True:
time.sleep(60)
try:
check_no_default_route()
except OSError, e:
if e.errno != errno.ENOMEM:
raise
except:
utils.log_exception()
finally:
......
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 to comment