[lxc-devel] [lxd/master] openpty: fix TIOCGPTPEER usage
brauner on Github
lxc-bot at linuxcontainers.org
Tue May 12 09:05:52 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 433 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200512/5ff3d606/attachment.bin>
-------------- next part --------------
From 6f123325150ff49bef6d7d67570a92ce20233b3e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Tue, 12 May 2020 11:04:53 +0200
Subject: [PATCH] openpty: fix TIOCGPTPEER usage
We made this our controlling terminal which is a bit of an issue.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
shared/util_linux.go | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/shared/util_linux.go b/shared/util_linux.go
index 4957a312bb..c0e6766c54 100644
--- a/shared/util_linux.go
+++ b/shared/util_linux.go
@@ -415,9 +415,16 @@ func OpenPty(uid, gid int64) (*os.File, *os.File, error) {
}
var slave *os.File
- slaveFd, err := unix.IoctlRetInt(int(master.Fd()), unix.TIOCGPTPEER)
+ slaveFd, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(master.Fd()), unix.TIOCGPTPEER, uintptr(unix.O_NOCTTY|unix.O_CLOEXEC|os.O_RDWR))
if err == nil {
- slave = os.NewFile(uintptr(slaveFd), fmt.Sprintf("%d", slaveFd))
+ // Get the slave side.
+ id := 0
+ _, _, errno = unix.Syscall(unix.SYS_IOCTL, uintptr(master.Fd()), unix.TIOCGPTN, uintptr(unsafe.Pointer(&id)))
+ if errno != 0 {
+ return nil, nil, unix.Errno(errno)
+ }
+
+ slave = os.NewFile(uintptr(slaveFd), fmt.Sprintf("/dev/pts/%d", id))
} else {
// Get the slave side.
id := 0
More information about the lxc-devel
mailing list