From 8195ffbeb664c3aead73c8447eb3a2ef6ce12199 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Tue, 8 Oct 2019 17:26:44 -0500 Subject: [PATCH] bug fixes for tor and lock files --- onionr/etc/cleanup/__init__.py | 1 + onionr/netcontroller/netcontrol.py | 16 +++++++++++++--- onionr/onionrcommands/daemonlaunch.py | 12 ++++++------ onionr/onionrcommands/pubkeymanager.py | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/onionr/etc/cleanup/__init__.py b/onionr/etc/cleanup/__init__.py index 56b3e402..cd4a9474 100644 --- a/onionr/etc/cleanup/__init__.py +++ b/onionr/etc/cleanup/__init__.py @@ -10,3 +10,4 @@ def delete_run_files(): _safe_remove(filepaths.public_API_host_file) _safe_remove(filepaths.private_API_host_file) _safe_remove(filepaths.daemon_mark_file) + _safe_remove(filepaths.lock_file) diff --git a/onionr/netcontroller/netcontrol.py b/onionr/netcontroller/netcontrol.py index 39dafa0d..dcd0d18a 100644 --- a/onionr/netcontroller/netcontrol.py +++ b/onionr/netcontroller/netcontrol.py @@ -128,15 +128,14 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) tor = subprocess.Popen([self.torBinary, '-f', self.torConfigLocation], stdout=subprocess.PIPE, stderr=subprocess.PIPE) except FileNotFoundError: logger.fatal("Tor was not found in your path or the Onionr directory. Please install Tor and try again.", terminal=True) - sys.exit(1) + return False else: # Test Tor Version torVersion = subprocess.Popen([self.torBinary, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) for line in iter(torVersion.stdout.readline, b''): if 'Tor 0.2.' in line.decode(): logger.fatal('Tor 0.3+ required', terminal=True) - sys.exit(1) - break + return False torVersion.kill() # wait for tor to get to 100% bootstrap @@ -147,6 +146,13 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) break elif 'opening socks listener' in line.decode().lower(): logger.debug(line.decode().replace('\n', '')) + else: + if 'err' in line.decode(): + logger.error(line.decode().replace('\n', '')) + elif 'warn' in line.decode(): + logger.warn(line.decode().replace('\n', '')) + else: + logger.debug(line.decode().replace('\n', '')) else: logger.fatal('Failed to start Tor. Maybe a stray instance of Tor used by Onionr is still running? This can also be a result of file permissions being too open', terminal=True) return False @@ -213,3 +219,7 @@ HiddenServicePort 80 ''' + self.apiServerIP + ''':''' + str(self.hsPort) os.kill(int(pidN), signal.SIGKILL) except (ProcessLookupError, PermissionError) as e: pass + try: + os.remove(self.dataDir + 'tordata/lock') + except FileNotFoundError: + pass diff --git a/onionr/onionrcommands/daemonlaunch.py b/onionr/onionrcommands/daemonlaunch.py index cfb86ebd..78eef666 100755 --- a/onionr/onionrcommands/daemonlaunch.py +++ b/onionr/onionrcommands/daemonlaunch.py @@ -91,6 +91,7 @@ def daemon(): logger.info('Tor is starting...', terminal=True) if not net.startTor(): localcommand.local_command('shutdown') + cleanup.delete_run_files() sys.exit(1) if len(net.myID) > 0 and config.get('general.security_level', 1) == 0: logger.debug('Started .onion service: %s' % (logger.colors.underline + net.myID)) @@ -101,7 +102,7 @@ def daemon(): try: time.sleep(1) except KeyboardInterrupt: - _proper_shutdown() + pass events.event('init', threaded = False) events.event('daemon_start') communicator.startCommunicator(shared_state) @@ -150,10 +151,9 @@ def start(input: bool = False, override: bool = False): lockFile.write('delete at your own risk') lockFile.close() daemon() - if not onionrvalues.DEVELOPMENT_MODE: - try: - os.remove(filepaths.lock_file) - except FileNotFoundError: - pass + try: + os.remove(filepaths.lock_file) + except FileNotFoundError: + pass start.onionr_help = "Start Onionr node (public and clients API servers)" diff --git a/onionr/onionrcommands/pubkeymanager.py b/onionr/onionrcommands/pubkeymanager.py index e301ccc8..27873289 100755 --- a/onionr/onionrcommands/pubkeymanager.py +++ b/onionr/onionrcommands/pubkeymanager.py @@ -116,4 +116,4 @@ def add_vanity(): key_manager.addKey(b32_pub, unpaddedbase32.b32encode(vanity[1])) except KeyboardInterrupt: pass -add_vanity.onionr_help = " - Generates and stores an Onionr vanity address (see https://github.com/trezor/python-mnemonic/blob/master/mnemonic/wordlist/english.txt)" +add_vanity.onionr_help = " - Generates and stores an Onionr vanity address (see https://github.com/moreati/python-niceware/blob/master/niceware/wordlist.py)"