diff options
author | Micah Lee <micah@micahflee.com> | 2020-11-17 18:06:36 -0800 |
---|---|---|
committer | Micah Lee <micah@micahflee.com> | 2020-11-17 18:06:36 -0800 |
commit | 894fb7c070aeff35af7786bf2c01f373f1fedf5a (patch) | |
tree | 4030c3faef875c558b925fcdd7b1192c0a9e5110 /cli | |
parent | 9f21d505de1c37f2159fb7d08fb88775a171183a (diff) | |
download | onionshare-894fb7c070aeff35af7786bf2c01f373f1fedf5a.tar.gz onionshare-894fb7c070aeff35af7786bf2c01f373f1fedf5a.zip |
Kill stale tor process
Diffstat (limited to 'cli')
-rw-r--r-- | cli/onionshare_cli/onion.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/cli/onionshare_cli/onion.py b/cli/onionshare_cli/onion.py index 0f712d5d..95734b1a 100644 --- a/cli/onionshare_cli/onion.py +++ b/cli/onionshare_cli/onion.py @@ -28,6 +28,7 @@ import tempfile import subprocess import time import shlex +import getpass import psutil from distutils.version import LooseVersion as Version @@ -115,13 +116,6 @@ class TorTooOld(Exception): pass -class BundledTorNotSupported(Exception): - """ - This exception is raised if onionshare is set to use the bundled Tor binary, - but it's not supported on that platform, or in dev mode. - """ - - class BundledTorTimeout(Exception): """ This exception is raised if onionshare is set to use the bundled Tor binary, @@ -242,6 +236,23 @@ class Onion(object): raise OSError("OnionShare port not available") self.tor_torrc = os.path.join(self.tor_data_directory_name, "torrc") + # If there is an existing OnionShare tor process, kill it + for proc in psutil.process_iter(["pid", "name", "username"]): + if proc.username() == getpass.getuser(): + cmdline = proc.cmdline() + if ( + cmdline[0] == self.tor_path + and cmdline[1] == "-f" + and cmdline[2] == self.torrc + ): + self.common.log( + "Onion", + "connect", + "found a stale tor process, killing it", + ) + proc.terminate() + proc.wait() + if self.common.platform == "Windows" or self.common.platform == "Darwin": # Windows doesn't support unix sockets, so it must use a network port. # macOS can't use unix sockets either because socket filenames are limited to |