[tor-commits] [sbws/master] Change runtime directory when running supervised

juga at torproject.org juga at torproject.org
Thu Nov 1 08:19:26 UTC 2018


commit ffb625ed2d3c9247ee26df107fe84b7d6c61a230
Author: juga0 <juga at riseup.net>
Date:   Wed Oct 31 19:44:41 2018 +0000

    Change runtime directory when running supervised
    
    Also go back to use sbws datadir as the default location for the
    tor temporal file sockets, because when XDG_RUNTIME_DIR is not
    set, the interpolation does not happen.
---
 sbws/config.default.ini |  3 +--
 sbws/globals.py         |  2 ++
 sbws/util/config.py     | 12 +++++++++++-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index 93b3505..8abee3d 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -58,8 +58,7 @@ max_download_size = 1073741824
 
 [tor]
 datadir = ${paths:sbws_home}/tor
-# create runtime dir for data that does not need to be persistent
-run_dpath = $$XDG_RUNTIME_DIR/sbws
+run_dpath = ${datadir}
 control_socket = ${tor:run_dpath}/control
 pid = ${tor:run_dpath}/tor.pid
 # note this is a directory
diff --git a/sbws/globals.py b/sbws/globals.py
index 66effd5..5dd644e 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -28,6 +28,8 @@ DEFAULT_CONFIG_PATH = os.path.join(PKG_DIR, 'config.default.ini')
 DEFAULT_LOG_CONFIG_PATH = os.path.join(PKG_DIR, 'config.log.default.ini')
 USER_CONFIG_PATH = os.path.join(os.path.expanduser('~'), '.sbws.ini')
 
+SUPERVISED_RUN_DPATH = "/run/sbws/tor"
+
 SOCKET_TIMEOUT = 60  # seconds
 
 SBWS_SCALE_CONSTANT = 7500
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 8ba5aac..2f6fa51 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -9,7 +9,7 @@ from urllib.parse import urlparse
 from string import Template
 from tempfile import NamedTemporaryFile
 from sbws.globals import (DEFAULT_CONFIG_PATH, DEFAULT_LOG_CONFIG_PATH,
-                          USER_CONFIG_PATH, fail_hard)
+                          USER_CONFIG_PATH, SUPERVISED_RUN_DPATH, fail_hard)
 
 _ALPHANUM = 'abcdefghijklmnopqrstuvwxyz'
 _ALPHANUM += _ALPHANUM.upper()
@@ -217,6 +217,15 @@ def _validate_general(conf):
     return errors
 
 
+def _obtain_run_dpath(conf):
+    """Set runtime directory when sbws is run by a system service."""
+    xdg = os.environ.get('XDG_RUNTIME_DIR')
+    if os.environ.get('SUPERVISED') == "1":
+        conf['tor']['run_dpath'] = SUPERVISED_RUN_DPATH
+    elif xdg is not None:
+        conf['tor']['run_dpath'] = os.path.join(xdg, 'sbws', 'tor')
+
+
 def _validate_paths(conf):
     errors = []
     sec = 'paths'
@@ -262,6 +271,7 @@ def _validate_scanner(conf):
 
 
 def _validate_tor(conf):
+    _obtain_run_dpath(conf)
     errors = []
     sec = 'tor'
     err_tmpl = Template('$sec/$key ($val): $e')





More information about the tor-commits mailing list