TIOCGWINSZ and busybox

Fischer, Matthew L (SHML - Diagnostics) matt.fischer at hp.com
Sun Mar 11 01:25:47 UTC 2007


 

> -----Original Message-----
> From: Denis Vlasenko [mailto:vda.linux at googlemail.com] 
> Sent: Saturday, March 10, 2007 9:24 AM
> To: busybox at busybox.net
> Cc: Fischer, Matthew L (SHML - Diagnostics)
> Subject: Re: TIOCGWINSZ and busybox
> 
> 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,

Well, sorta, its connected into a console through a management
processor.  The connection isn't quite serial, but the behavior is
probably about what you are thinking.


> 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?

Thanks for the response Denis.

I didn't see this option in our config file, so I will ask the team's
busybox/kernel guy to either get it set or upgrade busybox so we can set
it.

I did run the resize code (not from busybox, just from regular ole'
resize) and the ioctl fails there too (of course).  "Regular" Resize
seems to use some magic then to guess at the new row and height, but it
seems to be correct.

> 
> 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;


So it sounds like we wont be able to use the resize code that comes with
busybox, even if we enable it (since it lacks the "regular" resize
code's magic guesswork).  It does seem cheesy to change the calls to
more to also call resize too, but other than pulling in the source code,
that may be what we do (or just live with 80x24 mode).

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