All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] base-files/profile: Add universal resize function
@ 2020-11-02 18:59 Jason Wessel
  2020-11-02 18:59 ` [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux Jason Wessel
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Wessel @ 2020-11-02 18:59 UTC (permalink / raw)
  To: openembedded-core

Using an editor or any kind of command line that wraps beyond the
column width of the session on a serial port is quite problematic
unless you are using an 80x24 session.

The original /etc/profile tried to use the resize binary if it was
available.  The problem is that you only get the resize binary if
xterm, or busybox is installed.

This updated /etc/profile will add a resize function available to the
shell when no xterm or busybox resize binary is found.  More care is
taken in this new version to test that terminal is interactive.  The
EDITOR and SHLVL environment variables are checked to prevent resize
from running necessarily.

The function definitions are not indented intentionally to keep them
to the 80 column width.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 .../base-files/base-files/profile             | 48 ++++++++++++++++---
 1 file changed, 41 insertions(+), 7 deletions(-)

diff --git a/meta/recipes-core/base-files/base-files/profile b/meta/recipes-core/base-files/base-files/profile
index 9e4283e0c7..cc37e1ba77 100644
--- a/meta/recipes-core/base-files/base-files/profile
+++ b/meta/recipes-core/base-files/base-files/profile
@@ -2,7 +2,6 @@
 # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
 
 PATH="/usr/local/bin:/usr/bin:/bin"
-EDITOR="vi"			# needed for packages like cron, git-commit
 [ "$TERM" ] || TERM="vt100"	# Basic terminal capab. For screen etc.
 
 # Add /sbin & co to $PATH for the root user
@@ -20,13 +19,48 @@ if [ -d /etc/profile.d ]; then
 	unset i
 fi
 
-# Make sure we are on a serial console (i.e. the device used starts with
-# /dev/tty[A-z]), otherwise we confuse e.g. the eclipse launcher which tries do
-# use ssh
-case $(tty 2>/dev/null) in
-	/dev/tty[A-z]*) [ -x @BINDIR@/resize ] && @BINDIR@/resize >/dev/null;;
-esac
+if [ -t 0 -a $# -eq 0 ]; then
+	if [ ! -x @BINDIR@/resize ] ; then
+		if [ -n "$BASH_VERSION" ] ; then
+# Optimized resize funciton for bash
+resize() {
+	local x y
+	IFS='[;' read -t 2 -p $(printf '\e7\e[r\e[999;999H\e[6n\e8') -sd R _ y x _
+	[ -n "$y" ] && \
+	echo -e "COLUMNS=$x;\nLINES=$y;\nexport COLUMNS LINES;" && \
+	stty cols $x rows $y
+}
+		else
+# Portable resize function for ash/bash/dash/ksh
+# with subshell to avoid local variables
+resize() {
+	(o=$(stty -g)
+	stty -echo raw min 0 time 2
+	printf '\0337\033[r\033[999;999H\033[6n\0338'
+	if echo R | read -d R x 2> /dev/null; then
+		IFS='[;R' read -t 2 -d R -r z y x _
+	else
+		IFS='[;R' read -r _ y x _
+	fi
+	stty "$o"
+	[ -z "$y" ] && y=${z##*[}&&x=${y##*;}&&y=${y%%;*}
+	[ -n "$y" ] && \
+	echo "COLUMNS=$x;"&&echo "LINES=$y;"&&echo "export COLUMNS LINES;"&& \
+	stty cols $x rows $y)
+}
+		fi
+	fi
+	# Use the EDITOR not being set as a trigger to call resize
+	# and only do this for /dev/tty[A-z] which are typically
+	# serial ports
+	if [ -z "$EDITOR" -a "$SHLVL" = 1 ] ; then
+		case $(tty 2>/dev/null) in
+			/dev/tty[A-z]*) resize >/dev/null;;
+		esac
+	fi
+fi
 
+EDITOR="vi"			# needed for packages like cron, git-commit
 export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM
 
 umask 022
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux
  2020-11-02 18:59 [PATCH 1/2] base-files/profile: Add universal resize function Jason Wessel
@ 2020-11-02 18:59 ` Jason Wessel
  2020-11-02 19:22   ` [OE-core] " Konrad Weihmann
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Wessel @ 2020-11-02 18:59 UTC (permalink / raw)
  To: openembedded-core

Long ago in commit 473ff65c2f69de4ece3204fadfae7c5cb992149a
(serial-getty service: Add xterm as default TERM), the xterm
became the default for the serial port terminal.

Using the version of vim.tiny in oe-core master with the
serial port connected in xterm version 322 (which is one
of the most widely deployed versions at the current time)
causes artifacts and missed characters.

The example sequence is the following:
  * Start vim
  * Press "i" to enter input mode
  * Type "123"
  * Press Escape to enter command mode
  * Press "a" to enter append mode
  * Type "456"

At this point if you are using xterm less than version 535 you will
see on your screen "12456" instead of "123456".

Changing the TERM variable to "linux" will still allow you to have all
the same functionality with colorization, ansi character escapes
etc..., but will avoid the extra xterm specific escape sequence that
only exists in the most recent versions of xterm.

Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
---
 .../systemd/systemd-serialgetty/serial-getty@.service           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service b/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
index 549d566009..f2290639a6 100644
--- a/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
+++ b/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
@@ -29,7 +29,7 @@ Conflicts=rescue.service
 Before=rescue.service
 
 [Service]
-Environment="TERM=xterm"
+Environment="TERM=linux"
 ExecStart=-/sbin/agetty -8 -L %I @BAUDRATE@ $TERM
 Type=idle
 Restart=always
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [OE-core] [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux
  2020-11-02 18:59 ` [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux Jason Wessel
@ 2020-11-02 19:22   ` Konrad Weihmann
  2020-11-02 19:31     ` Jason Wessel
  0 siblings, 1 reply; 4+ messages in thread
From: Konrad Weihmann @ 2020-11-02 19:22 UTC (permalink / raw)
  To: openembedded-core; +Cc: jason.wessel

Why not have it configurable as already done with BAUDRATE?
Especially as it doesn't change the behavior for user without the 
mentioned prerequisites

On 02.11.20 19:59, Jason Wessel wrote:
> Long ago in commit 473ff65c2f69de4ece3204fadfae7c5cb992149a
> (serial-getty service: Add xterm as default TERM), the xterm
> became the default for the serial port terminal.
> 
> Using the version of vim.tiny in oe-core master with the
> serial port connected in xterm version 322 (which is one
> of the most widely deployed versions at the current time)
> causes artifacts and missed characters.
> 
> The example sequence is the following:
>    * Start vim
>    * Press "i" to enter input mode
>    * Type "123"
>    * Press Escape to enter command mode
>    * Press "a" to enter append mode
>    * Type "456"
> 
> At this point if you are using xterm less than version 535 you will
> see on your screen "12456" instead of "123456".
> 
> Changing the TERM variable to "linux" will still allow you to have all
> the same functionality with colorization, ansi character escapes
> etc..., but will avoid the extra xterm specific escape sequence that
> only exists in the most recent versions of xterm.
> 
> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
> ---
>   .../systemd/systemd-serialgetty/serial-getty@.service           | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service b/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
> index 549d566009..f2290639a6 100644
> --- a/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
> +++ b/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
> @@ -29,7 +29,7 @@ Conflicts=rescue.service
>   Before=rescue.service
>   
>   [Service]
> -Environment="TERM=xterm"
> +Environment="TERM=linux"
>   ExecStart=-/sbin/agetty -8 -L %I @BAUDRATE@ $TERM
>   Type=idle
>   Restart=always
> 
> 
> 
> 
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [OE-core] [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux
  2020-11-02 19:22   ` [OE-core] " Konrad Weihmann
@ 2020-11-02 19:31     ` Jason Wessel
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wessel @ 2020-11-02 19:31 UTC (permalink / raw)
  To: Konrad Weihmann, openembedded-core



On 11/2/20 1:22 PM, Konrad Weihmann wrote:
> Why not have it configurable as already done with BAUDRATE?
> Especially as it doesn't change the behavior for user without the 
> mentioned prerequisites
> 


Good idea.  That seems like a perfectly reasonable ask for
a v2 patch. 

I would still change the default to "linux" as it is broken
and the defaults for the oe-core should work for the broad
range of users. 

Jason. 


> On 02.11.20 19:59, Jason Wessel wrote:
>> Long ago in commit 473ff65c2f69de4ece3204fadfae7c5cb992149a
>> (serial-getty service: Add xterm as default TERM), the xterm
>> became the default for the serial port terminal.
>>
>> Using the version of vim.tiny in oe-core master with the
>> serial port connected in xterm version 322 (which is one
>> of the most widely deployed versions at the current time)
>> causes artifacts and missed characters.
>>
>> The example sequence is the following:
>>    * Start vim
>>    * Press "i" to enter input mode
>>    * Type "123"
>>    * Press Escape to enter command mode
>>    * Press "a" to enter append mode
>>    * Type "456"
>>
>> At this point if you are using xterm less than version 535 you will
>> see on your screen "12456" instead of "123456".
>>
>> Changing the TERM variable to "linux" will still allow you to have all
>> the same functionality with colorization, ansi character escapes
>> etc..., but will avoid the extra xterm specific escape sequence that
>> only exists in the most recent versions of xterm.
>>
>> Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
>> ---
>>   .../systemd/systemd-serialgetty/serial-getty@.service           | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service b/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
>> index 549d566009..f2290639a6 100644
>> --- a/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
>> +++ b/meta/recipes-core/systemd/systemd-serialgetty/serial-getty@.service
>> @@ -29,7 +29,7 @@ Conflicts=rescue.service
>>   Before=rescue.service
>>   
>>   [Service]
>> -Environment="TERM=xterm"
>> +Environment="TERM=linux"
>>   ExecStart=-/sbin/agetty -8 -L %I @BAUDRATE@ $TERM
>>   Type=idle
>>   Restart=always
>>
>>
>>
>> 
>>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-02 19:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-02 18:59 [PATCH 1/2] base-files/profile: Add universal resize function Jason Wessel
2020-11-02 18:59 ` [PATCH 2/2] systemd-serialgetty: Switch to TERM=linux Jason Wessel
2020-11-02 19:22   ` [OE-core] " Konrad Weihmann
2020-11-02 19:31     ` Jason Wessel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.