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