summaryrefslogtreecommitdiff
path: root/src/conf_mode/system_console.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-06-09 20:38:46 +0200
committerChristian Poessinger <christian@poessinger.com>2020-06-09 21:12:36 +0200
commitce7bf15a508beb29d59088c8b5b4ecaeb1694df7 (patch)
tree8155314d8c9d225cd8212d8e20f52f03b9ce651c /src/conf_mode/system_console.py
parentbafa91b945ac77e2e1d000e356ca819bd5f87460 (diff)
downloadvyos-1x-ce7bf15a508beb29d59088c8b5b4ecaeb1694df7.tar.gz
vyos-1x-ce7bf15a508beb29d59088c8b5b4ecaeb1694df7.zip
console: T2569: only start serial console if device exists
Only start console if it exists on the running system. If a user detaches a USB serial console and reboots - it should not fail!
Diffstat (limited to 'src/conf_mode/system_console.py')
-rwxr-xr-xsrc/conf_mode/system_console.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/conf_mode/system_console.py b/src/conf_mode/system_console.py
index a3e450a36..6d60a9d4d 100755
--- a/src/conf_mode/system_console.py
+++ b/src/conf_mode/system_console.py
@@ -22,6 +22,8 @@ from vyos.template import render
from vyos import ConfigError, airbag
airbag.enable()
+by_bus_dir = '/dev/serial/by-bus'
+
def get_config():
conf = Config()
base = ['system', 'console']
@@ -50,10 +52,11 @@ def get_config():
# getty, but that name may change across reboots - depending on the
# amount of connected devices. We will resolve the fixed device name
# to its dynamic device file - and create a new dict entry for it.
- #
- # updating the dict must come as last step in the loop!
- tmp = os.path.basename(os.readlink('/dev/serial/by-bus/usb0b1p1.0'))
- console['device'][tmp] = console['device'].pop(device)
+ by_bus_device = f'{by_bus_dir}/{device}'
+ if os.path.isdir(by_bus_dir) and os.path.exists(by_bus_device):
+ tmp = os.path.basename(os.readlink(by_bus_device))
+ # updating the dict must come as last step in the loop!
+ console['device'][tmp] = console['device'].pop(device)
return console
@@ -91,7 +94,10 @@ def apply(console):
# Start getty process on configured serial interfaces
for device in console['device'].keys():
- call(f'systemctl start serial-getty@{device}.service')
+ # Only start console if it exists on the running system. If a user
+ # detaches a USB serial console and reboots - it should not fail!
+ if os.path.exists(f'/dev/{device}'):
+ call(f'systemctl start serial-getty@{device}.service')
return None