klippy_connection: handle credential exceptions

Handle exceptions should the attempt to fetch peer
credentials on the unix socket fail.  This isn't a hard
requirement for connection and should not cause
the connection to abort.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-04-08 14:37:11 -04:00
parent b21f909705
commit 7631999c8f
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
1 changed files with 8 additions and 2 deletions

View File

@ -232,8 +232,14 @@ class KlippyConnection:
"Unable to get Unix Socket, cant fetch peer credentials"
)
return
data = sock.getsockopt(socket.SOL_SOCKET, socket.SO_PEERCRED, 12)
pid, uid, gid = struct.unpack("@LLL", data)
try:
data = sock.getsockopt(socket.SOL_SOCKET, socket.SO_PEERCRED, 12)
pid, uid, gid = struct.unpack("@LLL", data)
except asyncio.CancelledError:
raise
except Exception:
logging.exception("Failed to get Klippy Credentials")
return
self._peer_cred = {
"process_id": pid,
"user_id": uid,