Skip to content

Commit 9260646

Browse files
authored
Wheel Speed Controller Permission Denied Error (#494)
* Bug fixed: wrong format of permission. (#493) * Added error catches for LTM. (#493) * Added pre-check for write permission. (#493) * Added debug info. (#493) * Bug fixed. (#493) * Bug fixed. (#493) * Added debug info. (#493) * Hinted the permission issue. (#493) * Merged submodules. (#493) * Merged submodules. (#493)
1 parent 21d9115 commit 9260646

4 files changed

Lines changed: 44 additions & 10 deletions

File tree

leads/ltm.py

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,54 @@
11
from json import loads as _loads, dumps as _dumps
2-
from os.path import abspath as _abspath
2+
from os import chmod as _chmod, access as _access, R_OK as _R_OK, W_OK as _W_OK
3+
from os.path import abspath as _abspath, exists as _exists
34

5+
from leads.logger import L
46
from leads.types import SupportedConfigValue as _SupportedConfigValue
57

8+
_PATH: str = f"{_abspath(__file__)[:-6]}_ltm/core"
9+
610
_ltm: dict[str, _SupportedConfigValue] = {}
711

812

13+
def _acquire_permission() -> bool:
14+
if _access(_PATH, _R_OK) and _access(_PATH, _W_OK):
15+
return True
16+
L.debug(f"Attempting to acquire permission for {_PATH}")
17+
try:
18+
_chmod(_PATH, 0o666)
19+
return True
20+
except Exception as e:
21+
L.debug(f"Failed to acquire permission: {repr(e)}")
22+
L.debug(f"For Linux users, try executing `sudo chmod 666 {_PATH}` manually or run LEADS as the root user")
23+
return False
24+
25+
926
def _load_ltm() -> None:
27+
if not _permission_ok:
28+
return
1029
global _ltm
11-
with open(f"{_abspath(__file__)[:-6]}_ltm/core") as f:
12-
ltm_content = f.read()
13-
if not (ltm_content.startswith("{") and ltm_content.endswith("}")):
14-
ltm_content = "{}"
15-
_ltm = _loads(ltm_content)
30+
try:
31+
if not _exists(_PATH):
32+
with open(_PATH, "w") as f:
33+
f.write("{}")
34+
return
35+
with open(_PATH) as f:
36+
ltm_content = f.read()
37+
if not (ltm_content.startswith("{") and ltm_content.endswith("}")):
38+
ltm_content = "{}"
39+
_ltm = _loads(ltm_content)
40+
except Exception as e:
41+
L.warn(f"Attempted but failed to load LTM: {repr(e)}")
1642

1743

1844
def _sync_ltm() -> None:
19-
with open(f"{_abspath(__file__)[:-6]}_ltm/core", "w") as f:
20-
f.write(_dumps(_ltm))
45+
if not _permission_ok:
46+
return
47+
try:
48+
with open(_PATH, "w") as f:
49+
f.write(_dumps(_ltm))
50+
except Exception as e:
51+
L.warn(f"Attempted but failed to sync LTM: {repr(e)}")
2152

2253

2354
def ltm_get(key: str) -> _SupportedConfigValue:
@@ -29,4 +60,6 @@ def ltm_set(key: str, value: _SupportedConfigValue) -> None:
2960
_sync_ltm()
3061

3162

63+
_permission_ok: bool = _acquire_permission()
64+
L.debug(f"LTM permission {"OK" if _permission_ok else "NOT OK"}: {_PATH}")
3265
_load_ltm()

leads_vec/_bootloader/systemd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def register_leads_vec() -> None:
1616
_mkdirs("/usr/local/leads")
1717
with open("/usr/local/leads/config.json", "w") as f:
1818
f.write(str(Config({})))
19-
_chmod("/usr/local/leads/config.json", 0x644)
19+
_chmod("/usr/local/leads/config.json", 0o644)
2020
_chmod(script := f"{_abspath(__file__)[:-10]}leads-vec.service.sh", 0o755)
2121
if not _exists(user_systemd := f"/home/{(username := _get_login())}/.config/systemd/user"):
2222
_L.debug(f"User Systemd not found. Creating \"{user_systemd}\"...")

readthedocs

scripts/setup.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ execute_root "chmod" "+x" "/bin/leads-vec-rc"
3232
execute_root "echo" "#!/bin/bash" > "/bin/leads-vec-dp"
3333
execute_root "echo" 'python-leads -m leads_vec_dp "$@"' >> "/bin/leads-vec-dp"
3434
execute_root "chmod" "+x" "/bin/leads-vec-dp"
35+
execute_root "chmod" "666" "/usr/local/leads/venv/lib/python3.12/site-packages/leads/_ltm/core"
3536
echo "Verifying..."
3637
execute "leads-vec" "info"

0 commit comments

Comments
 (0)