-
Notifications
You must be signed in to change notification settings - Fork 56
pty: add GetPtyFromFile as safer GetPty #86
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
Conversation
v1.1.0 was released in 2022, and since then there have been some project renames that cause the old version to no longer work, breaking CI: go: github.com/kunalkushwaha/ltag@latest: github.com/kunalkushwaha/[email protected]: parsing go.mod: module declares its path as: github.com/containerd/ltag but was required as: github.com/kunalkushwaha/ltag Signed-off-by: Aleksa Sarai <[email protected]>
In a future patch we will split GetPty() so that users can pass a File as the already-opened pty master, but in order for us to be able to use the same File interface as our other external APIs we need to migrate our internal handlers to use File rather than *os.File. This change has no user-visible impact, as the underlying types used are identical. Signed-off-by: Aleksa Sarai <[email protected]>
Security-conscious callers may wish to have more control over opening /dev/ptmx, and so GetPty is not suitable for them. Previously it was not possible for such users to open /dev/ptmx and then use this package to create new ptys and manage the console. On Linux, the intended usage would be for a daemon to get an O_PATH handle to /dev/ptmx that can then be re-opened (through procfs) to get a new handle to /dev/ptmx. I suspect on FreeBSD you could use O_EMPTY_PATH to accomplish something similar. Signed-off-by: Aleksa Sarai <[email protected]>
@@ -31,7 +30,7 @@ const ( | |||
|
|||
// unlockpt unlocks the slave pseudoterminal device corresponding to the master pseudoterminal referred to by f. | |||
// unlockpt should be called before opening the slave side of a pty. | |||
func unlockpt(f *os.File) error { | |||
func unlockpt(f File) error { |
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.
Wondering if we can rather drop the File
interface and just use *os.File
, assuming that it is the only implementation of the interface
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.
hmm it was introduced due to the GC stuff
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.
Yeah this is an remarkably common issue to run into with *os.File
. It's a shame there isn't a properly supported way of doing this other than hacking around with runtime.SetFinalizer
which is (imho) incredibly dodgy.
To be fair, even Rust only really solved this issue in 1.63 with OwnedFd
and BorrowedFd
...
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.
Thanks, will merge and release
Security-conscious callers may wish to have more control over opening
/dev/ptmx, and so GetPty is not suitable for them. Previously it was not
possible for such users to open /dev/ptmx and then use this package to
create new ptys and manage the console.
On Linux, the intended usage would be for a daemon to get an O_PATH
handle to /dev/ptmx that can then be re-opened (through procfs) to get a
new handle to /dev/ptmx. I suspect on FreeBSD you could use O_EMPTY_PATH
to accomplish something similar.
Signed-off-by: Aleksa Sarai [email protected]