-
-
Notifications
You must be signed in to change notification settings - Fork 16
Fix zero size on TTY over SSH #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
STDOUT_FILENO | ||
}; | ||
|
||
let r = unsafe { ioctl(fd, TIOCGWINSZ, &mut us) }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a libc::close call here after r?
Good catch, we definitely should close it
Gesendet von Outlook für Android<https://aka.ms/AAb9ysg>
________________________________
From: Bjorn Beishline ***@***.***>
Sent: Tuesday, January 7, 2025 9:25:28 PM
To: softprops/termsize ***@***.***>
Cc: Furby Haxx ***@***.***>; Author ***@***.***>
Subject: Re: [softprops/termsize] Fix zero size on TTY over SSH (PR #24)
@BjornTheProgrammer commented on this pull request.
________________________________
In src/nix.rs<#24 (comment)>:
+ let fd = if let Ok(ssh_term) = std::env::var("SSH_TTY") {
+ // Convert path to a C-compatible string
+ let c_path = CString::new(ssh_term).expect("Failed to convert path to CString");
+
+ // Open the terminal device
+ let fd = unsafe { libc::open(c_path.as_ptr(), O_RDONLY) };
+ if fd < 0 {
+ return None; // Failed to open the terminal device
+ }
+
+ fd
+ } else {
+ STDOUT_FILENO
+ };
+
+ let r = unsafe { ioctl(fd, TIOCGWINSZ, &mut us) };
Should there be a libc::close call here after r?
—
Reply to this email directly, view it on GitHub<#24 (review)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADIWCTSA4RAYTMPZ47TTM4L2JQZ3RAVCNFSM6AAAAABUYKMCK6VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDKMZVGI4TKOJQGY>.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
}; | ||
let r = unsafe { ioctl(STDOUT_FILENO, TIOCGWINSZ, &mut us) }; | ||
|
||
let fd = if let Ok(ssh_term) = std::env::var("SSH_TTY") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure how it works, but what about checking for libc::isatty(libc::STDIN_FILENO) == 0
instead of SSH_TTY
to make this a lot more universal?
I noticed that when connected trough SSH (or using RustRover over Jetbrains Gateway) the termsize is always zero.
So I implemented a check if the "SSH_TTY" env variable is set and get the corresponding file descriptor and use that for the term size.