mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-28 16:59:35 -05:00
Kill stale tor process
This commit is contained in:
parent
9f21d505de
commit
894fb7c070
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user