Read mountinfo as binary file, ignore board-except for emit fallback

This commit is contained in:
Jan Čermák 2025-07-09 15:23:22 +02:00
parent 1ff0ee5256
commit e440429e48
No known key found for this signature in database
GPG Key ID: A78C897AA3AF012B

View File

@ -79,11 +79,11 @@ class HAOSLogHandler(JournaldLogHandler):
# mounted in the container or passed it there using other means. # mounted in the container or passed it there using other means.
# Not obtaining it will only result in the logs not being available # Not obtaining it will only result in the logs not being available
# through `docker logs` command, so it is not a critical issue. # through `docker logs` command, so it is not a critical issue.
with open("/proc/self/mountinfo") as f: with open("/proc/self/mountinfo", mode="rb") as f:
for line in f: for line in f:
if "/docker/containers/" in line: if b"/docker/containers/" in line:
container_id = line.split("/docker/containers/")[-1] container_id = line.split(b"/docker/containers/")[-1]
return container_id.split("/")[0] return str(container_id.split(b"/")[0])
return None return None
@classmethod @classmethod
@ -103,7 +103,7 @@ class HAOSLogHandler(JournaldLogHandler):
# only container ID is needed for interpretation through `docker logs` # only container ID is needed for interpretation through `docker logs`
formatted.append(("CONTAINER_ID", self._container_id)) formatted.append(("CONTAINER_ID", self._container_id))
self.transport.send(formatted) self.transport.send(formatted)
except Exception: except Exception: # pylint: disable=broad-except
self._fallback(record) self._fallback(record)