Make cleaning up the onion more reliably kill the tor subprocess, and make iit so testing tor settings in the settings dialog always uses a tmp tor data dir

This commit is contained in:
Micah Lee 2019-11-28 20:32:28 -08:00
parent 849176ac54
commit c588783f57
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 23 additions and 25 deletions

View File

@ -673,7 +673,7 @@ class Onion(object):
"Onion", "stop_onion_service", f"failed to remove {onion_host}"
)
def cleanup(self, stop_tor=True):
def cleanup(self):
"""
Stop onion services that were created earlier. If there's a tor subprocess running, kill it.
"""
@ -697,31 +697,29 @@ class Onion(object):
except:
pass
if stop_tor:
# Stop tor process
if self.tor_proc:
self.tor_proc.terminate()
time.sleep(0.2)
if not self.tor_proc.poll():
if self.tor_proc.poll() == None:
self.common.log("Onion", "cleanup", "Tried to terminate tor process but it's still running")
try:
self.tor_proc.kill()
time.sleep(0.2)
if self.tor_proc.poll() == None:
self.common.log("Onion", "cleanup", "Tried to kill tor process but it's still running")
except:
pass
self.common.log("Onion", "cleanup", "Exception while killing tor process")
self.tor_proc = None
# Reset other Onion settings
self.connected_to_tor = False
self.stealth = False
try:
# Delete the temporary tor data directory
if self.use_tmp_dir:
self.tor_data_directory.cleanup()
except AttributeError:
# Skip if cleanup was somehow run before connect
pass
except PermissionError:
# Skip if the directory is still open (#550)
# TODO: find a better solution
except:
pass
def get_tor_socks_port(self):

View File

@ -660,7 +660,7 @@ class SettingsDialog(QtWidgets.QDialog):
else:
tor_status_update_func = None
onion = Onion(self.common)
onion = Onion(self.common, use_tmp_dir=True)
onion.connect(
custom_settings=settings,
tor_status_update_func=tor_status_update_func,