Skip to content

Commit

Permalink
Work around 'podman exec' resetting the terminal size to 80x24
Browse files Browse the repository at this point in the history
See: containers/podman#3946

COLUMNS and LINES may not be set in the user's environment. Hence the
existing mechanism for preserving environment variables don't work.

Note that for things to keep working when invoked via D-Bus from
inside a toolbox container, the terminal size needs to be queried using
the standard input stream, instead of explicitly mentioning the
controlling terminal device /dev/tty. This is because stty(1) doesn't
have the notion of a controlling terminal when invoked via D-Bus, but
flatpak-spawn(1) ensures that the standard input stream still points
to the user's interactive terminal.

https://github.com/debarshiray/toolbox/issues/242
  • Loading branch information
tagoh authored and debarshiray committed Sep 9, 2019
1 parent cc448a2 commit 05544fb
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions toolbox
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,28 @@ create_enter_command()


create_environment_options()
{
(
columns=""
lines=""

if terminal_size=$(stty size 2>&3); then
columns=$(echo "$terminal_size" | cut --delimiter " " --fields 2 2>&3)
if ! is_integer "$columns"; then
echo "$base_toolbox_command: failed to parse the number of columns from the terminal size" >&3
columns=""
fi

lines=$(echo "$terminal_size" | cut --delimiter " " --fields 1 2>&3)
if ! is_integer "$lines"; then
echo "$base_toolbox_command: failed to parse the number of lines from the terminal size" >&3
lines=""
fi

environment_options="$environment_options --env=COLUMNS=$columns --env=LINES=$lines"
else
echo "$base_toolbox_command: failed to read terminal size" >&3
fi

echo "$environment_variables" \
| sed "s/ \+/\n/g" 2>&3 \
| {
Expand All @@ -339,12 +360,20 @@ create_environment_options()
fi
done

if [ "$columns" != "" ] 2>&3; then
environment_options="$environment_options --env=COLUMNS=$columns"
fi

if [ "$lines" != "" ] 2>&3; then
environment_options="$environment_options --env=LINES=$lines"
fi

environment_options=${environment_options#" "}
echo "$base_toolbox_command: created options for environment variables to forward" >&3
echo "$environment_options" >&3
echo "$environment_options"
}
}
)


create_toolbox_container_name()
Expand Down

0 comments on commit 05544fb

Please sign in to comment.