TIOCGWINSZ and busybox
Denis Vlasenko
vda.linux at googlemail.com
Sat Mar 10 16:23:35 UTC 2007
On Saturday 10 March 2007 00:56, Fischer, Matthew L (SHML - Diagnostics) wrote:
> I am trying to get the more command in busybox to recognize terminal
> window size changes. The more command is not responding to the window
> resizes, not only while its running, but even when I re-run more after a
> resize. I ran through it with gdb and the TIOCGWINSZ call is returning
> all 0 values (ws_row = ws_col = 0),
The kernel doesn't know the size of the terminal, then.
I suppose it's a serial console or similar. In this case,
screen size is taken from enviroment: $LINES, $COLUMNS:
int get_terminal_width_height(const int fd, int *width, int *height)
{
struct winsize win = { 0, 0, 0, 0 };
int ret = ioctl(fd, TIOCGWINSZ, &win);
if (height) {
if (!win.ws_row) {
char *s = getenv("LINES");
if (s) win.ws_row = atoi(s);
}
if (win.ws_row <= 1 || win.ws_row >= 30000)
win.ws_row = 24;
*height = (int) win.ws_row;
}
<< same for COLUMNS>>
> this is probably the resize culprit
> (since more appears to use these values).
With FEATURE_RESIZE_PRINT on, what does resize print and what is its
exit code?
resize's exit code is a result of "set terminal size" ioctl:
ret = ioctl(STDOUT_FILENO, TIOCSWINSZ, &w);
printf(ESC"8");
tcsetattr(STDOUT_FILENO, TCSANOW, &old);
if (ENABLE_FEATURE_RESIZE_PRINT)
printf("COLUMNS=%d;LINES=%d;export COLUMNS LINES;\n",
w.ws_col, w.ws_row);
return ret;
> On the first build we had AUTOWIDTH set, and then rebuilt with AUTOWIDTH
> and FEATURE_USE_TERMIOS set; there was no change in the behavior. I
> also tried using the "normal" more command, and the result was the same.
>
> Since I am connected to my test machine through a management processor,
> I don't expect SIGWINCH to work, but when more is run "from scratch", I
> do expect it to find the correct rows and columns.
Thus far I suspect that ioctl(STDOUT_FILENO, TIOCSWINSZ, &w) in resize
fails, and also you don't set environment variables. Thus 'more'
lives in default, 80x24 world.
BTW, you got me looking into 'more' source - it has a few bugs...
thanks.
--
vda
More information about the busybox
mailing list