Open
Conversation
| STDOUT_FILENO | ||
| }; | ||
|
|
||
| let r = unsafe { ioctl(fd, TIOCGWINSZ, &mut us) }; |
There was a problem hiding this comment.
Should there be a libc::close call here after r?
Author
|
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: ***@***.***>
|
jarjk
reviewed
Sep 6, 2025
| }; | ||
| 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.
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.