microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.46k stars 822 forks source link

The pixel information obtained by `TIOCGWINSZ` is incorrect. #12265

Open mikoto2000 opened 1 day ago

mikoto2000 commented 1 day ago

Windows Version

Microsoft Windows [Version 10.0.22631.4317]

WSL Version

2.3.24.0

Are you using WSL 1 or WSL 2?

Kernel Version

5.15.153.1-microsoft-standard-WSL2

Distro Version

Ubuntu 24.04

Other Software

My C application

termsize.c:

#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>

void main() {
  struct winsize ws;
  int fd = open("/dev/tty", O_RDONLY);
  if(fd == -1) {
    fprintf(stderr, "Can't open tty");
    return;
  }
  int ret = ioctl(fd, TIOCGWINSZ, &ws);
  close(fd);
  fprintf(stderr, "cols %d rows %d, xpixel %d, ypixel %d.\n", ws.ws_col, ws.ws_row, ws.ws_xpixel, ws.ws_ypixel);
}

Repro Steps

  1. Run gcc termsize.c -o termsize && ./termsize
  2. Output stderr cols 163 rows 60, xpixel 0, ypixel 0. † xpixel and ypixel is fixed value zero.

Expected Behavior

Output xpixel and ypixel is correct value.

Actual Behavior

Output xpixel and ypixel is fixed value zero.

Diagnostic Logs

strace output:

mikoto@mnmain:~/project/tmp$ strace -ff ./termsize
execve("./termsize", ["./termsize"], 0x7fffe8f162b8 /* 28 vars */) = 0
brk(NULL)                               = 0x5637986a2000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb22957b000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=40731, ...}) = 0
mmap(NULL, 40731, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fb229571000
close(3)                                = 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\220\243\2\0\0\0\0\0"..., 832) = 832
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
fstat(3, {st_mode=S_IFREG|0755, st_size=2125328, ...}) = 0
pread64(3, "\6\0\0\0\4\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0@\0\0\0\0\0\0\0"..., 784, 64) = 784
mmap(NULL, 2170256, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fb22935f000
mmap(0x7fb229387000, 1605632, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x28000) = 0x7fb229387000
mmap(0x7fb22950f000, 323584, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b0000) = 0x7fb22950f000
mmap(0x7fb22955e000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1fe000) = 0x7fb22955e000
mmap(0x7fb229564000, 52624, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fb229564000
close(3)                                = 0
mmap(NULL, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fb22935c000
arch_prctl(ARCH_SET_FS, 0x7fb22935c740) = 0
set_tid_address(0x7fb22935ca10)         = 1513339
set_robust_list(0x7fb22935ca20, 24)     = 0
rseq(0x7fb22935d060, 0x20, 0, 0x53053053) = 0
mprotect(0x7fb22955e000, 16384, PROT_READ) = 0
mprotect(0x563797e1e000, 4096, PROT_READ) = 0
mprotect(0x7fb2295b3000, 8192, PROT_READ) = 0
prlimit64(0, RLIMIT_STACK, NULL, {rlim_cur=8192*1024, rlim_max=RLIM64_INFINITY}) = 0
munmap(0x7fb229571000, 40731)           = 0
openat(AT_FDCWD, "/dev/tty", O_RDONLY)  = 3
ioctl(3, TIOCGWINSZ, {ws_row=60, ws_col=163, ws_xpixel=0, ws_ypixel=0}) = 0
close(3)                                = 0
write(2, "cols 163 rows 60, xpixel 0, ypix"..., 38cols 163 rows 60, xpixel 0, ypixel 0.
) = 38
exit_group(0)                           = ?
+++ exited with 0 +++
github-actions[bot] commented 1 day ago

Logs are required for review from WSL team

If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.

How to collect WSL logs Download and execute [collect-wsl-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-wsl-logs.ps1) in an **administrative powershell prompt**: ``` Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/diagnostics/collect-wsl-logs.ps1" -OutFile collect-wsl-logs.ps1 Set-ExecutionPolicy Bypass -Scope Process -Force .\collect-wsl-logs.ps1 ``` The script will output the path of the log file once done. If this is a networking issue, please use [collect-networking-logs.ps1](https://github.com/Microsoft/WSL/blob/master/diagnostics/collect-networking-logs.ps1), following the instructions [here](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#collect-wsl-logs-for-networking-issues) Once completed please upload the output files to this Github issue. [Click here for more info on logging](https://github.com/microsoft/WSL/blob/master/CONTRIBUTING.md#8-collect-wsl-logs-recommended-method) If you choose to email these logs instead of attaching to the bug, please send them to wsl-gh-logs@microsoft.com with the number of the github issue in the subject, and in the message a link to your comment in the github issue and reply with '/emailed-logs'.

View similar issues

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

mikoto2000 commented 1 day ago

I uploaded WslLogs.

WslLogs-2024-11-13_21-48-45.zip

github-actions[bot] commented 1 day ago
Diagnostic information ``` Detected appx version: 2.3.24.0 ```
zcobol commented 1 day ago

@mikoto2000 what terminal are you using?

xterm output:

zcobol@texas:~/pixel$ ./termsize
cols 80 rows 24, xpixel 804, ypixel 460.

windows terminal output;

zcobol@texas:~/pixel$ ./termsize
cols 120 rows 30, xpixel 0, ypixel 0.
mikoto2000 commented 1 day ago

I try windows terminal preview, mintty, wsltty and wezterm.

On these terminals, getting the pixel size using printf "\x1b[14t" was successful, but getting the pixel size using TIOCGWINSZ returned 0.

zcobol commented 1 day ago

You might want to address this issue with the Windows Terminal guys at https://github.com/microsoft/terminal. Using termsize overs SSH on a remote Fedora server it seems to work also:

zcobol@toto:~$ ./termsize
cols 120 rows 30, xpixel 640, ypixel 480.
zcobol@toto:~$ echo $TERM
xterm-256color