Control: tags -1 patch Hi, patch attached
Andrew, Andras, let me know if this looks good to you Best, Lorenzo
>From 58a61460b572460e67dc911a9eea60bd9b8c6529 Mon Sep 17 00:00:00 2001 From: Lorenzo Puliti <plore...@disroot.org> Date: Wed, 16 Apr 2025 10:50:18 +0200 Subject: [PATCH] getty-run: fix tests for busy getty device * fix tests for when a getty is already busy with a process * use 'exec sv d .' to stop the service, more robust to service name changes * recommends: procps. It's not necessary to guard pgrep calls: due the fact that pgrep returns 0 on success, the test logic continue with the runscript if the pgrep call returns nonzero. Closes: #1103152 --- debian/control | 3 ++- debian/sv/getty-hvc0/finish | 7 +++---- debian/sv/getty-hvc0/run | 4 ++-- debian/sv/getty-ttyS0/run | 22 +++++++++++----------- debian/sv/getty.in/finish.in | 7 +++---- debian/sv/getty.in/run.in | 4 ++-- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/debian/control b/debian/control index c5c3fa0..26adb01 100644 --- a/debian/control +++ b/debian/control @@ -55,9 +55,10 @@ Description: service supervision (systemd and sysv integration) Package: getty-run Architecture: all -Suggests: fgetty Breaks: ${runit:Breaks} Depends: ${misc:Depends}, ${shlibs:Depends} +Recommends: procps +Suggests: fgetty Description: runscripts to supervise getty processes runit is a collection of tools to provide system-wide service supervision and to manage services. Contrary to sysv init, it not only cares about diff --git a/debian/sv/getty-hvc0/finish b/debian/sv/getty-hvc0/finish index 5f43afb..2be1242 100755 --- a/debian/sv/getty-hvc0/finish +++ b/debian/sv/getty-hvc0/finish @@ -1,8 +1,7 @@ #!/bin/sh -euC -SERVICE=getty-hvc0 + if [ "$1" = 163 ] ; then - echo "runsv: ERROR in $SERVICE: another getty already on hvc0" - sv d "$(dirname "${0}")" - exit 0 + echo "runsv: ERROR in ${PWD}: another process already on hvc0" + exec sv d . fi exec utmpset -w hvc0 diff --git a/debian/sv/getty-hvc0/run b/debian/sv/getty-hvc0/run index ab703c8..0237461 100755 --- a/debian/sv/getty-hvc0/run +++ b/debian/sv/getty-hvc0/run @@ -6,7 +6,7 @@ if ! test -c /dev/hvc0 ; then exit 0 fi -pgrep -x getty -t hvc0 && exit 163 -pgrep -x agetty -t hvc0 && exit 163 +pgrep -t hvc0 && exit 163 + ! type fgetty >/dev/null 2>&1 || exec chpst -P fgetty hvc0 exec chpst -P getty 38400 hvc0 linux diff --git a/debian/sv/getty-ttyS0/run b/debian/sv/getty-ttyS0/run index b612359..6b3d957 100755 --- a/debian/sv/getty-ttyS0/run +++ b/debian/sv/getty-ttyS0/run @@ -2,12 +2,12 @@ # get device from kernel command line, override ./env/SGETTY if grep 'console=' /proc/cmdline ; then - kconsole=$(grep -o '\bconsole=[^ ]*' /proc/cmdline) - #TODO: only a subset of this parameter is supported: no uart[8250]/brl, no options - #full format: see https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html - kconsole=${kconsole##*=} #only the last one matches, the kernel writes there - SGETTY=${kconsole%,*} #discard options if any - [ "$SGETTY" = 'null' ] && SGETTY="" #discard null + kconsole=$(grep -o '\bconsole=[^ ]*' /proc/cmdline) + #TODO: only a subset of this parameter is supported: no uart[8250]/brl, no options + #full format: see https://www.kernel.org/doc/html/latest/admin-guide/kernel-parameters.html + kconsole=${kconsole##*=} #only the last one matches, the kernel writes there + SGETTY=${kconsole%,*} #discard options if any + [ "$SGETTY" = 'null' ] && SGETTY="" #discard null fi #don't change here, edit ./env/SGETTY instead @@ -15,12 +15,12 @@ fi [ -z "$SGETTY" ] && SGETTY=ttyS0 if ! test -c /dev/"$SGETTY" ; then - sv d getty-ttyS0 - echo "/dev/$SGETTY not found: stopping getty-ttyS0" + echo "/dev/$SGETTY not found: stopping getty-ttyS0" + exec sv d . fi -if pgrep -x agetty -t "$SGETTY" || pgrep -x fgetty -t "$SGETTY"; then - sv d getty-ttyS0 - echo "already another getty on $SGETTY: stopping getty-ttyS0" +if pgrep -t "$SGETTY" ; then + echo "already another process on $SGETTY: stopping getty-ttyS0" + exec sv d . fi exec 1>&2 diff --git a/debian/sv/getty.in/finish.in b/debian/sv/getty.in/finish.in index 231b4f3..68bb38d 100644 --- a/debian/sv/getty.in/finish.in +++ b/debian/sv/getty.in/finish.in @@ -1,8 +1,7 @@ #!/bin/sh -euC -SERVICE=getty-@TTY@ + if [ "$1" = 163 ] ; then - echo "runsv: ERROR in $SERVICE: another getty already on @TTY@" - sv d "$(dirname "${0}")" - exit 0 + echo "runsv: ERROR in ${PWD}: another getty already on @TTY@" + exec sv d . fi exec utmpset -w @TTY@ diff --git a/debian/sv/getty.in/run.in b/debian/sv/getty.in/run.in index 64d4f34..020205b 100644 --- a/debian/sv/getty.in/run.in +++ b/debian/sv/getty.in/run.in @@ -6,7 +6,7 @@ if ! test -c /dev/@TTY@ ; then exit 0 fi -pgrep -x getty -t @TTY@ && exit 163 -pgrep -x agetty -t @TTY@ && exit 163 +pgrep -t @TTY@ && exit 163 + ! type fgetty >/dev/null 2>&1 || exec chpst -P fgetty @TTY@ exec chpst -P getty 38400 @TTY@ linux -- 2.49.0