Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't change terminal size on pty/N (works on ttyN)

I use the next to change terminal size:
rc = ioctl(fd, TIOCSWINSZ, &ws);
When I run this under linux text terminal (switching by Alt-Ctrl-F1), the result is that I expect to see. The whole my input and output within ranges given by ioctl syscall.
But when I connect to localhost by SSH, and run the same program, it works only partly. I mean that I can't input command wider than terminal size set by ioctl, but the output can cross the borders of terminal given by ioctl, and input can take more rows that set by ioctl. Also there is no auto carriage return and new line after that.
The only difference that I see when I run program directly it run on the terminal /dev/ttyN, and it's major number is 5, and when I run program via SSH it use /dev/pts/N as terminal, with major number 136. So, as I understood, it happens due the difference in terminals.
My questions:
1. Is that correct? Is the reason in terminal drivers?
2. How do I fix it? I need the same behaviour via SSH like in local tty terminal.

Thanks!

like image 404
van Avatar asked Jul 14 '12 10:07

van


1 Answers

Usually TIOCSWINSZ is used by the tty master (such as xterm, the Linux console itself, etc...) to tell the kernel driver how big the terminal actually is. The program running on the tty slave (i.e. the application itself) uses TIOCGWINSZ to query the size of the terminal. Most tty drivers don't support pushing it the other way; you can't in general call TIOCSWINSZ on the tty slave from the application and get the master to change its size.

Some terminals, such as xterm do support escape sequences to request them to resize, but this is just a byte escape sequence, and not an ioctl() command.

If you want the application to force the size of the terminal, then portably there is no way to do this. Unportably, you can apply a few special tricks like attempting TIOCSWINSZ or sending the xterm escape sequence.

like image 154
LeoNerd Avatar answered Oct 05 '22 04:10

LeoNerd