Skip to contentSkip to conversation

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

PATCH Superseded André Draszik 2 participants 4 messages Feb 8, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 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]

---
 meta/recipes-core/sysvinit/sysvinit-inittab/start_getty | 9 ++++++++-
 meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +8 -1
index e15ae35f90..ae613f1e54 100644
@@ -13,6 +13,13 @@ 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' getty needs extra help
+getty="/sbin/getty"
+if ! basename $(readlink -f "${getty}") | grep -q busybox \
+    && [ -x "/usr/bin/setsid" ] ; then
+    getty="/usr/bin/setsid ${getty}"
+fi
+
 # Backup $IFS.
 DEFAULT_IFS=$IFS
 # Customize Internal Field Separator.
@@ -31,7 +38,7 @@ for line in $active_serial; do
 			then
 				if [ -c /dev/$2 ]
 				then
-				    /sbin/getty -L $1 $2 $3
+				    eval ${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 40 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]

---
 meta/recipes-core/sysvinit/sysvinit-inittab/start_getty | 9
++++++++-
 meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +0 -0
index e15ae35f90..ae613f1e54 100644
@@ -13,6 +13,13 @@ 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' getty needs extra help

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

Quoted 5 lines
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +5 -0
+getty="/sbin/getty"
+if ! basename $(readlink -f "${getty}") | grep -q busybox \
+    && [ -x "/usr/bin/setsid" ] ; then
+    getty="/usr/bin/setsid ${getty}"
+fi

The reason I'm reluctant to take changes like this is you just added 3 fork calls above. This does have a significant effect on boot time on slower devices.

Is there a way we can do a shell string comparison rather than using grep? case statement maybe?

Cheers,

Richard

#2 lore raw
Quoted 51 lines · Richard Purdie
Quoted 40 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]

---
 meta/recipes-core/sysvinit/sysvinit-inittab/start_getty | 9
++++++++-
 meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +0 -0
index e15ae35f90..ae613f1e54 100644
@@ -13,6 +13,13 @@ 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' getty needs extra help

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

Quoted 5 lines
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +5 -0
+getty="/sbin/getty"
+if ! basename $(readlink -f "${getty}") | grep -q busybox \
+    && [ -x "/usr/bin/setsid" ] ; then
+    getty="/usr/bin/setsid ${getty}"
+fi

The reason I'm reluctant to take changes like this is you just added 3 fork calls above. This does have a significant effect on boot time on slower devices.

Quoted 2 lines

Is there a way we can do a shell string comparison rather than using grep? case statement maybe?

I've sent a v2.

Are you aware that there are at least 9 forks in this file for something as simple as forking a getty?

Cheers,
Andre'

Quoted 6 lines

Cheers,

Richard

#3 lore raw
Quoted 60 lines · André Draszik
Quoted 55 lines · Richard Purdie
Quoted 42 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]

---
 meta/recipes-core/sysvinit/sysvinit-inittab/start_getty | 9
++++++++-
 meta/recipes-core/sysvinit/sysvinit-inittab_2.88dsf.bb  | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

inittab/start_getty b/meta/recipes-core/sysvinit/sysvinit-inittab/start_getty index e15ae35f90..ae613f1e54 100644

meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +0 -0
@@ -13,6 +13,13 @@ 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' getty needs extra help

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

Quoted 5 lines
meta/recipes-core/sysvinit/sysvinit-inittab/start_getty +5 -0
+getty="/sbin/getty"
+if ! basename $(readlink -f "${getty}") | grep -q busybox \
+    && [ -x "/usr/bin/setsid" ] ; then
+    getty="/usr/bin/setsid ${getty}"
+fi

The reason I'm reluctant to take changes like this is you just added 3
fork calls above. This does have a significant effect on boot time on
slower devices.

Quoted 3 lines

Is there a way we can do a shell string comparison rather than using
grep? case statement maybe?

Quoted 5 lines

I've sent a v2.

Are you aware that there are at least 9 forks in this file for something as
simple as forking a getty?

I'm not familiar with this file in particular.

I know we removed a lot from general startup but a lot has crept in since then :(

Cheers,

Richard