mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
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:
parent
849176ac54
commit
c588783f57
@ -673,7 +673,7 @@ class Onion(object):
|
|||||||
"Onion", "stop_onion_service", f"failed to remove {onion_host}"
|
"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.
|
Stop onion services that were created earlier. If there's a tor subprocess running, kill it.
|
||||||
"""
|
"""
|
||||||
@ -697,31 +697,29 @@ class Onion(object):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if stop_tor:
|
|
||||||
# Stop tor process
|
# Stop tor process
|
||||||
if self.tor_proc:
|
if self.tor_proc:
|
||||||
self.tor_proc.terminate()
|
self.tor_proc.terminate()
|
||||||
time.sleep(0.2)
|
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:
|
try:
|
||||||
self.tor_proc.kill()
|
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:
|
except:
|
||||||
pass
|
self.common.log("Onion", "cleanup", "Exception while killing tor process")
|
||||||
self.tor_proc = None
|
self.tor_proc = None
|
||||||
|
|
||||||
# Reset other Onion settings
|
# Reset other Onion settings
|
||||||
self.connected_to_tor = False
|
self.connected_to_tor = False
|
||||||
self.stealth = False
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Delete the temporary tor data directory
|
# Delete the temporary tor data directory
|
||||||
|
if self.use_tmp_dir:
|
||||||
self.tor_data_directory.cleanup()
|
self.tor_data_directory.cleanup()
|
||||||
except AttributeError:
|
except:
|
||||||
# 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
|
pass
|
||||||
|
|
||||||
def get_tor_socks_port(self):
|
def get_tor_socks_port(self):
|
||||||
|
@ -660,7 +660,7 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
else:
|
else:
|
||||||
tor_status_update_func = None
|
tor_status_update_func = None
|
||||||
|
|
||||||
onion = Onion(self.common)
|
onion = Onion(self.common, use_tmp_dir=True)
|
||||||
onion.connect(
|
onion.connect(
|
||||||
custom_settings=settings,
|
custom_settings=settings,
|
||||||
tor_status_update_func=tor_status_update_func,
|
tor_status_update_func=tor_status_update_func,
|
||||||
|
Loading…
Reference in New Issue
Block a user