serial-console: Use udev rules to startup getty

Update the systemd serial port element implementation
so that it uses udev rules. Much nicer than
hard coding ttyS0 and ttyS1.

The udev rule only adds real serial device types
(i.e. == 4). See:

  define TTY_DRIVER_TYPE_SERIAL 0x0003

from include/linux/tty_driver.h.

Change-Id: I5d7de4815fd09c01693b7da4b8949f22fee20745
This commit is contained in:
Dan Prince 2014-03-19 16:21:43 -04:00
parent 39964b975e
commit 576fa64abf
3 changed files with 6 additions and 7 deletions

View File

@ -1,4 +1,4 @@
Start getty on ttyS0 and/or ttyS1
Start getty on active serial consoles.
With ILO and other remote admin environments, having a serial console can be
useful for debugging and troubleshooting.
@ -7,4 +7,4 @@ For upstart:
If ttyS1 exists, getty will run on that, otherwise on ttyS0.
For systemd:
Try to start getty on both ttyS0 and ttyS1.
We dynamically start a getty on any active serial port via udev rules.

View File

@ -1,12 +1,10 @@
#!/bin/bash
home=$(dirname $0)
set -uex
SCRIPTDIR=$(dirname $0)
DIB_INIT_SYSTEM=$(dib-init-system)
if [ "$DIB_INIT_SYSTEM" == "upstart" ]; then
install -m 0644 -o root -g root $home/ttySx.conf /etc/init/ttySx.conf
install -m 0644 -o root -g root ${SCRIPTDIR}/ttySx.conf /etc/init/ttySx.conf
elif [ "$DIB_INIT_SYSTEM" == "systemd" ]; then
ln -s /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyS0.service
ln -s /usr/lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttyS1.service
install -D -g root -o root -m 0644 ${SCRIPTDIR}/serial-console-udev.rules /etc/udev/rules.d/99-serial-console.rules
fi

View File

@ -0,0 +1 @@
SUBSYSTEM=="tty", ACTION=="add", TAG+="systemd", ENV{SYSTEMD_WANTS}+="getty@$name.service", ATTRS{type}=="4"