From e7dd78dba7e085863bef7518e59cac895bbd482c Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 7 Dec 2017 16:08:03 +1100 Subject: [PATCH] cleanup the ephemeral hidden service when GUI server is stopped, but don't disconnect from Tor --- onionshare/onion.py | 39 +++++++++++++++++--------------- onionshare_gui/onionshare_gui.py | 2 ++ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 218dafd5..00b7dd51 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -422,7 +422,7 @@ class Onion(object): 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. """ @@ -436,25 +436,28 @@ class Onion(object): pass self.service_id = None - # Stop tor process - if self.tor_proc: - self.tor_proc.terminate() - time.sleep(0.2) - if not self.tor_proc.poll(): - self.tor_proc.kill() - self.tor_proc = None + 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 - # Reset other Onion settings - self.connected_to_tor = False - self.stealth = False - self.service_id = None + # Reset other Onion settings + self.connected_to_tor = False + self.stealth = False - try: - # Delete the temporary tor data directory - self.tor_data_directory.cleanup() - except AttributeError: - # Skip if cleanup was somehow run before connect - pass + try: + # Delete the temporary tor data directory + self.tor_data_directory.cleanup() + except AttributeError: + # Skip if cleanup was somehow run before connect + pass def get_tor_socks_port(self): """ diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index a5fb0edb..17b4cfc1 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -355,6 +355,8 @@ class OnionShareGui(QtWidgets.QMainWindow): # Probably we had no port to begin with (Onion service didn't start) pass self.app.cleanup() + # Remove ephemeral service, but don't disconnect from Tor + self.onion.cleanup(stop_tor=False) self.filesize_warning.hide() self.stop_server_finished.emit()