Fix bug that was preventing tor from connecting in snapcraft

This commit is contained in:
Micah Lee 2021-11-14 20:53:22 -08:00
parent f09bb66425
commit 99c85f55e2
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 27 additions and 11 deletions

View file

@ -437,6 +437,12 @@ class Common:
Returns True if OnionShare is running in a Flatpak sandbox Returns True if OnionShare is running in a Flatpak sandbox
""" """
return os.environ.get("FLATPAK_ID") == "org.onionshare.OnionShare" return os.environ.get("FLATPAK_ID") == "org.onionshare.OnionShare"
def is_snapcraft(self):
"""
Returns True if OnionShare is running in a Flatpak sandbox
"""
return os.environ.get("SNAP_INSTANCE_NAME") == "onionshare"
@staticmethod @staticmethod
def random_string(num_bytes, output_len=None): def random_string(num_bytes, output_len=None):

View file

@ -29,6 +29,7 @@ import subprocess
import time import time
import shlex import shlex
import psutil import psutil
import traceback
from distutils.version import LooseVersion as Version from distutils.version import LooseVersion as Version
@ -371,11 +372,16 @@ class Onion(object):
startupinfo=startupinfo, startupinfo=startupinfo,
) )
else: else:
if self.common.is_snapcraft():
env = None
else:
env = {"LD_LIBRARY_PATH": os.path.dirname(self.tor_path)}
self.tor_proc = subprocess.Popen( self.tor_proc = subprocess.Popen(
[self.tor_path, "-f", self.tor_torrc], [self.tor_path, "-f", self.tor_torrc],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
env={"LD_LIBRARY_PATH": os.path.dirname(self.tor_path)}, env=env,
) )
# Wait for the tor controller to start # Wait for the tor controller to start
@ -392,16 +398,20 @@ class Onion(object):
"connect", "connect",
"authenticating to tor controller", "authenticating to tor controller",
) )
# try: try:
if self.common.platform == "Windows" or self.common.platform == "Darwin": if (
self.c = Controller.from_port(port=self.tor_control_port) self.common.platform == "Windows"
self.c.authenticate() or self.common.platform == "Darwin"
else: ):
self.c = Controller.from_socket_file(path=self.tor_control_socket) self.c = Controller.from_port(port=self.tor_control_port)
self.c.authenticate() self.c.authenticate()
# except Exception as e: else:
# print("OnionShare could not connect to Tor:\n{}".format(e)) self.c = Controller.from_socket_file(path=self.tor_control_socket)
# raise BundledTorBroken(e.args[0]) self.c.authenticate()
except Exception as e:
print("OnionShare could not connect to Tor:\n{}".format(e.args[0]))
print(traceback.format_exc())
raise BundledTorBroken(e.args[0])
while True: while True:
try: try: