summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/utils/serial.py13
-rwxr-xr-xsrc/conf_mode/system_console.py7
2 files changed, 20 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
diff --git a/src/conf_mode/system_console.py b/src/conf_mode/system_console.py
index 2f742ee07..fe910c1b0 100755
--- a/src/conf_mode/system_console.py
+++ b/src/conf_mode/system_console.py
@@ -17,9 +17,11 @@
import os
from pathlib import Path
+from vyos.base import Warning
from vyos.config import Config
from vyos.utils.process import call
from vyos.utils.serial import restart_login_consoles
+from vyos.utils.serial import is_tty
from vyos.system import grub_util
from vyos.template import render
from vyos import ConfigError
@@ -66,6 +68,8 @@ def verify(console):
# and it can not be used as a serial interface
if not os.path.isdir(by_bus_dir) or not os.path.exists(by_bus_device):
raise ConfigError(f'Device {device} does not support beeing used as tty')
+ if not is_tty(device):
+ Warning(f'Device "{device}" used for console is not a TTY!')
return None
@@ -98,6 +102,9 @@ def generate(console):
raise ConfigError(f'Device {device} does not support beeing used as tty')
for device, device_config in console['device'].items():
+ # Do not render getty configuration if specified device is not a TTY.
+ if not is_tty(device):
+ continue
config_file = base_dir + f'/serial-getty@{device}.service'
Path(f'{base_dir}/getty.target.wants').mkdir(exist_ok=True)
getty_wants_symlink = base_dir + f'/getty.target.wants/serial-getty@{device}.service'