Skip to contentSkip to conversation

sysvinit-initab: rewrite loop to generate inittab

PATCH New [email protected] 1 participant 4 messages Oct 6, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 sysvinit-initab: rewrite loop to generate inittab

From: Ross Burton <[email protected]>

Instead of one-letter variables and arcane sed expressions, use English words and 'cut'.

(From OE-Core rev: de9833792dd0cfac6f17d5c733c263b976e89cf6)

---
 .../sysvinit/sysvinit-inittab_2.88dsf.bb           | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb +7 -7
index b1f9cb4caa6..e70dc705c05 100644
@@ -21,14 +21,14 @@ do_install() {
     install -m 0755 ${WORKDIR}/start_getty ${D}${base_bindir}/start_getty
     sed -e 's,/usr/bin,${bindir},g' -i ${D}${base_bindir}/start_getty
 
-    set -x
-    tmp="${SERIAL_CONSOLES}"
-    for i in $tmp
+    CONSOLES="${SERIAL_CONSOLES}"
+    for s in $CONSOLES
     do
-	j=`echo ${i} | sed s/\;/\ /g`
-	l=`echo ${i} | sed -e 's/tty//' -e 's/^.*;//' -e 's/;.*//'`
-	label=`echo $l | sed 's/.*\(....\)/\1/'`
-	echo "$label:12345:respawn:${base_bindir}/start_getty ${j} vt102" >> ${D}${sysconfdir}/inittab
+        speed=$(echo $s | cut -d\; -f 1)
+        device=$(echo $s | cut -d\; -f 2)
+        label=$(echo $device | sed -e 's/tty//' | tail --bytes=5)
+
+        echo "$label:12345:respawn:${base_bindir}/start_getty $speed $device vt102" >> ${D}${sysconfdir}/inittab
     done
 
     if [ "${USE_VT}" = "1" ]; then
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/4 ttyrun: add new recipe

From: Ross Burton <[email protected]>

ttyrun is a small tool from IBM's s390-tools package to run a command if the specified TTY is present, and hang if not.

This is useful so that you can list all of the potential terminals in inittab and not have getty quiting instantly when a device isn't present, resulting in the "respawning too fast" errors.

Note that DISTRELEASE has to be set as otherwise "build$(DATE)" is used, which is non-reproducible.

---
 meta/conf/distro/include/maintainers.inc  |  1 +
 meta/recipes-core/ttyrun/ttyrun_2.29.0.bb | 33 +++++++++++++++++++++++
 2 files changed, 34 insertions(+)
 create mode 100644 meta/recipes-core/ttyrun/ttyrun_2.29.0.bb
meta/conf/distro/include/maintainers.inc +1 -0
index dcc507bb982..b2579fc44c3 100644
@@ -810,6 +810,7 @@ RECIPE_MAINTAINER:pn-texinfo-dummy-native = "Anuj Mittal <[email protected]>
 RECIPE_MAINTAINER:pn-tiff = "Alexander Kanavin <[email protected]>"
 RECIPE_MAINTAINER:pn-time = "Robert Yang <[email protected]>"
 RECIPE_MAINTAINER:pn-ttf-bitstream-vera = "Anuj Mittal <[email protected]>"
+RECIPE_MAINTAINER:pn-ttyrun = "Ross Burton <[email protected]>"
 RECIPE_MAINTAINER:pn-tzcode-native = "Unassigned <[email protected]>"
 RECIPE_MAINTAINER:pn-tzdata = "Unassigned <[email protected]>"
 RECIPE_MAINTAINER:pn-u-boot = "Marek Vasut <[email protected]>"
meta/recipes-core/ttyrun/ttyrun_2.29.0.bb new file +33 -0
new file mode 100644
index 00000000000..e0956b9ac61
@@ -0,0 +1,33 @@
+SUMMARY = "Start the program if the specified terminal device is available."
+DESCRIPTION = "ttyrun is typically used to prevent a respawn through the \
+init(8) program when a terminal is not available."
+HOMEPAGE = "https://github.com/ibm-s390-linux/s390-tools"
+
+LICENSE = "MIT"
+LIC_FILES_CHKSUM = "file://LICENSE;md5=f5118f167b055bfd7c3450803f1847af"
+
+SRC_URI = "git://github.com/ibm-s390-linux/s390-tools;protocol=https;branch=master"
+SRCREV = "d9ce54dee3ac3827e76624352293a83eb05c727e"
+
+S = "${WORKDIR}/git"
+
+EXTRA_OEMAKE = "\
+    V=1 \
+    CC="${CC}" \
+    DISTRELEASE=${PR} \
+    "
+
+# We just want ttyrun and not the rest of s390-utils
+
+do_configure() {
+    oe_runmake -C ${S}/iucvterm/src clean
+}
+
+do_compile() {
+    oe_runmake -C ${S}/iucvterm/src ttyrun
+}
+
+do_install() {
+    install -d ${D}${sbindir}
+    install ${S}/iucvterm/src/ttyrun ${D}${sbindir}
+}
Signature · 1 line
2.34.1
#2 lore raw

PATCH 3/4 sysvinit-inittab: use ttyrun to run getty only if the terminal exists

In reply to [email protected]

From: Ross Burton <[email protected]>

Wrap calls to start_getty with ttyrun, so that getty isn't started if the device doesn't exist. As we know start_getty is only called when the device exists we can remove the partial workaround for this problem in that scripts too.

This neatly obsoletes SERIAL_CONSOLES_CHECK, whose sole purpose was to check what terminals are present at boot and rewrite inittab. Notably, this meant that SERIAL_CONSOLES_CHECK made using a read-only rootfs impossible.

(From OE-Core rev: f4fd17d5a5e4eaa31995d3ca52c871cfbdc0df68)

---
 .../sysvinit/sysvinit-inittab/start_getty     | 11 ++++---
 .../sysvinit/sysvinit-inittab_2.88dsf.bb      | 30 ++-----------------
 2 files changed, 7 insertions(+), 34 deletions(-)
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +5 -6
index f60409eae3a..f5671ee53d2 100644
@@ -1,5 +1,9 @@
 #!/bin/sh
 
+SPEED=$1
+DEVICE=$2
+TERM=$3
+
 # busybox' getty does this itself, util-linux' agetty needs extra help
 getty="/sbin/getty"
 case $(readlink -f "${getty}") in
@@ -13,9 +17,4 @@ case $(readlink -f "${getty}") in
         ;;
 esac
 
-if [ -e /sys/class/tty/$2 -a -c /dev/$2 ]; then
-	${setsid:-} ${getty} ${options:-} -L $1 $2 $3
-else
-    # Prevent respawning to fast error if /dev entry does not exist
-    sleep 1000
-fi
+${setsid:-} ${getty} ${options:-} -L $SPEED $DEVICE $TERM
meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb +2 -28
index e70dc705c05..6bbe517df1b 100644
@@ -28,7 +28,7 @@ do_install() {
         device=$(echo $s | cut -d\; -f 2)
         label=$(echo $device | sed -e 's/tty//' | tail --bytes=5)
 
-        echo "$label:12345:respawn:${base_bindir}/start_getty $speed $device vt102" >> ${D}${sysconfdir}/inittab
+        echo "$label:12345:respawn:${sbindir}/ttyrun $device ${base_bindir}/start_getty $speed $device vt102" >> ${D}${sysconfdir}/inittab
     done
 
     if [ "${USE_VT}" = "1" ]; then
@@ -52,33 +52,6 @@ EOF
     fi
 }
 
-pkg_postinst:${PN} () {
-# run this on host and on target
-if [ "${SERIAL_CONSOLES_CHECK}" = "" ]; then
-       exit 0
-fi
-}
-
-pkg_postinst_ontarget:${PN} () {
-# run this on the target
-if [ -e /proc/consoles ]; then
-	tmp="${SERIAL_CONSOLES_CHECK}"
-	for i in $tmp
-	do
-		j=`echo ${i} | sed -e s/^.*\;//g -e s/\:.*//g`
-		k=`echo ${i} | sed s/^.*\://g`
-		if [ -z "`grep ${j} /proc/consoles`" ]; then
-			if [ -z "${k}" ] || [ -z "`grep ${k} /proc/consoles`" ] || [ ! -e /dev/${j} ]; then
-				sed -i -e /^.*${j}\ /d -e /^.*${j}$/d /etc/inittab
-			fi
-		fi
-	done
-	kill -HUP 1
-else
-	exit 1
-fi
-}
-
 # USE_VT and SERIAL_CONSOLES are generally defined by the MACHINE .conf.
 # Set PACKAGE_ARCH appropriately.
 PACKAGE_ARCH = "${MACHINE_ARCH}"
@@ -89,4 +62,5 @@ CONFFILES:${PN} = "${sysconfdir}/inittab"
 USE_VT ?= "1"
 SYSVINIT_ENABLED_GETTYS ?= "1"
 
+RDEPENDS:${PN} = "ttyrun"
 RCONFLICTS:${PN} = "busybox-inittab"
Signature · 1 line
2.34.1
#3 lore raw

PATCH 4/4 busybox: use ttyrun to run getty only if the terminal exists

In reply to [email protected]

From: Ross Burton <[email protected]>

Wrap calls to start_getty with ttyrun, so that getty isn't started if the device doesn't exist. As we know start_getty is only called when the device exists we can remove the partial workaround for this problem in that scripts too.

This neatly obsoletes SERIAL_CONSOLES_CHECK, whose sole purpose was to check what terminals are present at boot and rewrite inittab. Notably, this meant that SERIAL_CONSOLES_CHECK made using a read-only rootfs impossible.

(From OE-Core rev: 950ecaabc04836efc346be0ac7e0331e2378872b)

---
 .../busybox/busybox-inittab_1.36.1.bb         | 46 +++++--------------
 1 file changed, 12 insertions(+), 34 deletions(-)
meta/recipes-core/busybox/busybox-inittab_1.36.1.bb +12 -34
index 868d7a230f6..462c9bb9c5f 100644
@@ -15,14 +15,17 @@ do_compile() {
 do_install() {
 	install -d ${D}${sysconfdir}
 	install -D -m 0644 ${WORKDIR}/inittab ${D}${sysconfdir}/inittab
-	tmp="${SERIAL_CONSOLES}"
-	[ -n "$tmp" ] && echo >> ${D}${sysconfdir}/inittab
-	for i in $tmp
-	do
-		j=`echo ${i} | sed s/\;/\ /g`
-		id=`echo ${i} | sed -e 's/^.*;//' -e 's/;.*//'`
-		echo "$id::respawn:${base_sbindir}/getty ${j}" >> ${D}${sysconfdir}/inittab
-	done
+
+    CONSOLES="${SERIAL_CONSOLES}"
+    for s in $CONSOLES
+    do
+        speed=$(echo $s | cut -d\; -f 1)
+        device=$(echo $s | cut -d\; -f 2)
+        label=$(echo $device | sed -e 's/tty//' | tail --bytes=5)
+
+        echo "$label::respawn:${sbindir}/ttyrun $device ${base_bindir}/start_getty $speed $device vt102" >> ${D}${sysconfdir}/inittab
+    done
+
 	if [ "${USE_VT}" = "1" ]; then
 		cat <<EOF >>${D}${sysconfdir}/inittab
 # ${base_sbindir}/getty invocations for the runlevels.
@@ -45,32 +48,6 @@ EOF
 
 }
 
-pkg_postinst:${PN} () {
-# run this on host and on target
-if [ "${SERIAL_CONSOLES_CHECK}" = "" ]; then
-       exit 0
-fi
-}
-
-pkg_postinst_ontarget:${PN} () {
-# run this on the target
-if [ -e /proc/consoles ]; then
-        tmp="${SERIAL_CONSOLES_CHECK}"
-        for i in $tmp
-        do
-                j=`echo ${i} | sed -e s/^.*\;//g -e s/\:.*//g`
-                k=`echo ${i} | sed s/^.*\://g`
-                if [ -z "`grep ${j} /proc/consoles`" ]; then
-                        if [ -z "${k}" ] || [ -z "`grep ${k} /proc/consoles`" ] || [ ! -e /dev/${j} ]; then
-                                sed -i -e /^.*${j}\ /d -e /^.*${j}$/d /etc/inittab
-                        fi
-                fi
-        done
-        kill -HUP 1
-else
-        exit 1
-fi
-}
 
 # SERIAL_CONSOLES is generally defined by the MACHINE .conf.
 # Set PACKAGE_ARCH appropriately.
@@ -79,6 +56,7 @@ PACKAGE_ARCH = "${MACHINE_ARCH}"
 FILES:${PN} = "${sysconfdir}/inittab"
 CONFFILES:${PN} = "${sysconfdir}/inittab"
 
+RDEPENDS:${PN} = "ttyrun"
 RCONFLICTS:${PN} = "sysvinit-inittab"
 
 USE_VT ?= "1"
Signature · 1 line
2.34.1