[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Better messaging when unable to connect to tor on FreeBSD
commit c01d8c859d1272465e4261a10df8f598ea82e889
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Tue Oct 31 10:36:34 2017 -0700
Better messaging when unable to connect to tor on FreeBSD
FreeBSD ps output lists the full tor path rather than just the process name.
Recognizing its default location so our connect() method provides better
messaging when unable to connect.
---
docs/change_log.rst | 3 +++
stem/connection.py | 10 +++++++---
stem/util/system.py | 15 ++++++++++++---
test/unit/util/system.py | 4 +++-
4 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/docs/change_log.rst b/docs/change_log.rst
index 4699c2b9..12a7dc8c 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -54,6 +54,7 @@ The following are only available within Stem's `git repository
* Unable to use cookie auth when path includes wide characters (chinese, japanese, etc)
* Tor change caused :func:`~stem.control.Controller.list_ephemeral_hidden_services` to provide empty strings if unset (:trac:`21329`)
* Better error message when :func:`~stem.control.Controller.set_conf` fails due to an option being immutable
+ * :func:`~stem.control.Controller.get_ports` didn't provide ports for many representations of localhost (:trac:`24085`)
* :func:`~stem.control.Controller.is_geoip_unavailable` now determines if database is available right away
* Added the time attribute to :class:`~stem.response.events.StreamBwEvent` and :class:`~stem.response.events.CircuitBandwidthEvent` (:spec:`00b9daf`)
* Added the consensus_content attribute to :class:`~stem.response.events.NewConsensusEvent` and deprecated its 'desc'
@@ -65,6 +66,7 @@ The following are only available within Stem's `git repository
* Resilient to 'Tor' prefix in 'GETINFO version' result (:spec:`c5ff1b1`)
* Added a **all_extra** parameter to :class:`stem.version.Version` and support for multiple parenthetical entries (:trac:`22110`, :spec:`b50917d`)
* Closing controller connection faster when under heavy event load
+ * Better messaging when unable to connect to tor on FreeBSD
* More succinct trace level logging
* **Descriptors**
@@ -100,6 +102,7 @@ The following are only available within Stem's `git repository
* Added a `'--run [command or path]' argument <tutorials/down_the_rabbit_hole.html#running-individual-commands>`_ to invoke specific commands (:trac:`21541`)
* Allowing interpreter to continue after tor shutsdown (:trac:`22374`)
+ * Interpreter buffered an unbounded number of events, leaking memory over time
* **Website**
diff --git a/stem/connection.py b/stem/connection.py
index cce00bf7..62309f0b 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -198,6 +198,12 @@ CONNECT_MESSAGES = {
'wrong_socket_type': WRONG_SOCKET_TYPE_MSG.strip(),
}
+COMMON_TOR_COMMANDS = (
+ 'tor',
+ 'tor.real', # TBB command ran
+ '/usr/local/bin/tor', # FreeBSD expands the whole path, this is the default location
+)
+
def connect(control_port = ('127.0.0.1', 'default'), control_socket = '/var/run/tor/control', password = None, password_prompt = False, chroot_path = None, controller = stem.control.Controller):
"""
@@ -273,12 +279,10 @@ def connect(control_port = ('127.0.0.1', 'default'), control_socket = '/var/run/
# If unable to connect to either a control socket or port then finally fail
# out. If we only attempted to connect to one of them then provide the error
# output from that. Otherwise we provide a more generic error message.
- #
- # We check for a 'tor.real' process name because that's what TBB uses.
if not control_connection:
if control_socket and control_port:
- is_tor_running = stem.util.system.is_running('tor') or stem.util.system.is_running('tor.real')
+ is_tor_running = stem.util.system.is_running(COMMON_TOR_COMMANDS)
error_msg = CONNECT_MESSAGES['no_control_port'] if is_tor_running else CONNECT_MESSAGES['tor_isnt_running']
print(error_msg)
diff --git a/stem/util/system.py b/stem/util/system.py
index fb799227..459cde4a 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -401,9 +401,10 @@ def is_running(command):
Checks for if a process with a given name or pid is running.
.. versionchanged:: 1.6.0
- Added support for pid arguments.
+ Added support for list and pid arguments.
- :param str,int command: process name if a str or pid if an int to be checked
+ :param str,list,int command: process name if a str, multiple process names if
+ a list, or pid if an int to be checked
:returns: **True** if the process is running, **False** if it's not among ps
results, and **None** if ps can't be queried
@@ -444,7 +445,15 @@ def is_running(command):
if command_listing:
command_listing = map(str_type.strip, command_listing)
- return command in command_listing
+
+ if isinstance(command, (bytes, unicode)):
+ command = [command]
+
+ for cmd in command:
+ if cmd in command_listing:
+ return True
+
+ return False
return None
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index a957a23f..fd8fe2d9 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -137,9 +137,11 @@ class TestSystem(unittest.TestCase):
self.assertTrue(system.is_running('irssi'))
self.assertTrue(system.is_running('moc'))
self.assertTrue(system.is_running('tor'))
+ self.assertTrue(system.is_running(['funky-tor', 'tor']))
self.assertTrue(system.is_running('ps'))
self.assertTrue(system.is_running('firefox'))
- self.assertEqual(False, system.is_running('something_else'))
+ self.assertFalse(system.is_running('something_else'))
+ self.assertFalse(system.is_running(['funky-tor', 'funkier-tor']))
# mock both calls failing
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits