runtime/Stunnel.py
author Edouard Tisserant
Tue, 23 Oct 2018 16:13:34 +0200
changeset 2322 7ce4e5cf6339
parent 2321 0a3103cd825d
child 2323 33a0dbabccd3
permissions -rw-r--r--
Added runtime/spawn_subprocess.py. Force use posix spawn instead of fork, with API similar to subprocess. Using fork in runtime is incompatible with Xenomai, because memory is locked and this can lead to out of memory error.
import os
from binascii import hexlify

restart_stunnel_cmdline = ["/etc/init.d/S50stunnel","restart"]

def pskgen(ID, pskpath):
    secretstring = hexlify(os.urandom(256))
    pskstring = ID+":"+secretstring
    with open(pskpath, 'w') as f:
        f.write(pskstring)
    call(restart_stunnel_cmdline)

def ensurepsk(ID, pskpath):
    # check if already there
    if not os.path.exists(pskpath):
        # create if needed
        pskgen(IS, pskpath)