fix forking duplicating processes on shutdown and breaking on windows

master
Kevin Froman 2019-11-01 13:35:28 -05:00
parent 9ccbcf6c1d
commit 027ce4f45b
3 changed files with 15 additions and 2 deletions

View File

@ -19,6 +19,7 @@
""" """
import base64 import base64
import binascii import binascii
import mimetypes
import unpaddedbase32 import unpaddedbase32
@ -37,6 +38,7 @@ site_api = Blueprint('siteapi', __name__)
def site(name: str)->Response: def site(name: str)->Response:
"""Accept a site 'name', if pubkey then show multi-page site, if hash show single page site""" """Accept a site 'name', if pubkey then show multi-page site, if hash show single page site"""
resp: str = 'Not Found' resp: str = 'Not Found'
mime_type = 'text/html'
# If necessary convert the name to base32 from mnemonic # If necessary convert the name to base32 from mnemonic
if mnemonickeys.DELIMITER in name: if mnemonickeys.DELIMITER in name:

View File

@ -126,7 +126,12 @@ def kill_daemon():
''' '''
logger.warn('Stopping the running daemon...', timestamp = False, terminal=True) logger.warn('Stopping the running daemon...', timestamp = False, terminal=True)
try: try:
os.fork() # On platforms where we can, fork out to prevent locking
try:
pid = os.fork()
if pid != 0: return
except (AttributeError, OSError) as e: pass
events.event('daemon_stop') events.event('daemon_stop')
net = NetController(config.get('client.port', 59496)) net = NetController(config.get('client.port', 59496))
try: try:

View File

@ -33,7 +33,13 @@ SCRIPT_NAME = os.path.dirname(os.path.realpath(__file__)) + f'/../../{onionrvalu
def restart(): def restart():
logger.info('Restarting Onionr', terminal=True) logger.info('Restarting Onionr', terminal=True)
os.fork()
# On platforms where we can, fork out to prevent locking
try:
pid = os.fork()
if pid != 0: return
except (AttributeError, OSError) as e: pass
daemonlaunch.kill_daemon() daemonlaunch.kill_daemon()
while localcommand.local_command('ping', maxWait=8) == 'pong!': while localcommand.local_command('ping', maxWait=8) == 'pong!':
time.sleep(0.3) time.sleep(0.3)