klippy_connect: resolve the uds path
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
1ef34b8b60
commit
1a3689cb7d
|
@ -15,6 +15,7 @@ import confighelper
|
||||||
import asyncio
|
import asyncio
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
|
import pathlib
|
||||||
from utils import ServerError
|
from utils import ServerError
|
||||||
|
|
||||||
# Annotation imports
|
# Annotation imports
|
||||||
|
@ -46,8 +47,9 @@ UNIX_BUFFER_LIMIT = 20 * 1024 * 1024
|
||||||
class KlippyConnection:
|
class KlippyConnection:
|
||||||
def __init__(self, config: confighelper.ConfigHelper) -> None:
|
def __init__(self, config: confighelper.ConfigHelper) -> None:
|
||||||
self.server = config.get_server()
|
self.server = config.get_server()
|
||||||
self.uds_address: str = config.get(
|
uds_addr: str = config.get(
|
||||||
'klippy_uds_address', "/tmp/klippy_uds")
|
'klippy_uds_address', "/tmp/klippy_uds")
|
||||||
|
self.uds_address = pathlib.Path(uds_addr).expanduser().resolve()
|
||||||
self.writer: Optional[asyncio.StreamWriter] = None
|
self.writer: Optional[asyncio.StreamWriter] = None
|
||||||
self.connection_mutex: asyncio.Lock = asyncio.Lock()
|
self.connection_mutex: asyncio.Lock = asyncio.Lock()
|
||||||
self.event_loop = self.server.get_event_loop()
|
self.event_loop = self.server.get_event_loop()
|
||||||
|
@ -217,9 +219,9 @@ class KlippyConnection:
|
||||||
await asyncio.sleep(INIT_TIME)
|
await asyncio.sleep(INIT_TIME)
|
||||||
if self.closing or not self.server.is_running():
|
if self.closing or not self.server.is_running():
|
||||||
return False
|
return False
|
||||||
if not os.path.exists(self.uds_address):
|
if not self.uds_address.exists():
|
||||||
continue
|
continue
|
||||||
if not os.access(self.uds_address, os.R_OK | os.W_OK):
|
if not os.access(str(self.uds_address), os.R_OK | os.W_OK):
|
||||||
if self.log_no_access:
|
if self.log_no_access:
|
||||||
user = getpass.getuser()
|
user = getpass.getuser()
|
||||||
logging.info(
|
logging.info(
|
||||||
|
@ -231,7 +233,7 @@ class KlippyConnection:
|
||||||
self.log_no_access = True
|
self.log_no_access = True
|
||||||
try:
|
try:
|
||||||
reader, writer = await asyncio.open_unix_connection(
|
reader, writer = await asyncio.open_unix_connection(
|
||||||
self.uds_address, limit=UNIX_BUFFER_LIMIT)
|
str(self.uds_address), limit=UNIX_BUFFER_LIMIT)
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
raise
|
raise
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
Loading…
Reference in New Issue