diff options
author | Micah Lee <micah@micahflee.com> | 2019-11-28 20:32:28 -0800 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2019-11-28 20:32:28 -0800 |
commit | c588783f57855719b6341ab305451daf6db8c917 (patch) | |
tree | 7ad1673b9f27ad3cb04cb638903ba2f001defda5 /onionshare | |
parent | 849176ac54b4cf0744f67a15b791bb0569e4e629 (diff) | |
download | onionshare-c588783f57855719b6341ab305451daf6db8c917.tar.gz onionshare-c588783f57855719b6341ab305451daf6db8c917.zip |
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
Diffstat (limited to 'onionshare')
-rw-r--r-- | onionshare/onion.py | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/onionshare/onion.py b/onionshare/onion.py index b04ab6b4..4c4112db 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -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,32 +697,30 @@ 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(): - try: - self.tor_proc.kill() - except: - pass - self.tor_proc = None + # Stop tor process + if self.tor_proc: + self.tor_proc.terminate() + time.sleep(0.2) + 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: + 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 + # Reset other Onion settings + self.connected_to_tor = False - try: - # Delete the temporary tor data directory + 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 - pass + except: + pass def get_tor_socks_port(self): """ |