Skip to contentSkip to conversation

sysvinit-inittab: support non-busybox-getty on serial consoles

PATCH In review André Draszik 2 participants 2 messages Feb 11, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 sysvinit-inittab: support non-busybox-getty on serial consoles

From: André Draszik <[email protected]>

Busybox' getty has code to try to make itself a session leader, whereas util-linux' agetty doesn't. It expects this to happen from outside.
When getty is not a session leader, many things don't work on the serial console, e.g. setting the terminal process group, job control doesn't work, etc.

Executing image tests also fails with AssertionErrors, because

    Feb  5 16:12:55 qemuarm getty[590]: /dev/ttyAMA1: cannot get controlling tty: Operation not permitted
    Feb  5 16:12:55 qemuarm getty[590]: /dev/ttyAMA1: cannot set process group: Inappropriate ioctl for device

Update the start_getty script to invoke getty via the setsid utility if needed, i.e. if /sbin/getty is not busybox getty.

[YOCTO #13058]

---
v3: also get rid of eval
v2: fork fewer processes

---
 .../sysvinit/sysvinit-inittab/start_getty          | 14 +++++++++++++-
 .../sysvinit/sysvinit-inittab_2.88dsf.bb           |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +13 -1
index e15ae35f90..96fd6cfcfd 100644
@@ -13,6 +13,18 @@ active_serial=$(grep "serial" /proc/tty/drivers | cut -d/ -f1 | sed "s/ *$//")
 # Rephrase input parameter from ttyS target index (ttyS1, ttyS2, ttyAMA0, etc).
 runtime_tty=$(echo $2 | grep -oh '[0-9]')
 
+# busybox' getty does this itself, util-linux' agetty needs extra help
+getty="/sbin/getty"
+case $(readlink -f "${getty}") in
+    */busybox*)
+        ;;
+    *)
+        if [ -x "/usr/bin/setsid" ] ; then
+            setsid="/usr/bin/setsid"
+        fi
+        ;;
+esac
+
 # Backup $IFS.
 DEFAULT_IFS=$IFS
 # Customize Internal Field Separator.
@@ -31,7 +43,7 @@ for line in $active_serial; do
 			then
 				if [ -c /dev/$2 ]
 				then
-				    /sbin/getty -L $1 $2 $3
+				    ${setsid:-} ${getty} -L $1 $2 $3
 				fi
 				break
 			fi
meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb +1 -0
index 8585a418ab..bfd890d924 100644
@@ -20,6 +20,7 @@ do_install() {
     install -m 0644 ${WORKDIR}/inittab ${D}${sysconfdir}/inittab
     install -d ${D}${base_bindir}
     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}"
Signature · 1 line
2.20.1
#1 lore raw
Quoted 32 lines · André Draszik

From: André Draszik <[email protected]>
Busybox' getty has code to try to make itself a session leader, whereas util-linux' agetty doesn't. It expects this to happen from outside.
When getty is not a session leader, many things don't work on the serial console, e.g. setting the terminal process group, job control doesn't work, etc.

Executing image tests also fails with AssertionErrors, because

    Feb  5 16:12:55 qemuarm getty[590]: /dev/ttyAMA1: cannot get controlling tty: Operation not permitted
    Feb  5 16:12:55 qemuarm getty[590]: /dev/ttyAMA1: cannot set process group: Inappropriate ioctl for device

Update the start_getty script to invoke getty via the setsid utility if needed, i.e. if /sbin/getty is not busybox getty.

[YOCTO #13058]

---
v3: also get rid of eval
v2: fork fewer processes

---
 .../sysvinit/sysvinit-inittab/start_getty          | 14 +++++++++++++-
 .../sysvinit/sysvinit-inittab_2.88dsf.bb           |  1 +
 2 files changed, 14 insertions(+), 1 deletion(-)
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +0 -0
index e15ae35f90..96fd6cfcfd 100644

meta/recipes-core/sysvinit/sysvinit-inittab/start_getty active_serial=$(grep "serial" /proc/tty/drivers | cut -d/ -f1 | sed "s/ *$//") · line 18

Quoted 6 lines
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +3 -0
@@ -13,6 +13,18 @@ active_serial=$(grep "serial" /proc/tty/drivers | cut -d/ -f1 | sed "s/ *$//")
 # Rephrase input parameter from ttyS target index (ttyS1, ttyS2, ttyAMA0, etc).
 runtime_tty=$(echo $2 | grep -oh '[0-9]')
 
+# busybox' getty does this itself, util-linux' agetty needs extra help
+getty="/sbin/getty"
+case $(readlink -f "${getty}") in

Maybe directly checking the output of "getty --version" would be even more efficient than trying to infer busybox -vs- util-linux based on symlinks?

Checking symlinks will fail if busybox is built with CONFIG_FEATURE_INDIVIDUAL (which we do have support for in the busybox recipe... even if no one actually uses it).

Quoted 41 lines
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +10 -1
+    */busybox*)
+        ;;
+    *)
+        if [ -x "/usr/bin/setsid" ] ; then
+            setsid="/usr/bin/setsid"
+        fi
+        ;;
+esac
+
 # Backup $IFS.
 DEFAULT_IFS=$IFS
 # Customize Internal Field Separator.
@@ -31,7 +43,7 @@ for line in $active_serial; do
                        then
                                if [ -c /dev/$2 ]
                                then
-                                   /sbin/getty -L $1 $2 $3
+                                   ${setsid:-} ${getty} -L $1 $2 $3
                                fi
                                break
                        fi
meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb +1 -1
index 8585a418ab..bfd890d924 100644
@@ -20,6 +20,7 @@ do_install() {
     install -m 0644 ${WORKDIR}/inittab ${D}${sysconfdir}/inittab
     install -d ${D}${base_bindir}
     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}"
--

2.20.1

--
_______________________________________________
Openembedded-core mailing list
[email protected]
http://lists.openembedded.org/mailman/listinfo/openembedded-core