#!/usr/bin/execlineb -P
# No device, no getty -- said ONCE instead of tried forever.
#
# Containers do not get this unit at all since s6-policy-exclusive 2.1.7: the
# postinst leaves it out of /etc/s6-linux-init/current when env/container
# exists, and removes a running copy from /run/service. This check stays for
# every other place without the device (a VM without a serial port, a
# container set up by hand).
#
# Why it matters: without /dev/ttyS0 getty exits at once, s6-supervise correctly
# restarts it, and that goes on forever -- measured on dns-1 and puppet-1 at
# about one new process every 10 seconds, some 8600 process starts per day and
# container (Deploy, 23.09.2026). It is not only noise: an acceptance check
# "all longruns up" catches the unit inside its restart window and turns red by
# chance.
#
# The stopping is done by the finish script next to this one: 125 from FINISH
# makes s6-supervise leave the service alone. From run, 125 does NOT work --
# measured, the service kept being restarted every second. This script only
# says its line and leaves; finish decides.
# ifelse, not "if -n": "if -n { test } prog" runs prog when the test FAILS and
# otherwise exits 1 itself -- getty would never be reached. With ifelse the
# rest of the script is the else branch.
ifelse -n { test -c /dev/ttyS0 } {
  foreground {
    echo "getty-ttyS0: /dev/ttyS0 does not exist here -- this unit has nothing to do."
  }
  exit 125
}
getty -L -8 115200 ttyS0
