Merge branch 'onion_cleanup_on_stop_server' of https://github.com/mig5/onionshare into mig5-onion_cleanup_on_stop_server

This commit is contained in:
Micah Lee 2018-01-12 18:56:03 -08:00
commit 9eb4131839
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 23 additions and 18 deletions

View file

@ -415,7 +415,7 @@ class Onion(object):
return onion_host return onion_host
def cleanup(self): def cleanup(self, stop_tor=True):
""" """
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.
""" """
@ -429,25 +429,28 @@ class Onion(object):
pass pass
self.service_id = None self.service_id = None
# Stop tor process if stop_tor:
if self.tor_proc: # Stop tor process
self.tor_proc.terminate() if self.tor_proc:
time.sleep(0.2) self.tor_proc.terminate()
if not self.tor_proc.poll(): time.sleep(0.2)
self.tor_proc.kill() if not self.tor_proc.poll():
self.tor_proc = None try:
self.tor_proc.kill()
except:
pass
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 self.stealth = False
self.service_id = None
try: try:
# Delete the temporary tor data directory # Delete the temporary tor data directory
self.tor_data_directory.cleanup() self.tor_data_directory.cleanup()
except AttributeError: except AttributeError:
# Skip if cleanup was somehow run before connect # Skip if cleanup was somehow run before connect
pass pass
def get_tor_socks_port(self): def get_tor_socks_port(self):
""" """

View file

@ -354,6 +354,8 @@ class OnionShareGui(QtWidgets.QMainWindow):
# Probably we had no port to begin with (Onion service didn't start) # Probably we had no port to begin with (Onion service didn't start)
pass pass
self.app.cleanup() self.app.cleanup()
# Remove ephemeral service, but don't disconnect from Tor
self.onion.cleanup(stop_tor=False)
self.filesize_warning.hide() self.filesize_warning.hide()
self.stop_server_finished.emit() self.stop_server_finished.emit()