systemd has this really nice feature where instead of spawning gettys for
all the different ttys (usually tty1-tty6), it waits until the user
switches to the tty and then the getty is spawned.
This is really useful since usually gdm gets spawned on tty1, and if you
log into GNOME for example, gdm will look for the next free tty to put
GNOME to. In systemd, this ends up being tty2, but in alpine this ends up
being tty7 since tty1-tty6 have gettys spawned on them via /etc/inittab
which looks like this for me (for reference)
# /etc/inittab
::sysinit:/sbin/openrc sysinit
::sysinit:/sbin/openrc boot
::wait:/sbin/openrc default
# Set up a couple of getty's
tty1::respawn:/sbin/getty 38400 tty1
tty2::respawn:/sbin/getty 38400 tty2
tty3::respawn:/sbin/getty 38400 tty3
tty4::respawn:/sbin/getty 38400 tty4
tty5::respawn:/sbin/getty 38400 tty5
tty6::respawn:/sbin/getty 38400 tty6
# Put a getty on the serial port
#ttyS0::respawn:/sbin/getty -L 115200 ttyS0 vt100
# Stuff to do for the 3-finger salute
::ctrlaltdel:/sbin/reboot
# Stuff to do before rebooting
::shutdown:/sbin/openrc shutdown
Furthermore, the invocation of login on alpine seems to change the owner of
the tty to root:root instead of root:tty which locks out users who would
like to have X on their ttys, which is problematic.
I wanted to make a simple `autovt` script that will get a tty as a
parameter, then a script to execute when the tty is "activated" or switched
to. I'm not particularly sure how systemd does it, but I wrote this sample
script, and it seems to mostly work.
At the end I want to replace the lines in /etc/inittab to be something like
this
tty2::respawn:/usr/local/bin/autovt tty2 -- /sbin/getty 38400 tty2
As this is my first real execline program, I would like to get some
feedback, either towards the execline syntax or even towards the
implementation itself. Thanks in advance.
#!/usr/bin/env -S execlineb
# get the variables
importas tty 1
importas separator 2
importas count \#
# check that we have atleast 3 arguments and that the second argument is
"--"
ifelse -n { eltest $count -ge 3 -a $separator = "--" }
{
# print to stderr
fdmove 1 2
importas prog 0
foreground {
echo "Usage: ${prog} ttyX -- command <args...>"
}
exit 1
}
# get the tty as the first argument
shift -n 2
elgetpositionals
# define paths
define ACTIVE_FILE "/sys/class/tty/tty0/active"
define TTY_DEVICE "/dev/${tty}"
# check everytime the active file changes
pipeline {
# trigger this script atleast once
foreground { echo c $ACTIVE_FILE }
inotifyd - "${ACTIVE_FILE}:c"
}
# Not sure if this should be parallel
forstdin -E _event
# check the currently active TTY
backtick -E ACTIVE_TTY { cat $ACTIVE_FILE }
# test if the current active tty is the same as the requested one, or else,
move to next iteration
if { eltest $ACTIVE_TTY = $tty }
# check if there is nothing already running on the tty
if -n {
fdmove 2 1
redirfd -w 1 /dev/null
fuser $TTY_DEVICE
}
exec $_at_
Received on Fri May 23 2025 - 00:40:27 CEST