summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorViacheslav Hletenko <v.gletenko@vyos.io>2025-07-31 19:18:51 +0300
committerGitHub <noreply@github.com>2025-07-31 19:18:51 +0300
commit8c34aa09954f4b266478d48d8a0256e695f4e666 (patch)
tree84c6314eb18a3a9fc3d6717f29b66df446c1c5c7 /python
parentebd16523072e39848d32e88b13c9b8ff72e86aad (diff)
parentfba27cac855cf196a394ac4bb955f9f7402982cb (diff)
downloadvyos-1x-8c34aa09954f4b266478d48d8a0256e695f4e666.tar.gz
vyos-1x-8c34aa09954f4b266478d48d8a0256e695f4e666.zip
Merge pull request #4638 from c-po/is-a-tty
serial: T7484: treat unavailable serial console devices as non-fatal
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/serial.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/python/vyos/utils/serial.py b/python/vyos/utils/serial.py
index 68aad676e..36b483e91 100644
--- a/python/vyos/utils/serial.py
+++ b/python/vyos/utils/serial.py
@@ -116,3 +116,16 @@ def restart_login_consoles(prompt_user=False, quiet=True, devices: List[str]=[])
cmd(f'systemctl stop {unit_name}')
return True
+
+def is_tty(name: str) -> bool:
+ """ Check if a given device file (e.g. /dev/ttyS0) is a TTY (teletypewriter)
+ device in Linux
+ """
+ import os
+ path_tty = f'/dev/{name}'
+ if os.path.exists(path_tty):
+ with open(path_tty, 'rb') as f:
+ fd = f.fileno()
+ # True if filename is a TTY
+ return os.isatty(fd)
+ return False